import org.junit.*; import static org.junit.Assert.*; // // Example of jUnit testing of the class LinkedList. Note that this is not // a complete test. Shown are all the details for the several steps of testing. public class TestLinkedList { LinkedList l1; // Fixtures here: method to initialize any common // objects during each test. // (Optional) @Before public void setup() { l1 = new LinkedList(); } @After public void tearDown() { l1.clear(); } // Individual test routines here. These are in the order they were written. @Test public void testToString() { System.out.println( "l1 = " + l1.toString() ); l1.add( "one" ); System.out.println( "l1 = " + l1.toString() ); l1.add( "two" ); System.out.println( "l1 = " + l1.toString() ); l1.add( "three" ); System.out.println( "l1 = " + l1.toString() ); assertTrue( true ); } @Test public void testAdd() { assertTrue( l1.isEmpty() ); assertTrue( l1.size() == 0 ); l1.add( "one" ); assertFalse( l1.isEmpty() ); assertTrue( l1.size() == 1 ); l1.add( "two" ); assertFalse( l1.isEmpty() ); assertTrue( l1.size() == 2 ); l1.add( "three" ); assertFalse( l1.isEmpty() ); assertTrue( l1.size() == 3 ); } @Test public void testGet() { l1.add( "one" ); l1.add( "two" ); l1.add( "three" ); assertTrue( l1.get(0).equals( "one" ) ); assertFalse( l1.get(0).equals( "two" ) ); assertFalse( l1.get(0).equals( "three" ) ); assertFalse( l1.get(1).equals( "one" ) ); assertTrue( l1.get(1).equals( "two" ) ); assertFalse( l1.get(1).equals( "three" ) ); assertFalse( l1.get(2).equals( "one" ) ); assertFalse( l1.get(2).equals( "two" ) ); assertTrue( l1.get(2).equals( "three" ) ); } @Test public void testContains() { assertFalse( l1.contains( "" )); assertFalse( l1.contains( "one" )); l1.add( "one" ); assertTrue( l1.contains( "one" )); l1.add( "two" ); assertTrue( l1.contains( "one" )); assertTrue( l1.contains( "two" )); l1.add( "three" ); assertTrue( l1.contains( "one" )); assertTrue( l1.contains( "two" )); assertTrue( l1.contains( "three" )); assertFalse( l1.contains( "four" )); } public static void main( String[] args ) { org.junit.runner.JUnitCore.main("TestLinkedList"); } }