### Question:
TimeValidator implements AbacValidator<TimeValidator.TimeConfig> { @Override public void validate(TimeConfig config, Errors.Collector collector, ProviderRequest request) { ZonedDateTime now = request.env().time(); config.validate(this, now, collector); } private  TimeValidator(); static TimeValidator create(); @Override Class<TimeConfig> configClass(); @Override String configKey(); @Override TimeConfig fromConfig(Config config); @Override TimeConfig fromAnnotations(EndpointConfig endpointConfig); @Override void validate(TimeConfig config, Errors.Collector collector, ProviderRequest request); @Override Collection<Class<? extends Annotation>> supportedAnnotations();  }### Answer:
@Test public void testBetweenTimesAndDayOfWekPermit() { SecurityTime time = SecurityTime.builder() .value(ChronoField.HOUR_OF_DAY, 10) .value(ChronoField.MINUTE_OF_HOUR, 0) .value(ChronoField.DAY_OF_WEEK, DayOfWeek.TUESDAY.getValue()) .build(); Errors.Collector collector = Errors.collector(); SecurityEnvironment env = SecurityEnvironment.builder() .time(time) .build(); ProviderRequest request = mock(ProviderRequest.class); when(request.env()).thenReturn(env); validator.validate(timeConfig, collector, request); collector.collect().checkValid(); }
@Test public void testBetweenTimesDeny() { SecurityTime time = SecurityTime.builder() .value(ChronoField.HOUR_OF_DAY, 12) .value(ChronoField.MINUTE_OF_HOUR, 15) .value(ChronoField.DAY_OF_WEEK, DayOfWeek.TUESDAY.getValue()) .build(); Errors.Collector collector = Errors.collector(); SecurityEnvironment env = SecurityEnvironment.builder() .time(time) .build(); ProviderRequest request = mock(ProviderRequest.class); when(request.env()).thenReturn(env); validator.validate(timeConfig, collector, request); if (collector.collect().isValid()) { fail("Should have failed, as 12:15 is not in supported times"); } }
@Test public void testDayOfWeekDeny() { SecurityTime time = SecurityTime.builder() .value(ChronoField.HOUR_OF_DAY, 12) .value(ChronoField.MINUTE_OF_HOUR, 15) .value(ChronoField.DAY_OF_WEEK, DayOfWeek.SUNDAY.getValue()) .build(); Errors.Collector collector = Errors.collector(); SecurityEnvironment env = SecurityEnvironment.builder() .time(time) .build(); ProviderRequest request = mock(ProviderRequest.class); when(request.env()).thenReturn(env); validator.validate(timeConfig, collector, request); if (collector.collect().isValid()) { fail("Should have failed, as 12:15 is not in supported times"); } }