@Test public void shouldValidateDateField() throws CoreTokenException { CoreTokenField key = CoreTokenField.DATE_ONE; Calendar value = Calendar.getInstance(); CoreTokenFieldTypes.validateType(key, value); }
public static void validateType(CoreTokenField field, Object value) throws CoreTokenException { if (value == null) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value field cannot be null!" + "Key: {0}:{1}", CoreTokenField.class.getSimpleName(), field.name())); } try { if (isString(field)) { assertClass(value, String.class); } else if (isInteger(field)) { assertClass(value, Integer.class); } else if (isCalendar(field)) { assertClass(value, Calendar.class); } else if (isByteArray(field)) { assertClass(value, byte[].class); } else { throw new IllegalStateException("Unknown field: " + field.name()); } } catch (LDAPOperationFailedException e) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value was not the correct type:\n" + " Key: {0}:{1}\n" + "Required Class: {2}" + " Actual Class: {3}", CoreTokenField.class.getSimpleName(), field.name(), e.getMessage(), value.getClass().getName()), e); } }
CoreTokenFieldTypes { public static void validateType(CoreTokenField field, Object value) throws CoreTokenException { if (value == null) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value field cannot be null!" + "Key: {0}:{1}", CoreTokenField.class.getSimpleName(), field.name())); } try { if (isString(field)) { assertClass(value, String.class); } else if (isInteger(field)) { assertClass(value, Integer.class); } else if (isCalendar(field)) { assertClass(value, Calendar.class); } else if (isByteArray(field)) { assertClass(value, byte[].class); } else { throw new IllegalStateException("Unknown field: " + field.name()); } } catch (LDAPOperationFailedException e) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value was not the correct type:\n" + " Key: {0}:{1}\n" + "Required Class: {2}" + " Actual Class: {3}", CoreTokenField.class.getSimpleName(), field.name(), e.getMessage(), value.getClass().getName()), e); } } }
CoreTokenFieldTypes { public static void validateType(CoreTokenField field, Object value) throws CoreTokenException { if (value == null) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value field cannot be null!" + "Key: {0}:{1}", CoreTokenField.class.getSimpleName(), field.name())); } try { if (isString(field)) { assertClass(value, String.class); } else if (isInteger(field)) { assertClass(value, Integer.class); } else if (isCalendar(field)) { assertClass(value, Calendar.class); } else if (isByteArray(field)) { assertClass(value, byte[].class); } else { throw new IllegalStateException("Unknown field: " + field.name()); } } catch (LDAPOperationFailedException e) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value was not the correct type:\n" + " Key: {0}:{1}\n" + "Required Class: {2}" + " Actual Class: {3}", CoreTokenField.class.getSimpleName(), field.name(), e.getMessage(), value.getClass().getName()), e); } }  }
CoreTokenFieldTypes { public static void validateType(CoreTokenField field, Object value) throws CoreTokenException { if (value == null) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value field cannot be null!" + "Key: {0}:{1}", CoreTokenField.class.getSimpleName(), field.name())); } try { if (isString(field)) { assertClass(value, String.class); } else if (isInteger(field)) { assertClass(value, Integer.class); } else if (isCalendar(field)) { assertClass(value, Calendar.class); } else if (isByteArray(field)) { assertClass(value, byte[].class); } else { throw new IllegalStateException("Unknown field: " + field.name()); } } catch (LDAPOperationFailedException e) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value was not the correct type:\n" + " Key: {0}:{1}\n" + "Required Class: {2}" + " Actual Class: {3}", CoreTokenField.class.getSimpleName(), field.name(), e.getMessage(), value.getClass().getName()), e); } }  static void validateTypes(Map<CoreTokenField, Object> types); static void validateType(CoreTokenField field, Object value); static boolean isCalendar(CoreTokenField field); static boolean isInteger(CoreTokenField field); static boolean isString(CoreTokenField field); static boolean isByteArray(CoreTokenField field); }
CoreTokenFieldTypes { public static void validateType(CoreTokenField field, Object value) throws CoreTokenException { if (value == null) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value field cannot be null!" + "Key: {0}:{1}", CoreTokenField.class.getSimpleName(), field.name())); } try { if (isString(field)) { assertClass(value, String.class); } else if (isInteger(field)) { assertClass(value, Integer.class); } else if (isCalendar(field)) { assertClass(value, Calendar.class); } else if (isByteArray(field)) { assertClass(value, byte[].class); } else { throw new IllegalStateException("Unknown field: " + field.name()); } } catch (LDAPOperationFailedException e) { throw new LDAPOperationFailedException(MessageFormat.format( "\n" + CoreTokenConstants.DEBUG_HEADER + "Value was not the correct type:\n" + " Key: {0}:{1}\n" + "Required Class: {2}" + " Actual Class: {3}", CoreTokenField.class.getSimpleName(), field.name(), e.getMessage(), value.getClass().getName()), e); } }  static void validateTypes(Map<CoreTokenField, Object> types); static void validateType(CoreTokenField field, Object value); static boolean isCalendar(CoreTokenField field); static boolean isInteger(CoreTokenField field); static boolean isString(CoreTokenField field); static boolean isByteArray(CoreTokenField field);  }