Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java Thu Sep 15 20:27:39 2011 @@ -16,15 +16,15 @@ */ package org.apache.commons.functor.example; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import org.apache.commons.functor.BinaryFunction; import org.apache.commons.functor.UnaryFunction; import org.apache.commons.functor.core.Constant; @@ -34,6 +34,7 @@ import org.apache.commons.functor.core.c import org.apache.commons.functor.core.composite.ConditionalUnaryFunction; import org.apache.commons.functor.generator.FilteredGenerator; import org.apache.commons.functor.generator.IteratorToGeneratorAdapter; +import org.junit.Test; /* * ---------------------------------------------------------------------------- @@ -59,21 +60,7 @@ import org.apache.commons.functor.genera * @author Rodney Waldhoff */ @SuppressWarnings("unchecked") -public class QuicksortExample extends TestCase { - -/* - * Let's declare the constructor and suite() methods we need - * to ensure this test suite can be executed along with all the - * others: - */ - - public QuicksortExample(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(QuicksortExample.class); - } +public class QuicksortExample { /* * ---------------------------------------------------------------------------- @@ -94,6 +81,7 @@ public class QuicksortExample extends Te * Sorting an empty List should produce an empty list: */ + @Test public void testSortEmpty() { List empty = Collections.EMPTY_LIST; List result = quicksort(empty); @@ -105,6 +93,7 @@ public class QuicksortExample extends Te * should produce an equivalent list: */ + @Test public void testSortSingleElementList() { List list = new ArrayList(); list.add("element"); @@ -126,6 +115,7 @@ public class QuicksortExample extends Te * of a single value should produce an equivalent list: */ + @Test public void testSortSingleValueList() { List list = new ArrayList(); for (int i = 0; i < 10; i++) { @@ -147,6 +137,7 @@ public class QuicksortExample extends Te * * Sorting an already sorted list: */ + @Test public void testSortSorted() { List list = new ArrayList(); for (int i = 0; i < 10; i++) { @@ -169,6 +160,7 @@ public class QuicksortExample extends Te * Sorting a reverse-order list (finally, a test case that requires something * more than an identity function): */ + @Test public void testSortReversed() { List expected = new ArrayList(); List tosort = new ArrayList(); @@ -189,6 +181,7 @@ public class QuicksortExample extends Te /* * Just for fun, let's add some randomness to the tests, first by shuffling: */ + @Test public void testSortShuffled() { List expected = new ArrayList(); for (int i = 0; i < 10; i++) { @@ -203,6 +196,7 @@ public class QuicksortExample extends Te /* * and then using random values: */ + @Test public void testSortRandom() { Random random = new Random(); /* @@ -232,6 +226,7 @@ public class QuicksortExample extends Te private static final int SIZE = 1000; private static final int COUNT = 100; + @Test public void testTimings() { /* * We'll need the total elapsed time:
Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/four/TestSoccer.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/four/TestSoccer.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/four/TestSoccer.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/four/TestSoccer.java Thu Sep 15 20:27:39 2011 @@ -16,9 +16,9 @@ */ package org.apache.commons.functor.example.kata.four; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * See http://pragprog.com/pragdave/Practices/Kata/KataFour.rdoc,v @@ -27,15 +27,9 @@ import junit.framework.TestSuite; * @version $Revision$ $Date$ * @author Rodney Waldhoff */ -public class TestSoccer extends TestCase { - public TestSoccer(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(TestSoccer.class); - } +public class TestSoccer { + @Test public void testProcess() { // for our soccer example, we want to select the second column of the // line with the minimal difference between the seventh and ninth columns. Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java Thu Sep 15 20:27:39 2011 @@ -16,9 +16,7 @@ */ package org.apache.commons.functor.example.kata.one; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; import org.apache.commons.functor.UnaryFunction; import org.apache.commons.functor.adapter.BinaryFunctionUnaryFunction; @@ -27,6 +25,7 @@ import org.apache.commons.functor.core.c import org.apache.commons.functor.core.composite.Composite; import org.apache.commons.functor.core.composite.ConditionalUnaryFunction; import org.apache.commons.functor.core.composite.UnaryCompositeBinaryFunction; +import org.junit.Test; /** * Dave Thomas's Kata One asks us to think about how one might @@ -51,22 +50,7 @@ import org.apache.commons.functor.core.c * @version $Revision$ $Date$ * @author Rodney Waldhoff */ -public class SupermarketPricingExample extends TestCase { - public SupermarketPricingExample(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(SupermarketPricingExample.class); - } - - public void setUp() throws Exception { - super.setUp(); - } - - public void tearDown() throws Exception { - super.tearDown(); - } +public class SupermarketPricingExample { // tests //---------------------------------------------------------- @@ -84,6 +68,7 @@ public class SupermarketPricingExample e * special Product constructor to wrap up create the * functors for us. */ + @Test public void testConstantPricePerUnit() throws Exception { { Product beans = new Product( @@ -131,6 +116,7 @@ public class SupermarketPricingExample e * * We can implement either: */ + @Test public void testFourForADollar_A() throws Exception { Product banana = new Product( "Banana", @@ -153,6 +139,7 @@ public class SupermarketPricingExample e } + @Test public void testFourForADollar_B() throws Exception { Product banana = new Product( "Banana", @@ -189,6 +176,7 @@ public class SupermarketPricingExample e * * For example... */ + @Test public void testBuyTwoGetOneFree_1() throws Exception { Product apple = new Product( "Apple", @@ -248,6 +236,7 @@ public class SupermarketPricingExample e private int n, m, costPerUnit; } + @Test public void testBuyTwoGetOneFree_2() throws Exception { Product apple = new Product( "Apple", @@ -267,7 +256,8 @@ public class SupermarketPricingExample e assertEquals(new Money(7*40),apple.getPrice(10)); } - public void testBuyThreeGetTwoFree() throws Exception { + @Test + public void testBuyThreeGetTwoFree() throws Exception { Product apple = new Product( "Apple", "SKU-0003", @@ -287,6 +277,7 @@ public class SupermarketPricingExample e assertEquals(new Money(7*40),apple.getPrice(11)); } + @Test public void testBuyTwoGetFiveFree() throws Exception { Product apple = new Product( "Apple", Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java Thu Sep 15 20:27:39 2011 @@ -16,19 +16,18 @@ */ package org.apache.commons.functor.example.kata.two; +import static org.junit.Assert.assertEquals; + import java.util.Collections; import java.util.List; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import org.apache.commons.functor.Function; import org.apache.commons.functor.Predicate; import org.apache.commons.functor.Procedure; import org.apache.commons.functor.core.algorithm.RecursiveEvaluation; import org.apache.commons.functor.core.algorithm.UntilDo; import org.apache.commons.functor.generator.util.IntegerRange; +import org.junit.Test; /** * Examples of binary search implementations. @@ -74,14 +73,7 @@ import org.apache.commons.functor.genera * @author Rodney Waldhoff */ @SuppressWarnings("unchecked") -public class TestBinaryChop extends TestCase { - public TestBinaryChop(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(TestBinaryChop.class); - } +public class TestBinaryChop { /** * This is Dave's test case, plus @@ -126,6 +118,7 @@ public class TestBinaryChop extends Test * java.util.Collections, but that's not * really the point of this exercise. */ + @Test public void testBuiltIn() { chopTest(new BaseBinaryChop() { public int find(Object seeking, List list) { @@ -155,6 +148,7 @@ public class TestBinaryChop extends Test * that we can return -1 if the element is not yet * in the list. */ + @Test public void testIterative() { chopTest(new BaseBinaryChop() { public int find(Object seeking, List list) { @@ -278,6 +272,7 @@ public class TestBinaryChop extends Test * Now we can use the Algorithms.dountil method to * execute that loop: */ + @Test public void testIterativeWithInvariants() { chopTest(new BaseBinaryChop() { @@ -395,6 +390,7 @@ public class TestBinaryChop extends Test private final List list; } + @Test public void testIterativeWithInvariantsAndAssertions() { chopTest(new BaseBinaryChop() { public int find(Object seeking, List list) { @@ -409,6 +405,7 @@ public class TestBinaryChop extends Test * method parameters to track the upper and * lower bounds. */ + @Test public void testRecursive() { chopTest(new BaseBinaryChop() { public int find(Object seeking, List list) { @@ -442,6 +439,7 @@ public class TestBinaryChop extends Test * tail recursion, since there is a bit of state * to be tracked. */ + @Test public void testTailRecursive() { chopTest(new BaseBinaryChop() { public int find(final Object seeking, final List list) { @@ -487,6 +485,7 @@ public class TestBinaryChop extends Test * is probably less efficient than either the iterative * or the recursive implemenations above. */ + @Test public void testRecursive2() { chopTest(new BaseBinaryChop() { public int find(Object seeking, List list) { @@ -516,6 +515,7 @@ public class TestBinaryChop extends Test * Again, the anonymous Function implemenation * holds the "continuation" state. */ + @Test public void testTailRecursive2() { chopTest(new BaseBinaryChop() { public int find(final Object seeking, final List list) { Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java Thu Sep 15 20:27:39 2011 @@ -16,47 +16,34 @@ */ package org.apache.commons.functor.generator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -//import org.apache.commons.functor.UnaryPredicate; import org.apache.commons.functor.UnaryProcedure; -//import org.apache.commons.functor.adapter.LeftBoundPredicate; -//import org.apache.commons.functor.core.IsEqual; import org.apache.commons.functor.generator.util.CollectionTransformer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Tests the Base Generator class. * @author Jason Horman (ja...@jhorman.org) */ @SuppressWarnings("unchecked") -public class TestBaseGenerator extends TestCase { +public class TestBaseGenerator { private Generator simpleGenerator = null; - // Conventional - // ------------------------------------------------------------------------ - - public TestBaseGenerator(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(TestBaseGenerator.class); - } - // Lifecycle // ------------------------------------------------------------------------ + @Before public void setUp() throws Exception { - super.setUp(); - simpleGenerator = new BaseGenerator() { public void run(UnaryProcedure proc) { for (int i=0;i<5;i++) { @@ -85,8 +72,8 @@ public class TestBaseGenerator extends T } } + @After public void tearDown() throws Exception { - super.tearDown(); simpleGenerator = null; list = null; evens = null; @@ -97,6 +84,7 @@ public class TestBaseGenerator extends T // Tests // ------------------------------------------------------------------------ + @Test public void testSimpleGenerator() { final StringBuffer result = new StringBuffer(); simpleGenerator.run(new UnaryProcedure() { @@ -108,6 +96,7 @@ public class TestBaseGenerator extends T assertEquals("01234", result.toString()); } + @Test public void testStop() { final StringBuffer result = new StringBuffer(); simpleGenerator.run(new UnaryProcedure() { @@ -123,6 +112,7 @@ public class TestBaseGenerator extends T assertEquals("012", result.toString()); } + @Test public void testWrappingGenerator() { final StringBuffer result = new StringBuffer(); final Generator gen = new BaseGenerator(simpleGenerator) { @@ -163,6 +153,7 @@ public class TestBaseGenerator extends T // Tests // ------------------------------------------------------------------------ + @Test public void testTo() { Collection col = (Collection) simpleGenerator.to(new CollectionTransformer()); assertEquals("[0, 1, 2, 3, 4]", col.toString()); Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java Thu Sep 15 20:27:39 2011 @@ -16,14 +16,19 @@ */ package org.apache.commons.functor.generator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.apache.commons.functor.BaseFunctorTest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * @version $Revision$ $Date$ @@ -32,17 +37,6 @@ import org.apache.commons.functor.BaseFu @SuppressWarnings("unchecked") public class TestIteratorToGeneratorAdapter extends BaseFunctorTest { - // Conventional - // ------------------------------------------------------------------------ - - public TestIteratorToGeneratorAdapter(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(TestIteratorToGeneratorAdapter.class); - } - public Object makeFunctor() { List list = new ArrayList(); list.add("1"); @@ -54,30 +48,33 @@ public class TestIteratorToGeneratorAdap private List list = null; + @Before public void setUp() throws Exception { - super.setUp(); list = new ArrayList(); list.add("1"); list.add("two"); list.add("c"); } + @After public void tearDown() throws Exception { - super.tearDown(); list = null; } // Tests // ------------------------------------------------------------------------ + @Test public void testAdaptNull() { assertNull(IteratorToGeneratorAdapter.adapt(null)); } + @Test public void testAdaptNonNull() { assertNotNull(IteratorToGeneratorAdapter.adapt(list.iterator())); } + @Test public void testGenerate() { Iterator iter = list.iterator(); Generator gen = new IteratorToGeneratorAdapter(iter); @@ -86,6 +83,7 @@ public class TestIteratorToGeneratorAdap assertEquals(list,list2); } + @Test public void testConstructNull() { try { new IteratorToGeneratorAdapter(null); @@ -95,6 +93,7 @@ public class TestIteratorToGeneratorAdap } } + @Test public void testEquals() { Iterator iter = list.iterator(); Generator gen = new IteratorToGeneratorAdapter(iter); Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java Thu Sep 15 20:27:39 2011 @@ -16,6 +16,9 @@ */ package org.apache.commons.functor.generator.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -23,9 +26,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.core.Limit; import org.apache.commons.functor.core.Offset; @@ -33,6 +33,8 @@ import org.apache.commons.functor.genera import org.apache.commons.functor.generator.GenerateWhile; import org.apache.commons.functor.generator.UntilGenerate; import org.apache.commons.functor.generator.WhileGenerate; +import org.junit.Before; +import org.junit.Test; /** * @author Jason Horman (ja...@jhorman.org) @@ -44,17 +46,6 @@ public class TestEachElement extends Bas private Map map = null; private Object[] array = null; - // Conventional - // ------------------------------------------------------------------------ - - public TestEachElement(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(TestEachElement.class); - } - protected Object makeFunctor() throws Exception { return EachElement.from(new ArrayList()); } @@ -62,9 +53,8 @@ public class TestEachElement extends Bas // Lifecycle // ------------------------------------------------------------------------ + @Before public void setUp() throws Exception { - super.setUp(); - list = new ArrayList(); list.add(new Integer(0)); list.add(new Integer(1)); @@ -87,13 +77,10 @@ public class TestEachElement extends Bas array[4] = "5"; } - public void tearDown() throws Exception { - super.tearDown(); - } - // Tests // ------------------------------------------------------------------------ + @Test public void testFromNull() { assertNull(EachElement.from((Collection) null)); assertNull(EachElement.from((Map) null)); @@ -102,11 +89,13 @@ public class TestEachElement extends Bas } + @Test public void testWithList() { Collection col = EachElement.from(list).toCollection(); assertEquals("[0, 1, 2, 3, 4]", col.toString()); } + @Test public void testWithMap() { List col = (List) EachElement.from(map).toCollection(); int i = 0; @@ -128,11 +117,13 @@ public class TestEachElement extends Bas assertEquals(5, i); } + @Test public void testWithArray() { Collection col = EachElement.from(array).toCollection(); assertEquals("[1, 2, 3, 4, 5]", col.toString()); } + @Test public void testWithStop() { assertEquals("[0, 1, 2]", new UntilGenerate(new Offset(3), EachElement.from(list)).toCollection().toString()); assertEquals("[0, 1, 2, 3]", new GenerateUntil(EachElement.from(list), new Offset(3)).toCollection().toString()); @@ -140,6 +131,7 @@ public class TestEachElement extends Bas assertEquals("[0, 1, 2, 3]", new GenerateWhile(EachElement.from(list), new Limit(3)).toCollection().toString()); } + @Test public void testWithIterator() { Collection col = EachElement.from(list.iterator()).toCollection(); assertEquals("[0, 1, 2, 3, 4]", col.toString()); Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java Thu Sep 15 20:27:39 2011 @@ -16,13 +16,14 @@ */ package org.apache.commons.functor.generator.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.List; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.apache.commons.functor.BaseFunctorTest; +import org.junit.Test; /** * @version $Revision$ $Date$ @@ -31,16 +32,6 @@ import org.apache.commons.functor.BaseFu */ @SuppressWarnings("unchecked") public class TestIntegerRange extends BaseFunctorTest { - // Conventional - // ------------------------------------------------------------------------ - - public TestIntegerRange(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(TestIntegerRange.class); - } protected Object makeFunctor() throws Exception { return new IntegerRange(10, 20); @@ -49,6 +40,7 @@ public class TestIntegerRange extends Ba // Tests // ------------------------------------------------------------------------ + @Test public void testGenerateListExample() { // generates a collection of Integers from 0 (inclusive) to 10 (exclusive) { @@ -67,6 +59,7 @@ public class TestIntegerRange extends Ba } } + @Test public void testStepChecking() { { new IntegerRange(2, 2, 0); // step of 0 is ok when range is empty @@ -103,6 +96,7 @@ public class TestIntegerRange extends Ba } } + @Test public void testObjectConstructor() { IntegerRange range = new IntegerRange(new Integer(0), new Integer(5)); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); @@ -111,36 +105,42 @@ public class TestIntegerRange extends Ba } + @Test public void testReverseStep() { IntegerRange range = new IntegerRange(10, 0, -2); assertEquals("[10, 8, 6, 4, 2]", range.toCollection().toString()); assertEquals("[10, 8, 6, 4, 2]", range.toCollection().toString()); } + @Test public void testStep() { IntegerRange range = new IntegerRange(0, 10, 2); assertEquals("[0, 2, 4, 6, 8]", range.toCollection().toString()); assertEquals("[0, 2, 4, 6, 8]", range.toCollection().toString()); } + @Test public void testForwardRange() { IntegerRange range = new IntegerRange(0, 5); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); } + @Test public void testReverseRange() { IntegerRange range = new IntegerRange(5, 0); assertEquals("[5, 4, 3, 2, 1]", range.toCollection().toString()); assertEquals("[5, 4, 3, 2, 1]", range.toCollection().toString()); } + @Test public void testEdgeCase() { IntegerRange range = new IntegerRange(Integer.MAX_VALUE - 3, Integer.MAX_VALUE); assertEquals("[2147483644, 2147483645, 2147483646]", range.toCollection().toString()); assertEquals("[2147483644, 2147483645, 2147483646]", range.toCollection().toString()); } + @Test public void testEquals() { IntegerRange range = new IntegerRange(1, 5); assertObjectsAreEqual(range, range); Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java?rev=1171255&r1=1171254&r2=1171255&view=diff ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java (original) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java Thu Sep 15 20:27:39 2011 @@ -16,13 +16,14 @@ */ package org.apache.commons.functor.generator.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.List; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.apache.commons.functor.BaseFunctorTest; +import org.junit.Test; /** * @version $Revision$ $Date$ @@ -31,16 +32,6 @@ import org.apache.commons.functor.BaseFu */ @SuppressWarnings("unchecked") public class TestLongRange extends BaseFunctorTest { - // Conventional - // ------------------------------------------------------------------------ - - public TestLongRange(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(TestLongRange.class); - } protected Object makeFunctor() throws Exception { return new LongRange(10, 20); @@ -49,6 +40,7 @@ public class TestLongRange extends BaseF // Tests // ------------------------------------------------------------------------ + @Test public void testGenerateListExample() { // generates a collection of Integers from 0 (inclusive) to 10 (exclusive) { @@ -67,6 +59,7 @@ public class TestLongRange extends BaseF } } + @Test public void testStepChecking() { { new LongRange(2, 2, 0); // step of 0 is ok when range is empty @@ -103,6 +96,7 @@ public class TestLongRange extends BaseF } } + @Test public void testObjectConstructor() { LongRange range = new LongRange(new Long(0), new Long(5)); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); @@ -111,36 +105,42 @@ public class TestLongRange extends BaseF } + @Test public void testReverseStep() { LongRange range = new LongRange(10, 0, -2); assertEquals("[10, 8, 6, 4, 2]", range.toCollection().toString()); assertEquals("[10, 8, 6, 4, 2]", range.toCollection().toString()); } + @Test public void testStep() { LongRange range = new LongRange(0, 10, 2); assertEquals("[0, 2, 4, 6, 8]", range.toCollection().toString()); assertEquals("[0, 2, 4, 6, 8]", range.toCollection().toString()); } + @Test public void testForwardRange() { LongRange range = new LongRange(0, 5); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); assertEquals("[0, 1, 2, 3, 4]", range.toCollection().toString()); } + @Test public void testReverseRange() { LongRange range = new LongRange(5, 0); assertEquals("[5, 4, 3, 2, 1]", range.toCollection().toString()); assertEquals("[5, 4, 3, 2, 1]", range.toCollection().toString()); } + @Test public void testEdgeCase() { LongRange range = new LongRange(Long.MAX_VALUE - 3L, Long.MAX_VALUE); assertEquals("[9223372036854775804, 9223372036854775805, 9223372036854775806]", range.toCollection().toString()); assertEquals("[9223372036854775804, 9223372036854775805, 9223372036854775806]", range.toCollection().toString()); } + @Test public void testEquals() { LongRange range = new LongRange(1, 5); assertObjectsAreEqual(range, range);