FactoryBaseValidator { protected void validateCurrentTimeBetweenSinceUntil(Factory factory) throws ConflictException { final Policies policies = factory.getPolicies(); if (policies == null) { return; } Long validSince = policies.getValidSince(); Long validUntil = policies.getValidUntil(); if (validSince != null && validSince != 0) { if (new Date().before(new Date(validSince))) { throw new ConflictException(FactoryConstants.ILLEGAL_FACTORY_BY_VALIDSINCE_MESSAGE); } } if (validUntil != null && validUntil != 0) { if (new Date().after(new Date(validUntil))) { throw new ConflictException(FactoryConstants.ILLEGAL_FACTORY_BY_VALIDUNTIL_MESSAGE); } } } FactoryBaseValidator(AccountDao accountDao,
                                UserDao userDao,
                                PreferenceDao preferenceDao);   }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = FactoryConstants.ILLEGAL_FACTORY_BY_VALIDUNTIL_MESSAGE) public void shouldNotValidateIfValidUntilBeforeCurrentTime() throws ApiException { Long currentTime = new Date().getTime(); factory.withPolicies(dto.createDto(Policies.class) .withValidUntil(currentTime - 10000L) ); validator.validateCurrentTimeBetweenSinceUntil(factory); }
@Test public void shouldValidateIfCurrentTimeBetweenValidUntilSince() throws ApiException { Long currentTime = new Date().getTime(); factory.withPolicies(dto.createDto(Policies.class) .withValidSince(currentTime - 10000L) .withValidUntil(currentTime + 10000L) ); validator.validateCurrentTimeBetweenSinceUntil(factory); }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = FactoryConstants.ILLEGAL_FACTORY_BY_VALIDSINCE_MESSAGE) public void shouldNotValidateIfValidUntilSinceAfterCurrentTime() throws ApiException { Long currentTime = new Date().getTime(); factory.withPolicies(dto.createDto(Policies.class) .withValidSince(currentTime + 10000L) ); validator.validateCurrentTimeBetweenSinceUntil(factory); }