diff --git a/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java b/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java index 081205d3d..d78e6b443 100644 --- a/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java +++ b/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java @@ -176,13 +176,11 @@ private AspectPropertyValue getDifferenceInternal() { * @return drift */ private AspectPropertyValue getDriftInternal() { - int result = Integer.MAX_VALUE; + int total = 0; for (ResultsHashSwig results : resultsList) { - if (results.getDrift() < result) { - result = results.getDrift(); - } + total += results.getDrift(); } - return new AspectPropertyValueDefault<>(result); + return new AspectPropertyValueDefault<>(total); } /** diff --git a/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataTests.java b/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataTests.java index 0c5b36069..64dc19f0f 100644 --- a/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataTests.java +++ b/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataTests.java @@ -39,6 +39,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.*; @@ -84,7 +85,32 @@ public void DeviceData_ResultsClose() throws Exception { arg -> data); flowData.close(); verify(results, times(1)).close(); - } + } + } + + /** + * Check that drift adds the drift of every native result, one per + * component, as the specification describes and the native results do. + * @throws Exception + */ + @Test + public void DeviceData_Drift_IsTheSumOfTheResults() throws Exception { + try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { + DeviceDataHashDefault data = new DeviceDataHashDefault( + logger, + flowData, + getWrapper().getEngine(), + missingPropertyService); + + ResultsHashSwig hardware = mock(ResultsHashSwig.class); + when(hardware.getDrift()).thenReturn(3); + ResultsHashSwig browser = mock(ResultsHashSwig.class); + when(browser.getDrift()).thenReturn(5); + data.setResults(hardware); + data.setResults(browser); + + assertEquals(8, data.getDrift().getValue().intValue()); + } } /**