svn commit: r1365025 - in /commons/proper/chain/trunk: core/src/main/java/org/apache/commons/chain2/ core/src/test/java/org/apache/commons/chain2/impl/ src/changes/
Author: simonetripodi Date: Tue Jul 24 12:57:56 2012 New Revision: 1365025 URL: http://svn.apache.org/viewvc?rev=1365025&view=rev Log: [CHAIN-70] Add a small EDSL to simplify Catalog setup Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/NameSetter.java (with props) commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/NamedCommandSetter.java (with props) Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java commons/proper/chain/trunk/src/changes/changes.xml Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java?rev=1365025&r1=1365024&r2=1365025&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java Tue Jul 24 12:57:56 2012 @@ -16,6 +16,8 @@ */ package org.apache.commons.chain2; +import static java.lang.String.format; + import java.util.Map; /** @@ -41,6 +43,20 @@ public final class Chains { } /** + * Defines the target {@link Catalog} has to be invoked. + * + * @param Context key type + * @param Context value type + * @param Type of the context associated with this command + * @param Type of the {@link Chain} to execute + * @param catalog the catalog instance reference to be setup + * @return next chain builder + */ +public static , CA extends Catalog> NamedCommandSetter on(CA catalog) { +return new DefaultNamedCommandSetter(checkNotNullArgument(catalog, "Null Catalog can not be setup")); +} + +/** * Private constructor, this class cannot be instantiated directly. */ private Chains() { @@ -81,9 +97,44 @@ public final class Chains { } -private static T checkNotNullArgument(T reference, String message) { +private static final class DefaultNamedCommandSetter> +implements NamedCommandSetter { + +private final Catalog catalog; + +public DefaultNamedCommandSetter(Catalog catalog) { +this.catalog = catalog; +} + +public > NameSetter addCommand(CMD command) { +CMD checkedCommand = checkNotNullArgument( command, "Catalog does not accept null Command instances" ); +return new DefaultNameSetter(catalog, checkedCommand); +} + +} + +private static final class DefaultNameSetter> implements NameSetter { + +private final Catalog catalog; + +private final Command command; + +public DefaultNameSetter(Catalog catalog, Command command) { +this.catalog = catalog; +this.command = command; +} + +public NamedCommandSetter identifiedBy(String name) { +catalog.addCommand(checkNotNullArgument(name, "Command <%s> cannot be identified by a null name", command), + command); +return new DefaultNamedCommandSetter(catalog); +} + +} + +private static T checkNotNullArgument(T reference, String message, Object...args) { if (reference == null) { -throw new IllegalArgumentException(message); +throw new IllegalArgumentException(format(message, args)); } return reference; } Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java?rev=1365025&r1=1365024&r2=1365025&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java Tue Jul 24 12:57:56 2012 @@ -24,11 +24,11 @@ import java.util.Map; * @param Context key type * @param Context value type * @param Type of the context associated with this command setter - * @param Type of the next chain builder + * @param Type of the next chain builder * @since 2.0 * @version $Id$ */ -public interface CommandSetter, CS extends CommandSetter> { +public interface CommandSetter, R> { /** * Add the given command to the target {@link Chain} has to be executed. @@ -38,6 +38,6 @@ public interface CommandSetter> CS addCommand(CMD command); +> R addCommand(CMD command); } Added: commons/pr
svn commit: r1365049 - in /commons/proper/chain/trunk: core/src/main/java/org/apache/commons/chain2/ core/src/main/java/org/apache/commons/chain2/impl/ core/src/test/java/org/apache/commons/chain2/imp
Author: simonetripodi Date: Tue Jul 24 13:40:08 2012 New Revision: 1365049 URL: http://svn.apache.org/viewvc?rev=1365049&view=rev Log: [CHAIN-74] Improve Chain/Catalog use of Generics Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Catalog.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CatalogFactory.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java commons/proper/chain/trunk/src/changes/changes.xml Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Catalog.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Catalog.java?rev=1365049&r1=1365048&r2=1365049&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Catalog.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Catalog.java Tue Jul 24 13:40:08 2012 @@ -45,21 +45,23 @@ public interface Catalog the {@link Command} type to be added in the {@link Catalog} * @param name Name of the new command * @param command {@link Command} or {@link Chain} to be returned * for later lookups on this name */ -void addCommand(String name, Command command); +> void addCommand(String name, CMD command); /** * Return the {@link Command} or {@link Chain} associated with the * specified name, if any; otherwise, return null. * + * @param the expected {@link Command} type to be returned * @param name Name for which a {@link Command} or {@link Chain} * should be retrieved * @return The Command associated with the specified name. */ -Command getCommand(String name); +> CMD getCommand(String name); /** * Return an Iterator over the set of named commands Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CatalogFactory.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CatalogFactory.java?rev=1365049&r1=1365048&r2=1365049&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CatalogFactory.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CatalogFactory.java Tue Jul 24 13:40:08 2012 @@ -108,6 +108,7 @@ public abstract class CatalogFactoryIllegalArgumentException to be thrown. * + * @param the expected {@link Command} type to be returned * @param commandID the identifier of the command to return * @return the command located with commandID, or null * if either the command name or the catalog name cannot be resolved @@ -116,7 +117,7 @@ public abstract class CatalogFactory getCommand(String commandID) { +public > CMD getCommand(String commandID) { String commandName = commandID; String catalogName = null; Catalog catalog = null; @@ -150,7 +151,7 @@ public abstract class CatalogFactorygetCommand(commandName); } // --- Static Variables Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java?rev=1365049&r1=1365048&r2=1365049&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java Tue Jul 24 13:40:08 2012 @@ -63,6 +63,7 @@ public interface Chain * + * @param the {@link Command} type to be added in the {@link Chain} * @param command The {@link Command} to be added * * @exception IllegalArgumentException if command @@ -70,7 +71,7 @@ public interface Chain command); +> void addCommand(CMD command); /** * Execute the processing represented by this {@link Chain} according Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java?rev=1365049&r1=1365048&r2=1365049&view=diff == --- commons/proper
svn commit: r1365107 - in /commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config: ConfigParser2TestCase.java ConfigParserTestCase.java
Author: simonetripodi Date: Tue Jul 24 15:04:08 2012 New Revision: 1365107 URL: http://svn.apache.org/viewvc?rev=1365107&view=rev Log: fixed boken tests (on Continuum) after introduced [CHAIN-74] Modified: commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParser2TestCase.java commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParserTestCase.java Modified: commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParser2TestCase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParser2TestCase.java?rev=1365107&r1=1365106&r2=1365107&view=diff == --- commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParser2TestCase.java (original) +++ commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParser2TestCase.java Tue Jul 24 15:04:08 2012 @@ -103,43 +103,47 @@ public class ConfigParser2TestCase { checkCommandCount(17); // Check individual single command instances -Command> command = null; +{ +AddingCommand command = catalog.getCommand("AddingCommand"); +assertNotNull(command); +} + +{ +DelegatingCommand command = catalog.getCommand("DelegatingCommand"); +assertNotNull(command); +} + +{ +DelegatingFilter command = catalog.getCommand("DelegatingFilter"); +assertNotNull(command); +} + +{ +ExceptionCommand command = catalog.getCommand("ExceptionCommand"); +assertNotNull(command); +} + +{ +ExceptionFilter command = catalog.getCommand("ExceptionFilter"); +assertNotNull(command); +} + +{ +NonDelegatingCommand command = catalog.getCommand("NonDelegatingCommand"); +assertNotNull(command); +} + +{ +NonDelegatingFilter command = catalog.getCommand("NonDelegatingFilter"); +assertNotNull(command); +} -command = catalog.getCommand("AddingCommand"); -assertNotNull(command); -assertTrue(command instanceof AddingCommand); - -command = catalog.getCommand("DelegatingCommand"); -assertNotNull(command); -assertTrue(command instanceof DelegatingCommand); - -command = catalog.getCommand("DelegatingFilter"); -assertNotNull(command); -assertTrue(command instanceof DelegatingFilter); - -command = catalog.getCommand("ExceptionCommand"); -assertNotNull(command); -assertTrue(command instanceof ExceptionCommand); - -command = catalog.getCommand("ExceptionFilter"); -assertNotNull(command); -assertTrue(command instanceof ExceptionFilter); - -command = catalog.getCommand("NonDelegatingCommand"); -assertNotNull(command); -assertTrue(command instanceof NonDelegatingCommand); - -command = catalog.getCommand("NonDelegatingFilter"); -assertNotNull(command); -assertTrue(command instanceof NonDelegatingFilter); - -command = catalog.getCommand("ChainBase"); -assertNotNull(command); -assertTrue(command instanceof ChainBase); -assertTrue(command instanceof TestChain); +ChainBase chain = catalog.getCommand("ChainBase"); +assertNotNull(chain); +assertTrue(chain instanceof TestChain); // Check configurable properties instance -TestCommand tcommand = (TestCommand) catalog.getCommand("Configurable"); +TestCommand tcommand = catalog.getCommand("Configurable"); assertNotNull(tcommand); assertEquals("Foo Value", tcommand.getFoo()); assertEquals("Bar Value", tcommand.getBar()); Modified: commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParserTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParserTestCase.java?rev=1365107&r1=1365106&r2=1365107&view=diff == --- commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParserTestCase.java (original) +++ commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/ConfigParserTestCase.java Tue Jul 24 15:04:08 2012 @@ -115,43 +115,47 @@ public class ConfigParserTestCase { checkCommandCount(17); // Check individual single command instances -Command> command = null; +{ +AddingCommand command = catalog.getCommand("AddingCommand"); +
svn commit: r1365238 - /commons/proper/digester/trunk/src/changes/changes.xml
Author: elijah Date: Tue Jul 24 19:24:30 2012 New Revision: 1365238 URL: http://svn.apache.org/viewvc?rev=1365238&view=rev Log: Added update to changes.xml for checkin for DIGESTER-166 fix. Modified: commons/proper/digester/trunk/src/changes/changes.xml Modified: commons/proper/digester/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/changes/changes.xml?rev=1365238&r1=1365237&r2=1365238&view=diff == --- commons/proper/digester/trunk/src/changes/changes.xml (original) +++ commons/proper/digester/trunk/src/changes/changes.xml Tue Jul 24 19:24:30 2012 @@ -23,6 +23,9 @@ + + Link to core APIs page in documentation was broken + BinderClassLoader does not override getResource
svn commit: r1365262 - in /commons/proper/chain/trunk: apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ core/src/main/java/org/apache/commons/chain2/ core/src/main/java/org/apache/c
Author: elijah Date: Tue Jul 24 19:56:21 2012 New Revision: 1365262 URL: http://svn.apache.org/viewvc?rev=1365262&view=rev Log: CHAIN-75 Updated serialVersionUID field in chain classes to a format based on the current date Modified: commons/proper/chain/trunk/apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ExampleServlet.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ContextBase.java commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ContextMap.java commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/TestContext.java commons/proper/chain/trunk/src/changes/changes.xml commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/ChainServlet.java commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/WebContext.java commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/faces/FacesWebContext.java commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/portlet/PortletWebContext.java commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/servlet/ChainProcessor.java commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/servlet/ServletWebContext.java Modified: commons/proper/chain/trunk/apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ExampleServlet.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ExampleServlet.java?rev=1365262&r1=1365261&r2=1365262&view=diff == --- commons/proper/chain/trunk/apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ExampleServlet.java (original) +++ commons/proper/chain/trunk/apps/example2/src/main/java/org/apache/commons/chain2/apps/example/ExampleServlet.java Tue Jul 24 19:56:21 2012 @@ -39,7 +39,7 @@ public class ExampleServlet extends Http /** * */ -private static final long serialVersionUID = 1L; +private static final long serialVersionUID = 20120724L; private String servletName; Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java?rev=1365262&r1=1365261&r2=1365262&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java Tue Jul 24 19:56:21 2012 @@ -30,7 +30,7 @@ public class ChainException extends Runt /** * */ -private static final long serialVersionUID = 1L; +private static final long serialVersionUID = 20120724L; /** * Context used when exception occurred. Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java?rev=1365262&r1=1365261&r2=1365262&view=diff == --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java (original) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java Tue Jul 24 19:56:21 2012 @@ -16,11 +16,11 @@ */ package org.apache.commons.chain2.generic; -import java.util.Map; - import org.apache.commons.chain2.ChainException; import org.apache.commons.chain2.Command; +import java.util.Map; + /** * Runtime Exception that wraps an underlying exception thrown during the * execution of a {@link org.apache.commons.chain2.Command} or {@link org.apache.commons.chain2.Chain}. @@ -32,7 +32,7 @@ public class DispatchException extends C /** * */ -private static final long serialVersionUID = 1L; +private static final long serialVersionUID = 20120724L; public DispatchException(String message) { super(message); Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ContextBase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ContextBase.java?rev=1365262&r1=1365261&r2=1365262&view=diff ==
svn commit: r1365325 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java test/java/org/apache/commons/functor/aggregator/AbstractN
Author: kinow Date: Tue Jul 24 22:14:33 2012 New Revision: 1365325 URL: http://svn.apache.org/viewvc?rev=1365325&view=rev Log: [FUNCTOR-12] Added test for AbstractListBackedAggregator no args constructor (created for JavaBean compatibility). Replaced the not-null-verification by Validate.notNull(). Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java?rev=1365325&r1=1365324&r2=1365325&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java Tue Jul 24 22:14:33 2012 @@ -19,6 +19,7 @@ package org.apache.commons.functor.aggre import java.util.List; import org.apache.commons.functor.UnaryFunction; +import org.apache.commons.lang3.Validate; /** * An aggregator which stores the data series in a List. Every call to @@ -99,10 +100,7 @@ public abstract class AbstractListBacked public AbstractListBackedAggregator(UnaryFunction, T> aggregationFunction, long interval, boolean useSharedTimer) { super(interval, useSharedTimer); -if (aggregationFunction == null) { -throw new NullPointerException("no function specified for aggregation"); -} -this.aggregationFunction = aggregationFunction; +this.aggregationFunction = Validate.notNull(aggregationFunction, "UnaryFunction argument must not be null"); this.series = createList(); } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java?rev=1365325&r1=1365324&r2=1365325&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java Tue Jul 24 22:14:33 2012 @@ -117,6 +117,11 @@ public class AbstractNoStoreAggregatorTe } } +@Test +public void testDataSize() { +assertEquals(0, new TestNoStoreAggregator(new Object()).retrieveDataSize()); +} + /** * Dummy binary function which always returns the first parameter. */
svn commit: r1365326 - in /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core: TestLeftIdentity.java TestRightIdentity.java
Author: kinow Date: Tue Jul 24 22:15:31 2012 New Revision: 1365326 URL: http://svn.apache.org/viewvc?rev=1365326&view=rev Log: Added tests to LeftIdentity and RightIdentity no args constructors (created for compatibility with tools using JavaBeans). Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java?rev=1365326&r1=1365325&r2=1365326&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java Tue Jul 24 22:15:31 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -43,6 +44,11 @@ public class TestLeftIdentity extends Ba // @Test +public void testJavabeanConstructor() { +assertNotNull(new LeftIdentity()); // Public constructor for JavaBean +} + +@Test public void testEvaluate() throws Exception { BinaryFunction f = LeftIdentity.FUNCTION; assertNull(f.evaluate(null,null)); Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java?rev=1365326&r1=1365325&r2=1365326&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java Tue Jul 24 22:15:31 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -43,6 +44,11 @@ public class TestRightIdentity extends B // @Test +public void testJavabeanConstructor() { +assertNotNull(new RightIdentity()); // Public constructor for JavaBean +} + +@Test public void testEvaluate() throws Exception { BinaryFunction f = RightIdentity.FUNCTION; assertNull(f.evaluate(null,null));
svn commit: r1365327 - /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
Author: kinow Date: Tue Jul 24 22:16:56 2012 New Revision: 1365327 URL: http://svn.apache.org/viewvc?rev=1365327&view=rev Log: [FUNCTOR-12] Added tests for FindWithinGenerator that cover untested branches. Replaced a try/catch + fail() by @Test(expected=SomeClass.class). Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java?rev=1365327&r1=1365326&r2=1365327&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java Tue Jul 24 22:16:56 2012 @@ -19,7 +19,6 @@ package org.apache.commons.functor.core. import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.Arrays; import java.util.List; @@ -29,7 +28,6 @@ import org.apache.commons.functor.BaseFu import org.apache.commons.functor.UnaryPredicate; import org.apache.commons.functor.adapter.LeftBoundPredicate; import org.apache.commons.functor.core.IsEqual; -import org.apache.commons.functor.core.algorithm.FindWithinGenerator; import org.apache.commons.functor.generator.IteratorToGeneratorAdapter; import org.junit.Test; @@ -76,14 +74,19 @@ public class TestFindWithinGenerator ext } @Test +public void testEquals() { +FindWithinGenerator f = new FindWithinGenerator(); +assertEquals(f,f); + +assertObjectsAreEqual(f,new FindWithinGenerator()); +assertObjectsAreEqual(new FindWithinGenerator(new Double(0)),new FindWithinGenerator(new Double(0))); +assertObjectsAreNotEqual(f, new FindWithinGenerator(new Integer(0))); +} + +@Test(expected=NoSuchElementException.class) public void testDetect() { assertEquals(new Integer(3),new FindWithinGenerator().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsThree)); -try { -new FindWithinGenerator().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsTwentyThree); -fail("Expected NoSuchElementException"); -} catch(NoSuchElementException e) { -// expected -} +new FindWithinGenerator().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsTwentyThree); } @Test
svn commit: r1365328 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/core/comparator/ test/java/org/apache/commons/functor/core/comparator/
Author: kinow Date: Tue Jul 24 22:19:23 2012 New Revision: 1365328 URL: http://svn.apache.org/viewvc?rev=1365328&view=rev Log: [FUNCTOR-12] Added more tests to core comparator classes. Also removed unreachable code, as it could not be tested and was immutable and created/validated during construction. Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java?rev=1365328&r1=1365327&r2=1365328&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java Tue Jul 24 22:19:23 2012 @@ -97,9 +97,6 @@ public final class IsEquivalent imple */ public boolean equals(IsEquivalent that) { if (null != that) { -if (null == comparator) { -return null == that.comparator; -} return comparator.equals(that.comparator); } return false; Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java?rev=1365328&r1=1365327&r2=1365328&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java Tue Jul 24 22:19:23 2012 @@ -97,9 +97,6 @@ public final class IsGreaterThan impl */ public boolean equals(IsGreaterThan that) { if (null != that) { -if (null == comparator) { -return null == that.comparator; -} return comparator.equals(that.comparator); } return false; Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java?rev=1365328&r1=1365327&r2=1365328&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java Tue Jul 24 22:19:23 2012 @@ -98,9 +98,6 @@ public final class IsGreaterThanOrEqual< */ public boolean equals(IsGreaterThanOrEqual that) { if (null != that) { -if (null == comparator) { -return null == that.comparator; -} return comparator.equals(that.comparator); } return false; Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java?rev=1365328&r1=1365327&r2=1365328&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java Tue Jul 24 22:19:23 2012 @@ -97,9 +97,6 @@ public final class IsLessThan impleme */ public boolean equals(IsLessThan that) { if (null != that) { -if (null == comparator) { -retu
svn commit: r1365329 [2/2] - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/core/composite/ test/java/org/apache/commons/functor/core/composite/
Added: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java?rev=1365329&view=auto == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java (added) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java Tue Jul 24 22:34:23 2012 @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.functor.core.composite; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.Serializable; + +import org.apache.commons.functor.BaseFunctorTest; +import org.apache.commons.functor.BinaryFunction; +import org.apache.commons.functor.UnaryFunction; +import org.junit.Test; + + +/** + * Tests for TransformedBinaryFunction. + * @version $Revision: $ $Date: $ + */ +public class TestTransformedBinaryFunction extends BaseFunctorTest { + +private static class Sum implements BinaryFunction, Serializable { +private static final long serialVersionUID = 2255396324585938931L; +public Integer evaluate(Integer left, Integer right) { +return left+right; +} +@Override +public boolean equals(Object obj) { +return obj == this || obj != null && obj instanceof Sum; +} +@Override +public int hashCode() { +return "Sum".hashCode(); +} +} + +private static class AddOne implements UnaryFunction, Serializable { +private static final long serialVersionUID = 8759620198239402369L; +public Integer evaluate(Integer obj) { +return obj + 1; +} +@Override +public boolean equals(Object obj) { +return obj == this || obj != null && obj instanceof AddOne; +} +@Override +public int hashCode() { +return "AddOne".hashCode(); +} +} + +@Override +protected Object makeFunctor() throws Exception { +return new TransformedBinaryFunction(new Sum(), new AddOne()); +} + +@Test +public void testRun() { +TransformedBinaryFunction transform = new TransformedBinaryFunction(new Sum(), new AddOne()); +assertEquals(Integer.valueOf(4), transform.evaluate(1, 2)); +} + +@Test +public void testEquals() { +TransformedBinaryFunction t = new TransformedBinaryFunction(new Sum(), new AddOne()); +BinaryFunction f = new BinaryFunction() { +public Integer evaluate(Integer left, Integer right) { +return left-right; +} +}; +UnaryFunction p = new UnaryFunction() { +public Integer evaluate(Integer obj) { +return obj-1; +} +}; +assertEquals(t,t); +assertObjectsAreEqual(t,new TransformedBinaryFunction(new Sum(), new AddOne())); +assertObjectsAreNotEqual(t,new TransformedBinaryFunction(f, new AddOne())); +assertObjectsAreNotEqual(t,new TransformedBinaryFunction(new Sum(), p)); +assertTrue(!t.equals(null)); +} + +} Propchange: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java -- svn:mime-type = text/plain Added: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java?rev=1365329&view=auto == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java (added) +++ common
svn commit: r1365330 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/generator/ test/java/org/apache/commons/functor/generator/ test/java/org/apache/commons/functor/genera
Author: kinow Date: Tue Jul 24 22:40:04 2012 New Revision: 1365330 URL: http://svn.apache.org/viewvc?rev=1365330&view=rev Log: [FUNCTOR-12] Added more tests for the generator classes (and util classes). Also removed unreachable code, as it could not be tested and was immutable and created/validated during construction. Tests that were using a try/catch + fail() approach were updated to use @Test(expected=SomeClass.class). Test classes missing $revision and $data svn tags were updated too. Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java?rev=1365330&r1=1365329&r2=1365330&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java Tue Jul 24 22:40:04 2012 @@ -84,9 +84,9 @@ public class FilteredGenerator extend int result = "FilteredGenerator".hashCode(); result <<= 2; Generator gen = getWrappedGenerator(); -result ^= gen == null ? 0 : gen.hashCode(); +result ^= gen.hashCode(); result <<= 2; -result ^= pred == null ? 0 : pred.hashCode(); +result ^= pred.hashCode(); return result; } } Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java?rev=1365330&r1=1365329&r2=1365330&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java Tue Jul 24 22:40:04 2012 @@ -90,9 +90,9 @@ public class GenerateUntil extends Ba int result = "GenerateUntil".hashCode(); result <<= 2; Generator gen = getWrappedGenerator(); -result ^= gen == null ? 0 : gen.hashCode(); +result ^= gen.hashCode(); result <<= 2; -result ^= test == null ? 0 : test.hashCode(); +result ^= test.hashCode(); return result; } } Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java?rev=1365330&r1=1365329&r2=1365330&view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java Tue Jul 24 22:40:04 2012 @@ -90,9 +90,9 @@ public class GenerateWhile extends Ba int result = "GenerateWhile".hashCode(); result <<= 2; Generator gen = getWrappedGenerator()
svn commit: r1365377 [2/2] - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ test/java/org/apache/commons/functor/adapter/
Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java?rev=1365377&r1=1365376&r2=1365377&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java Wed Jul 25 00:59:23 2012 @@ -19,11 +19,13 @@ package org.apache.commons.functor.adapt import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.UnaryProcedure; import org.apache.commons.functor.core.Constant; import org.apache.commons.functor.core.NoOp; +import org.apache.commons.functor.core.composite.Sequence; import org.junit.Test; /** @@ -54,6 +56,8 @@ public class TestProcedureUnaryProcedure assertEquals(p,p); assertObjectsAreEqual(p,new ProcedureUnaryProcedure(NoOp.INSTANCE)); assertObjectsAreNotEqual(p,NoOp.INSTANCE); +assertObjectsAreNotEqual(p,new ProcedureUnaryProcedure(new Sequence())); +assertTrue(!p.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java?rev=1365377&r1=1365376&r2=1365377&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java Wed Jul 25 00:59:23 2012 @@ -19,6 +19,7 @@ package org.apache.commons.functor.adapt import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.UnaryFunction; @@ -57,6 +58,9 @@ public class TestRightBoundFunction exte assertObjectsAreNotEqual(f,Constant.of("xyzzy")); assertObjectsAreNotEqual(f,new RightBoundFunction(RightIdentity.FUNCTION,"xyzzy")); assertObjectsAreNotEqual(f,new RightBoundFunction(LeftIdentity.FUNCTION,"bar")); +assertObjectsAreNotEqual(f,new RightBoundFunction(LeftIdentity.FUNCTION,null)); +assertObjectsAreEqual(new RightBoundFunction(LeftIdentity.FUNCTION,null),new RightBoundFunction(LeftIdentity.FUNCTION,null)); +assertTrue(!f.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java?rev=1365377&r1=1365376&r2=1365377&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java Wed Jul 25 00:59:23 2012 @@ -61,6 +61,8 @@ public class TestRightBoundPredicate ext assertObjectsAreNotEqual(f, new RightBoundPredicate(Constant.FALSE, "xyzzy")); assertObjectsAreNotEqual(f, new RightBoundPredicate(Constant.TRUE, "foo")); assertObjectsAreNotEqual(f, new RightBoundPredicate(Constant.TRUE, null)); +assertObjectsAreEqual(new RightBoundPredicate(Constant.TRUE, null), new RightBoundPredicate(Constant.TRUE, null)); +assertTrue(!f.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java?rev=1365377&r1=1365376&r2=1365377&view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java Wed Jul 25 00:59:23 2012 @@ -19,11 +19,13 @@ package org.apache.commons.functor.adapt import static org.ju