/** Test method for {@link org.apache.niolex.commons.collection.RetainLinkedList#isEmpty()}. */ @Test public void testIsEmpty() { RetainLinkedList<String> list = new RetainLinkedList<String>(3); list.add("It "); list.add("is "); list.add("a "); list.add("big "); list.add("world!"); assertTrue(list.hasNext()); assertFalse(list.hasRetain()); String w = ""; while (list.hasNext()) { list.handleNext(); } assertFalse(list.hasNext()); assertTrue(list.hasRetain()); assertEquals(list.totalSize(), 3); assertEquals(list.handleSize(), 0); while (list.hasRetain()) { w += list.handleRetain(); } assertEquals(w, "a big world!"); assertEquals(list.totalSize(), 0); assertEquals(list.handleSize(), 0); assertFalse(list.hasNext()); assertFalse(list.hasRetain()); }
/** Test method for {@link org.apache.niolex.commons.collection.RetainLinkedList#toArray(E[])}. */ @Test public void testToArray() { RetainLinkedList<String> list = new RetainLinkedList<String>(3); list.add("It "); list.add("is "); list.add("a "); list.add("big "); list.add("world!"); String[] arr = new String[6]; arr[5] = "not me."; list.toArray(arr); assertEquals(arr[5], "not me."); assertEquals(arr[4], "world!"); String w = ""; while (list.hasNext()) { list.handleNext(); } assertEquals(list.totalSize(), 3); assertEquals(list.handleSize(), 0); arr = new String[2]; list.toArray(arr); assertEquals(arr[0], "a "); assertEquals(arr[1], "big "); while (list.hasRetain()) { w += list.handleRetain(); } assertEquals(w, "a big world!"); assertEquals(list.totalSize(), 0); assertEquals(list.handleSize(), 0); }
/** * Test method for {@link * org.apache.niolex.commons.collection.RetainLinkedList#addAll(java.util.Collection)}. */ @Test public void testHasNext() { RetainLinkedList<String> list = new RetainLinkedList<String>(3); list.add("It "); list.add("is "); list.add("a "); list.add("big "); list.add("world!"); RetainLinkedList<String> list2 = new RetainLinkedList<String>(5); list2.addAll(list); list2.add("Good"); list2.add("Not yet implemented"); while (list2.handleNext() != null) { list2.handleNext(); } assertFalse(list2.hasNext()); assertEquals(list2.handleSize(), 0); assertTrue(list2.hasRetain()); assertEquals(list2.totalSize(), 5); }
/** * Test method for {@link * org.apache.niolex.commons.collection.RetainLinkedList#add(java.lang.Object)}. */ @Test public void testAdd1() { RetainLinkedList<String> list = new RetainLinkedList<String>(3); list.add("It "); assertEquals(list.totalSize(), 1); list.add("is "); assertEquals(list.totalSize(), 2); assertEquals(list.handleSize(), 2); list.add("me"); assertEquals(list.handleNext(), "It "); assertEquals(list.totalSize(), 3); assertEquals(list.handleSize(), 2); }
/** * Test method for {@link * org.apache.niolex.commons.collection.RetainLinkedList#addAll(org.apache.niolex.commons.collection.RetainLinkedList)}. */ @Test public void testHasRetain() { List<String> list = new ArrayList<String>(); list.add("It "); list.add("is "); list.add("a "); list.add("big "); list.add("world!"); RetainLinkedList<String> list2 = new RetainLinkedList<String>(3); list2.addAll(list); assertEquals(null, list2.handleRetain()); String w = ""; while (list2.handleNext() != null) { list2.handleNext(); } while (list2.hasRetain()) { w += list2.handleRetain(); } assertEquals(w, "a big world!"); assertEquals(list2.totalSize(), 0); assertEquals(list2.handleSize(), 0); }
/** Test method for {@link org.apache.niolex.commons.collection.RetainLinkedList#handleNext()}. */ @Test(expected = NullPointerException.class) public void testHandleNextCover() throws Exception { RetainLinkedList<String> other = new RetainLinkedList<String>(3); other.add("It "); other.add("is "); other.add("a "); other.add("big "); other.add("world!"); RetainLinkedList<String> list = new RetainLinkedList<String>(3); Field field = FieldUtil.getField(RetainLinkedList.class, "headPointerSize"); FieldUtil.setFieldValue(list, field, 5); // --- field = FieldUtil.getField(RetainLinkedList.class, "pointer"); Object ppt = FieldUtil.getFieldValue(other, field); FieldUtil.setFieldValue(list, field, ppt); list.handleNext(); }