diff --git a/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/ValueTests.java b/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/ValueTests.java index 8ee970d4b..edd7d3e1a 100644 --- a/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/ValueTests.java +++ b/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/ValueTests.java @@ -105,12 +105,27 @@ public static void valueTypes(WrapperCloud wrapper) throws Exception { assertNotNull("Value of " + property.getName() + " is null. ", value); assertTrue(AspectPropertyValue.class.isAssignableFrom(value.getClass())); + AspectPropertyValue propertyValue = + (AspectPropertyValue) value; + // A property the 51Degrees client script populates, such + // as HasWebDriver or IsVisible, has no value at all on a + // request that carries no client script evidence, and + // this request carries none. Asking such a value for its + // type throws, so what is checked here is that the reason + // for there being no value was given, which is what a + // caller reads. + if (propertyValue.hasValue() == false) { + assertNotNull("Property '" + property.getName() + + "' has no value and no reason was given.", + propertyValue.getNoValueMessage()); + continue; + } assertTrue("Value of '" + property.getName() + - "' was of type " + ((AspectPropertyValue) value).getValue().getClass().getSimpleName() + + "' was of type " + propertyValue.getValue().getClass().getSimpleName() + " but should have been " + expectedType.getSimpleName() + ".", expectedType.isAssignableFrom( - ((AspectPropertyValue) value).getValue().getClass())); + propertyValue.getValue().getClass())); } } } diff --git a/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java b/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java index 6ccc631bf..148e3a6e0 100644 --- a/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java +++ b/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java @@ -115,12 +115,27 @@ public static void valueTypes(Wrapper wrapper) throws Exception { expectedType = property.getType(); assertNotNull("Value of " + property.getName() + " is null. ", value); assertTrue(AspectPropertyValue.class.isAssignableFrom(value.getClass())); + AspectPropertyValue propertyValue = + (AspectPropertyValue) value; + // A property the 51Degrees client script populates, such + // as HasWebDriver or IsVisible, has no value at all on a + // request that carries no client script evidence, and + // this request carries none. Asking such a value for its + // type throws, so what is checked here is that the reason + // for there being no value was given, which is what a + // caller reads. + if (propertyValue.hasValue() == false) { + assertNotNull("Property '" + property.getName() + + "' has no value and no reason was given.", + propertyValue.getNoValueMessage()); + continue; + } assertTrue("Value of '" + property.getName() + - "' was of type " + ((AspectPropertyValue) value).getValue().getClass().getSimpleName() + + "' was of type " + propertyValue.getValue().getClass().getSimpleName() + " but should have been " + expectedType.getSimpleName() + ".", expectedType.isAssignableFrom( - ((AspectPropertyValue) value).getValue().getClass())); + propertyValue.getValue().getClass())); } } }