@Test public void register() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); Properties properties = new Properties(); groupedProperty.register(properties); verify(singleProperty1, times(1)).register(properties); verify(singleProperty2, times(1)).register(properties); verifyNoMoreInteractions(singleProperty1, singleProperty2); } }
@Test public void advanced() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); when(singleProperty1.isAdvanced()).thenReturn(true); when(singleProperty2.isAdvanced()).thenReturn(false); assertThat(groupedProperty.isAdvanced(), is(true)); when(singleProperty1.isAdvanced()).thenReturn(false); when(singleProperty2.isAdvanced()).thenReturn(false); assertThat(groupedProperty.isAdvanced(), is(false)); }
@Test public void serverRestartRequired() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); when(singleProperty1.isServerRestartRequired()).thenReturn(true); when(singleProperty2.isServerRestartRequired()).thenReturn(false); assertThat(groupedProperty.isServerRestartRequired(), is(true)); when(singleProperty1.isServerRestartRequired()).thenReturn(false); when(singleProperty2.isServerRestartRequired()).thenReturn(false); assertThat(groupedProperty.isServerRestartRequired(), is(false)); }
@Test public void groupValidation() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); groupedProperty.addValidator(validator1); groupedProperty.addValidator(validator2); PropertyValidation propertyValidation = groupedProperty.validate(); verify(singleProperty1, times(1)).validate(propertyValidation); verify(singleProperty2, times(1)).validate(propertyValidation); verify(validator1, times(1)).validate(groupedProperty, propertyValidation); verify(validator2, times(1)).validate(groupedProperty, propertyValidation); verifyNoMoreInteractions(singleProperty1, singleProperty2, validator1, validator2); }
@Test public void validationFailsOnSingleProperty() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); groupedProperty.addValidator(validator1); groupedProperty.addValidator(validator2); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); PropertyValidation propertyValidation = (PropertyValidation) args[0]; propertyValidation.addValidationError(new ValidationError()); return null; } }).when(singleProperty1).validate(Matchers.<PropertyValidation> anyObject()); PropertyValidation propertyValidation = groupedProperty.validate(); assertThat(propertyValidation.hasErrors(), is(true)); assertThat(propertyValidation.getErrorCount(), is(1)); verify(singleProperty1, times(1)).validate(propertyValidation); verify(singleProperty2, times(1)).validate(propertyValidation); verify(validator1, times(1)).validate(groupedProperty, propertyValidation); verify(validator2, times(1)).validate(groupedProperty, propertyValidation); verifyNoMoreInteractions(singleProperty1, singleProperty2, validator1, validator2); }
@Test public void validationFailsOnSinglePropertyAndGroupValidation() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); groupedProperty.addValidator(validator1); groupedProperty.addValidator(validator2);
groupedProperty.addSingleProperty(property3); SingleProperty<Long> property4 = new LongProperty("Min rotation", "Define min rotation", "properties.rotation.min", 0L, false, false); groupedProperty.addSingleProperty(property4); LessValidator<Long> lessValidator = new LessValidator<>(); lessValidator.setProperty("properties.rotation.min");