/** Runs all the tests using a textual runner. This is the * alternative to running all the tests within your favorite * development environment (DrJava, Eclipse...). This may require * downloading JUnit from www.junit.org. * * > javac -cp junit-4.8.jar:. TestPath.java * > java -cp junit-4.8.jar:. TestPath * * @author Marcel Turcotte (turcotte@site.uottawa.ca) */ import junit.framework.Assert; import junit.framework.TestCase; import junit.framework.TestSuite; public class TestPath extends TestCase { private Path path1, path2, path3; public TestPath() { path1 = new Path( null, "http://www.example.org" ); path2 = new Path( path1, "http://www.example.com" ); path3 = new Path( path2, "http://www.google.ca" ); } public void testSingletonSize() { Assert.assertTrue( path1.size() == 1 ); } public void testSingletonGetURL() { Assert.assertEquals( "http://www.example.org", path1.getURL( 0 ) ); } public void testSingletonGetLastURL() { Assert.assertEquals( "http://www.example.org", path1.getLastURL() ); } public void testSingletonContains() { Assert.assertTrue( path1.contains( "http://www.example.org" ) ); Assert.assertFalse( path1.contains( "http://www.example.com" ) ); } public void testTupleSize() { Assert.assertTrue( path2.size() == 2 ); } public void testTupleGetURL() { Assert.assertEquals( "http://www.example.org", path2.getURL( 0 ) ); Assert.assertEquals( "http://www.example.com", path2.getURL( 1 ) ); } public void testTupleGetLastURL() { Assert.assertEquals( "http://www.example.org", path2.getURL( 0 ) ); Assert.assertEquals( "http://www.example.com", path2.getURL( 1 ) ); } public void testTupleContains() { Assert.assertTrue( path2.contains( "http://www.example.org" ) ); Assert.assertTrue( path2.contains( "http://www.example.com" ) ); Assert.assertFalse( path2.contains( "http://www.google.ca" ) ); } public void testTripletSize() { Assert.assertTrue( path3.size() == 3 ); } public void testTripletGetURL() { Assert.assertEquals( "http://www.example.org", path3.getURL( 0 ) ); Assert.assertEquals( "http://www.example.com", path3.getURL( 1 ) ); Assert.assertEquals( "http://www.google.ca", path3.getURL( 2 ) ); } public void testTripletGetLastURL() { Assert.assertEquals( "http://www.google.ca", path3.getLastURL() ); } public void testTripletContains() { Assert.assertTrue( path3.contains( "http://www.example.org" ) ); Assert.assertTrue( path3.contains( "http://www.example.com" ) ); Assert.assertTrue( path3.contains( "http://www.google.ca" ) ); Assert.assertFalse( path3.contains( "http://www.site.uottawa.ca" ) ); } /** * Runs the test suite using the textual runner. */ public static void main( String[] args ) { StudentInfo.display(); TestSuite suite = new TestSuite(); suite.addTestSuite( TestPath.class ); junit.textui.TestRunner.run( suite ); } }