@Test public void basicCase() { CaseFunction<Integer, Integer> function = new CaseFunction<>(); function.addCase(ignored -> true, Functions.getIntegerPassThru()); Integer fortyTwo = 42; Assert.assertEquals(fortyTwo, function.valueOf(fortyTwo)); }
@Test public void defaultValue() { CaseFunction<Foo, String> function = Functions.caseDefault( Functions.getFixedValue("Yow!"), Predicates.attributeGreaterThan(Foo.TO_VALUE, 5.0D), Functions.getFixedValue("Patience, grasshopper")); Assert.assertEquals("Yow!", function.valueOf(new Foo("", 1.0D))); function.setDefault(Functions.getFixedValue("Patience, young grasshopper")); Assert.assertEquals("Patience, grasshopper", function.valueOf(new Foo("", 6.0D))); Assert.assertEquals("Patience, young grasshopper", function.valueOf(new Foo("", 1.0D))); Verify.assertContains("CaseFunction", function.toString()); }
@Test public void noopCase() { CaseFunction<Integer, Integer> function = new CaseFunction<>(); Assert.assertNull(function.valueOf(42)); }