@Override public boolean hasConstraints() { if ( beanDescriptor.isBeanConstrained() || !beanDescriptor.getConstrainedConstructors().isEmpty() || !beanDescriptor.getConstrainedMethods( MethodType.NON_GETTER, MethodType.GETTER ).isEmpty() ) { return true; } return false; }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "f") public void testGetConstrainedMethodsForUnconstrainedEntity() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( UnconstrainedEntity.class ); Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods( MethodType.GETTER, MethodType.NON_GETTER ); assertEquals( methodDescriptors.size(), 0, "We should get the empty set." ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "f") public void testGetConstrainedMethodsTypeGETTER() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( CustomerService.class ); Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods( MethodType.GETTER ); assertEquals( methodDescriptors.size(), 1 ); assertEquals( methodDescriptors.iterator().next().getName(), "getBestCustomer" ); }
final boolean validBusinessMethods = globalExecutableTypes.contains(ExecutableType.NON_GETTER_METHODS) && !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty(); final boolean validGetterMethods = globalExecutableTypes.contains(ExecutableType.GETTER_METHODS) && !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty();
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "f") public void testGetConstrainedMethodsTypeNON_GETTER() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( CustomerService.class ); Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods( MethodType.NON_GETTER ); assertThat( methodDescriptors ).extracting( MethodDescriptor::getName ).containsExactlyInAnyOrder( "createCustomer", "reset", "removeCustomer", "findCustomer", "findCustomer", "updateAccount", "updateAccountStrictly", "updateCustomer", "createOrder", "getOrderContent" ); }
final boolean validBusinessMethods = globalExecutableTypes.contains(ExecutableType.NON_GETTER_METHODS) && !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty(); final boolean validGetterMethods = globalExecutableTypes.contains(ExecutableType.GETTER_METHODS) && !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty();
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "f") public void testGetConstrainedMethodsTypesGETTERAndNON_GETTER() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( CustomerService.class ); Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods( MethodType.GETTER, MethodType.NON_GETTER ); assertThat( methodDescriptors ).extracting( MethodDescriptor::getName ).containsExactlyInAnyOrder( "createCustomer", "reset", "removeCustomer", "findCustomer", "findCustomer", "updateAccount", "updateAccountStrictly", "updateCustomer", "createOrder", "getOrderContent", "getBestCustomer" ); }