Javaeye紀実に進駐する

1308 ワード

これはいいですね.またコードをこの上に回して、見てもきれいです.
package wintys.junit;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * JUnit4     
 * @author Winty
 * @version 2009-07-05
 */
@RunWith(Parameterized.class)
public class CalculatorTestWithParameter {
	private int input1;
	private int input2;
	private int result;
	
	public CalculatorTestWithParameter(int input1, int input2, int result) {
		super();
		this.input1 = input1;
		this.input2 = input2;
		this.result = result;
	}
	
	@Parameters
	public static Collection<Object[]> initParam(){
		Object[][] objArray = new Object[][]{
				{1 , 1 , 2},
				{2 , 5 , 7},
				{-1 , 8 , 7},
				{-5 , -1 ,-6} 
		};
		
		return Arrays.asList(objArray);
	}
	
	@Test
	public void testAdd(){
		Calculator cal = new Calculator();
		int rt = cal.add(input1, input2);
		
		assertEquals(result , rt);
	}
}