オブジェクト指向けいかくその5.3
テストのぶぶん
import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import org.junit.Test; public class ArrayList2Test { @Test public void 引数に与えた文字列を配列に追加し表示する() throws Exception { ArrayList2 arraylist = new ArrayList2(); String result = arraylist.nameAdd("sasaki"); assertThat(result, is("sasaki")); result = arraylist.nameAdd("yamada"); assertThat(result, is("yamada")); } @Test public void 引数に与えられた文字列が配列にあるか調べる() throws Exception { ArrayList2 arraylist = new ArrayList2(); arraylist.nameAdd("sasaki"); arraylist.nameAdd("syoko"); Boolean result = arraylist.contain("sasaki"); assertTrue(result); result = arraylist.contain("yamada"); assertFalse(result); } }