You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/06/07 09:50:07 UTC

[GitHub] [commons-lang] stevebosman-oc commented on pull request #907: Increase test coverage of functional interfaces

stevebosman-oc commented on PR #907:
URL: https://github.com/apache/commons-lang/pull/907#issuecomment-1148448521

   There is repetition, but because there isn't a common interface for each nop, and each instance requires different parameter types in the apply call I can't see a good way of using a ParameterisedTest, e.g.
   
   ```
   assertNull(FailableBiFunction.nop().apply("Foo", "Bar"), "Expect NOP to return null");
   assertNull(FailableDoubleFunction.nop().apply(Double.MAX_VALUE), "Expect NOP to return null");
   assertNull(FailableIntFunction.nop().apply(Integer.MAX_VALUE), "Expect NOP to return null");
   assertNull(FailableLongFunction.nop().apply(Long.MAX_VALUE), "Expect NOP to return null");
   ```
   
   I could move the tests inside of FailableFunctionsTest either individually or bunched (similar to other tests in the class), e.g.
   
   ```
       @Test
       public void testFailablePrimitiveFunctionNops() throws Throwable {
           // NOP functions returning primitives should return default values and not throw exceptions
           assertEquals(0, FailableDoubleToIntFunction.nop().applyAsInt(Double.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableDoubleToLongFunction.nop().applyAsLong(Double.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableIntToDoubleFunction.nop().applyAsDouble(Integer.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableIntToLongFunction.nop().applyAsLong(Integer.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableLongToDoubleFunction.nop().applyAsDouble(Long.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableLongToIntFunction.nop().applyAsInt(Long.MAX_VALUE), "Expect NOP to return 0");
           assertEquals(0, FailableToIntFunction.nop().applyAsInt("Foo"), "Expect NOP to return 0");
           assertEquals(0, FailableToIntBiFunction.nop().applyAsInt("Foo", "Bar"), "Expect NOP to return 0");
           assertEquals(0, FailableToLongFunction.nop().applyAsLong("Foo"), "Expect NOP to return 0");
           assertEquals(0, FailableToLongBiFunction.nop().applyAsLong("Foo", "Bar"), "Expect NOP to return 0");
           assertEquals(0, FailableToDoubleFunction.nop().applyAsDouble("Foo"), "Expect NOP to return 0");
           assertEquals(0, FailableToDoubleBiFunction.nop().applyAsDouble("Foo", "Bar"), "Expect NOP to return 0");
       }
   
       @Test
       public void testFailableFunctionNops() throws Throwable {
           // NOP functions returning objects should return null and not throw exceptions
           assertNull(FailableBiFunction.nop().apply("Foo", "Bar"), "Expect NOP to return null");
           assertNull(FailableDoubleFunction.nop().apply(Double.MAX_VALUE), "Expect NOP to return null");
           assertNull(FailableIntFunction.nop().apply(Integer.MAX_VALUE), "Expect NOP to return null");
           assertNull(FailableLongFunction.nop().apply(Long.MAX_VALUE), "Expect NOP to return null");
       }
   
       @Test
       public void testFailableConsumerNops() throws Throwable {
           // NOP Consumers should not throw exceptions
           FailableConsumer.nop().accept("Foo");
           FailableDoubleConsumer.nop().accept(Double.MAX_VALUE);
           FailableIntConsumer.nop().accept(Integer.MAX_VALUE);
           FailableLongConsumer.nop().accept(Long.MAX_VALUE);
           FailableObjDoubleConsumer.nop().accept("Foo", Double.MAX_VALUE);
           FailableObjIntConsumer.nop().accept("Foo", Integer.MAX_VALUE);
           FailableObjLongConsumer.nop().accept("Foo", Long.MAX_VALUE);
       }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org