Created
April 8, 2014 11:59
-
-
Save mid0111/10114397 to your computer and use it in GitHub Desktop.
Custom List class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomList extends AbstractList<MyElement> { | |
private List<MyElement> list = null; | |
public CustomList() { | |
list = new ArrayList<MyElement>(); | |
} | |
@Override | |
public MyElement get(int index) { | |
return list.get(index); | |
} | |
@Override | |
public boolean add(MyElement e) { | |
list.add(list.size(), e); | |
return true; | |
} | |
@Override | |
public int size() { | |
return list.size(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomListTest { | |
@Test | |
public void CustomListインスタンスにCustomElementインスタンスを追加できること() { | |
String sample = "test"; | |
CustomElement e = new CustomElement(sample); | |
CustomList list = new CustomList(); | |
list.add(e); | |
assertThat(list.size()).isEqualTo(1); | |
assertThat(list.get(0).getText()).isEqualTo("test"); | |
for(CustomElement e : list) { | |
assertThat(e.getText()).isEqualTo("test"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment