ValueQualityAnalyzer implements Analyzer<ValueQualityStatistics> { @Override public List<ValueQualityStatistics> getResult() { if (semanticQualityAnalyzer == null) { return dataTypeQualityAnalyzer.getResult(); } else { List<ValueQualityStatistics> aggregatedResult = new ArrayList<ValueQualityStatistics>(); List<ValueQualityStatistics> dataTypeQualityResult = dataTypeQualityAnalyzer.getResult(); List<ValueQualityStatistics> semanticQualityResult = semanticQualityAnalyzer.getResult(); for (int i = 0; i < dataTypeQualityResult.size(); i++) { if ("UNKNOWN".equals(semanticQualityAnalyzer.getTypes()[i])) { aggregatedResult.add(dataTypeQualityResult.get(i)); } else { aggregatedResult.add(semanticQualityResult.get(i)); } } return aggregatedResult; } } ValueQualityAnalyzer(QualityAnalyzer<ValueQualityStatistics, DataTypeEnum[]> dataTypeQualityAnalyzer,
            QualityAnalyzer<ValueQualityStatistics, String[]> semanticQualityAnalyzer, boolean isStoreInvalidValues);  ValueQualityAnalyzer(QualityAnalyzer<ValueQualityStatistics, DataTypeEnum[]> dataTypeQualityAnalyzer,
            QualityAnalyzer<ValueQualityStatistics, String[]> semanticQualityAnalyzer); @Override void init(); void setStoreInvalidValues(boolean isStoreInvalidValues); @Override boolean analyze(String... record); @Override void end(); @Override List<ValueQualityStatistics> getResult(); @Override void close();  }
@Test public void valueQualityResultWithoutSemantic() { ValueQualityStatistics expectedResult = new ValueQualityStatistics(); expectedResult.setInvalidCount(1); expectedResult.setValidCount(234); expectedResult.setUnknownCount(345); List<ValueQualityStatistics> expectedResults = new ArrayList<>(); expectedResults.add(expectedResult); DataTypeQualityAnalyzer dataTypeQualityAnalyzer = Mockito.mock(DataTypeQualityAnalyzer.class); when(dataTypeQualityAnalyzer.getResult()).thenReturn(expectedResults); ValueQualityAnalyzer valueQualityAnalyzer = new ValueQualityAnalyzer(dataTypeQualityAnalyzer, null); List<ValueQualityStatistics> results = valueQualityAnalyzer.getResult(); assertEquals(expectedResults.size(), results.size()); ValueQualityStatistics statistics = results.get(0); assertEquals(1, statistics.getInvalidCount()); assertEquals(234, statistics.getValidCount()); assertEquals(345, statistics.getUnknownCount()); }
@Test public void valueQualityResultWithSemantic() { ValueQualityStatistics expectedDataTypeResult = new ValueQualityStatistics(); expectedDataTypeResult.setInvalidCount(1); expectedDataTypeResult.setValidCount(234); expectedDataTypeResult.setUnknownCount(345); ValueQualityStatistics expectedDataTypeResultTwo = new ValueQualityStatistics(); expectedDataTypeResultTwo.setInvalidCount(2); expectedDataTypeResultTwo.setValidCount(456); expectedDataTypeResultTwo.setUnknownCount(789); List<ValueQualityStatistics> expectedDataTypeResults = new ArrayList<>(); expectedDataTypeResults.add(expectedDataTypeResult); expectedDataTypeResults.add(expectedDataTypeResultTwo); DataTypeQualityAnalyzer dataTypeQualityAnalyzer = Mockito.mock(DataTypeQualityAnalyzer.class); when(dataTypeQualityAnalyzer.getResult()).thenReturn(expectedDataTypeResults); ValueQualityStatistics expectedSemanticResult = new ValueQualityStatistics(); expectedSemanticResult.setInvalidCount(14); expectedSemanticResult.setValidCount(7683); expectedSemanticResult.setUnknownCount(9874); List<ValueQualityStatistics> expectedSemanticResults = new ArrayList<>(); expectedSemanticResults.add(expectedSemanticResult); QualityAnalyzer analyzer = Mockito.mock(QualityAnalyzer.class); when(analyzer.getTypes()).thenReturn(new String[] { "FR COMMUNE", "UNKNOWN" }); when(analyzer.getResult()).thenReturn(expectedSemanticResults); ValueQualityAnalyzer valueQualityAnalyzer = new ValueQualityAnalyzer(dataTypeQualityAnalyzer, analyzer); List<ValueQualityStatistics> results = valueQualityAnalyzer.getResult(); assertEquals(2, results.size()); ValueQualityStatistics semanticStatistics = results.get(0); assertEquals(14, semanticStatistics.getInvalidCount()); assertEquals(7683, semanticStatistics.getValidCount()); assertEquals(9874, semanticStatistics.getUnknownCount()); ValueQualityStatistics dataTypeStatistics = results.get(1); assertEquals(2, dataTypeStatistics.getInvalidCount()); assertEquals(456, dataTypeStatistics.getValidCount()); assertEquals(789, dataTypeStatistics.getUnknownCount()); }