ProductValidator { public boolean isValid(Product product) { return containsGeocoding(product) && canHandleBandConfigurations(product) && isInDateRange(product); } ProductValidator(List<BandConfiguration> bandConfigurations, ProductData.UTC startDate, ProductData.UTC endDate, Logger logger); boolean isValid(Product product);  }
@Test public void testIsValid_IfIsEntirelyInTimeRange() { final boolean valid = _productValidator.isValid(_product); assertEquals(true, valid); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfProductDoesNotContainAGeoCoding() { when(_product.getGeoCoding()).thenReturn(null); when(_product.getName()).thenReturn("No Geocoding"); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'No Geocoding' does not contain a geo coding."); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfIsNotEntirelyInTimeRange_beforeTimeRange() { when(_product.getStartTime()).thenReturn(before(_startDate)); when(_product.getEndTime()).thenReturn(_endDate); when(_product.getName()).thenReturn("OutOfDateRange_before"); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'OutOfDateRange_before' is not inside the date range from 21-MAY-2012 00:00:00.000000 to 08-NOV-2012 00:00:00.000000"); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfIsNotEntirelyInTimeRange_afterTimeRange() { when(_product.getStartTime()).thenReturn(_startDate); when(_product.getEndTime()).thenReturn(after(_endDate)); when(_product.getName()).thenReturn("OutOfDateRange_after"); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'OutOfDateRange_after' is not inside the date range from 21-MAY-2012 00:00:00.000000 to 08-NOV-2012 00:00:00.000000"); verifyNoMoreInteractions(_loggerMock); }
@Test public void testProductValidatorThatHasOnlyStartTime() throws Exception { _productValidator = new ProductValidator(_bandConfigurations, _startDate, null, _loggerMock); assertTrue(isValid(configureProductTimes(_startDate, after(_endDate)))); assertTrue(isValid(configureProductTimes(_startDate, before(_endDate)))); assertTrue(isValid(configureProductTimes(_startDate, _endDate))); assertTrue(isValid(configureProductTimes(_startDate, null))); assertFalse(isValid(configureProductTimes(null, null))); assertFalse(isValid(configureProductTimes(null, _endDate))); assertFalse(isValid(configureProductTimes(before(_startDate), null))); assertFalse(isValid(configureProductTimes(before(_startDate), _endDate))); }
@Test public void testProductValidatorThatHasOnlyEndTime() throws Exception { _productValidator = new ProductValidator(_bandConfigurations, null, _endDate, _loggerMock); assertTrue(isValid(configureProductTimes(null, _endDate))); assertTrue(isValid(configureProductTimes(after(_startDate), _endDate))); assertTrue(isValid(configureProductTimes(before(_startDate), _endDate))); assertTrue(isValid(configureProductTimes(_startDate, _endDate))); assertFalse(isValid(configureProductTimes(null, null))); assertFalse(isValid(configureProductTimes(_startDate, null))); assertFalse(isValid(configureProductTimes(null, after(_endDate)))); assertFalse(isValid(configureProductTimes(_startDate, after(_endDate)))); }
@Test public void testProductValidatorThatHasNoTimes() throws Exception { _productValidator = new ProductValidator(_bandConfigurations, null, null, _loggerMock); assertTrue(isValid(configureProductTimes(null, _endDate))); assertTrue(isValid(configureProductTimes(after(_startDate), _endDate))); assertTrue(isValid(configureProductTimes(before(_startDate), _endDate))); assertTrue(isValid(configureProductTimes(_startDate, _endDate))); assertTrue(isValid(configureProductTimes(null, null))); assertTrue(isValid(configureProductTimes(_startDate, null))); assertTrue(isValid(configureProductTimes(null, after(_endDate)))); assertTrue(isValid(configureProductTimes(_startDate, after(_endDate)))); }
@Test public void testIsValid_IfProductHasAllBandsNeededInBandConfigurations() { final BandConfiguration bandConfiguration = new BandConfiguration(); bandConfiguration.sourceBandName = "band-1"; _bandConfigurations.add(bandConfiguration); when(_product.containsBand("band-1")).thenReturn(true); final boolean valid = _productValidator.isValid(_product); assertEquals(true, valid); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfProductDoesNotContainAllBandsNeededInBandConfigurations() { final BandConfiguration bandConfiguration = new BandConfiguration(); bandConfiguration.sourceBandName = "band-1"; _bandConfigurations.add(bandConfiguration); when(_product.containsBand("band-1")).thenReturn(false); when(_product.getName()).thenReturn("InvalidProduct"); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'InvalidProduct' does not contain the band 'band-1'"); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfProductCanNotResolveTheExpressionNeededInBandConfigurations() { final BandConfiguration bandConfiguration = new BandConfiguration(); bandConfiguration.expression = "band_1 + 4"; _bandConfigurations.add(bandConfiguration); when(_product.isCompatibleBandArithmeticExpression("band_1 + 4")).thenReturn(false); when(_product.getName()).thenReturn("InvalidProduct"); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'InvalidProduct' can not resolve the band arithmetic expression 'band_1 + 4'"); verifyNoMoreInteractions(_loggerMock); }
@Test public void testIsInvalid_IfProductAlreadyContainsBandWithExpressionName() { final BandConfiguration bandConfiguration = new BandConfiguration(); bandConfiguration.expression = "band_1 + 4"; _bandConfigurations.add(bandConfiguration); when(_product.isCompatibleBandArithmeticExpression("band_1 + 4")).thenReturn(true); when(_product.getName()).thenReturn("InvalidProduct"); when(_product.containsBand("band_1_+_4")).thenReturn(true); final boolean valid = _productValidator.isValid(_product); assertEquals(false, valid); verify(_loggerMock).info("Product skipped. The product 'InvalidProduct' already contains a band 'band_1_+_4'"); verifyNoMoreInteractions(_loggerMock); }