From: David S. <ds...@us...> - 2006-02-15 22:55:47
|
Update of /cvsroot/junit/junit/junit4.0/junit/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13390/junit4.0/junit/samples Added Files: SimpleTest.java AllTests.java ListTest.java Log Message: Merged with branch, Kent will make final changes and launch. --- NEW FILE: SimpleTest.java --- package junit.samples; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Some simple tests. * */ public class SimpleTest extends TestCase { protected int fValue1; protected int fValue2; @Override protected void setUp() { fValue1= 2; fValue2= 3; } public static Test suite() { /* * the type safe way * TestSuite suite= new TestSuite(); suite.addTest( new SimpleTest("add") { protected void runTest() { testAdd(); } } ); suite.addTest( new SimpleTest("testDivideByZero") { protected void runTest() { testDivideByZero(); } } ); return suite; */ /* * the dynamic way */ return new TestSuite(SimpleTest.class); } public void testAdd() { double result= fValue1 + fValue2; // forced failure result == 5 assertTrue(result == 6); } public void testDivideByZero() { int zero= 0; int result= 8/zero; result++; // avoid warning for not using result } public void testEquals() { assertEquals(12, 12); assertEquals(12L, 12L); assertEquals(new Long(12), new Long(12)); assertEquals("Size", 12, 13); assertEquals("Capacity", 12.0, 11.99, 0.0); } public static void main (String[] args) { junit.textui.TestRunner.run(suite()); } } --- NEW FILE: AllTests.java --- package junit.samples; import junit.framework.Test; import junit.framework.TestSuite; /** * TestSuite that runs all the sample tests * */ public class AllTests { public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } public static Test suite ( ) { TestSuite suite= new TestSuite("All JUnit Tests"); suite.addTest(ListTest.suite()); suite.addTest(new TestSuite(junit.samples.money.MoneyTest.class)); suite.addTest(junit.tests.AllTests.suite()); return suite; } } --- NEW FILE: ListTest.java --- package junit.samples; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * A sample test case, testing <code>java.util.Vector</code>. * */ public class ListTest extends TestCase { protected List<Integer> fEmpty; protected List<Integer> fFull; public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } @Override protected void setUp() { fEmpty= new ArrayList<Integer>(); fFull= new ArrayList<Integer>(); fFull.add(1); fFull.add(2); fFull.add(3); } public static Test suite() { return new TestSuite(ListTest.class); } public void testCapacity() { int size= fFull.size(); for (int i= 0; i < 100; i++) fFull.add(new Integer(i)); assertTrue(fFull.size() == 100+size); } public void testContains() { assertTrue(fFull.contains(1)); assertTrue(!fEmpty.contains(1)); } public void testElementAt() { int i= fFull.get(0); assertTrue(i == 1); try { fFull.get(fFull.size()); } catch (IndexOutOfBoundsException e) { return; } fail("Should raise an ArrayIndexOutOfBoundsException"); } public void testRemoveAll() { fFull.removeAll(fFull); fEmpty.removeAll(fEmpty); assertTrue(fFull.isEmpty()); assertTrue(fEmpty.isEmpty()); } public void testRemoveElement() { fFull.remove(new Integer(3)); assertTrue(!fFull.contains(3) ); } } |