diff --git a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsTest.java b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsTest.java index ce24ff24bc..674a2f89bc 100644 --- a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsTest.java +++ b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsTest.java @@ -39,7 +39,8 @@ public class ListOfListsTest { @SuppressWarnings("unchecked") @Test public void givenListOfLists_whenRemovingElements_thenCheckNames() { - ((ArrayList) listOfLists.get(1)).remove(0); + + ((ArrayList) listOfLists.get(1)).remove(0); listOfLists.remove(1); assertEquals("Rubber 1", ((Rubber) listOfLists.get(1) .get(0)).getName()); @@ -47,4 +48,29 @@ public class ListOfListsTest { assertEquals("Rubber 1", ((Rubber) listOfLists.get(0) .get(0)).getName()); } + + @Test + public void givenThreeList_whenCombineIntoOneList_thenCheckList() { + ArrayList pens = new ArrayList<>(); + pens.add(new Pen("Pen 1")); + pens.add(new Pen("Pen 2")); + ArrayList pencils = new ArrayList<>(); + pencils.add(new Pencil("Pencil 1")); + pencils.add(new Pencil("Pencil 2")); + ArrayList rubbers = new ArrayList<>(); + rubbers.add(new Rubber("Rubber 1")); + rubbers.add(new Rubber("Rubber 2")); + + List> list = new ArrayList>(); + list.add(pens); + list.add(pencils); + list.add(rubbers); + + assertEquals("Pen 1", ((Pen) list.get(0) + .get(0)).getName()); + assertEquals("Pencil 1", ((Pencil) list.get(1) + .get(0)).getName()); + assertEquals("Rubber 1", ((Rubber) list.get(2) + .get(0)).getName()); + } }