Skip to content

Instantly share code, notes, and snippets.

@mid0111
Created April 8, 2014 11:59
Show Gist options
  • Save mid0111/10114397 to your computer and use it in GitHub Desktop.
Save mid0111/10114397 to your computer and use it in GitHub Desktop.
Custom List class.
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();
}
}
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