@Override public String getLocalizedMessage() { return localizedMessage(); }
public String localizedMessage() { String[] messages = localizedMessagesFrom( null ); StringBuilder result = new StringBuilder(); boolean first = true; for( String message : messages ) { if( !first ) { result.append( ',' ); } first = false; result.append( message ); } return result.toString(); }
@Override public boolean isValid( ObjectSelection objectSelection ) { try { Object checkedObject = roleClass.equals( ObjectSelection.class ) ? objectSelection : objectSelection.get( roleClass ); return constraint.isValid( annotation, checkedObject ); } catch( IllegalArgumentException e ) { return false; } catch( Throwable e ) { logger.warn( "Could not check constraint " + constraint.getClass().getName(), e ); return false; } } }
@Test public void givenInvalidCacheNameWhenFetchingCacheExpectNullArgumentException() { try { cache = cachePool.fetchCache( "", String.class ); fail( "Expected " + NullArgumentException.class.getSimpleName() ); } catch( NullArgumentException e ) { // expected } try { cache = cachePool.fetchCache( null, String.class ); fail( "Expected " + NullArgumentException.class.getSimpleName() ); } catch( ConstraintViolationException e ) { // expected Collection<ConstraintViolation> violations = e.constraintViolations(); assertEquals( 1, violations.size() ); ConstraintViolation violation = violations.iterator().next(); assertEquals( "not optional", violation.constraint().toString() ); assertEquals( "param1", violation.name() ); } }
Annotation annotation = violation.constraint(); String name = violation.name(); Object value = violation.value(); String classes; if( Iterables.count( instanceTypes ) == 1 )
Annotation annotation = violation.constraint(); String message; try result += violation.value() == null ? "null" : violation.value().toString();
for( ConstraintViolation constraintViolation : e.constraintViolations() ) response.setEntity( new StringRepresentation( e.getMessage() ) ); response.setStatus( Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY );
for( Class<? extends Constraint<?, ?>> constraintClass : constraints.value() )
@Override public String getMessage() { return localizedMessage(); }
for( Class<? extends Constraint<?, ?>> aClass : constraints.value() )