SetInvalidFunction implements DDMExpressionFunction.Function2<String, String, Boolean>,
			   DDMExpressionObserverAware { @Override public Boolean apply(String field, String errorMessage) { if (_ddmExpressionObserver == null) { return false; } UpdateFieldPropertyRequest.Builder builder = UpdateFieldPropertyRequest.Builder.newBuilder( field, "valid", false); UpdateFieldPropertyRequest updateFieldPropertyRequest = builder.withParameter( "errorMessage", errorMessage ).build(); _ddmExpressionObserver.updateFieldProperty(updateFieldPropertyRequest); return true; }  @Override Boolean apply(String field, String errorMessage); @Override String getName(); @Override void setDDMExpressionObserver(
		DDMExpressionObserver ddmExpressionObserver); static final String NAME; }
@Test public void testApply() { DefaultDDMExpressionObserver defaultDDMExpressionObserver = new DefaultDDMExpressionObserver(); DefaultDDMExpressionObserver spy = spy(defaultDDMExpressionObserver); SetInvalidFunction setInvalidFunction = new SetInvalidFunction(); setInvalidFunction.setDDMExpressionObserver(spy); Boolean result = setInvalidFunction.apply( "contact", "Custom error message"); ArgumentCaptor<UpdateFieldPropertyRequest> argumentCaptor = ArgumentCaptor.forClass(UpdateFieldPropertyRequest.class); Mockito.verify( spy, Mockito.times(1) ).updateFieldProperty( argumentCaptor.capture() ); UpdateFieldPropertyRequest updateFieldPropertyRequest = argumentCaptor.getValue(); Map<String, Object> properties = updateFieldPropertyRequest.getProperties(); Assert.assertEquals("contact", updateFieldPropertyRequest.getField()); Assert.assertTrue("valid", properties.containsKey("valid")); Assert.assertEquals( "Custom error message", updateFieldPropertyRequest.getPropertyOptional( "errorMessage" ).get()); Assert.assertEquals(false, properties.get("valid")); Assert.assertTrue(result); }
@Test public void testNullObserver() { SetInvalidFunction setInvalidFunction = new SetInvalidFunction(); Boolean result = setInvalidFunction.apply("field", "errorMessage"); Assert.assertFalse(result); }