From b0c0884822423c3d11d6f1b66cbc9b37cf6c7ff2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Thu, 17 Sep 2026 01:17:03 +0100 Subject: [PATCH] TEST: Let a property the client script populates have no value The value type tests asked every available property for its value and its type. A property the 51Degrees client script populates, HasWebDriver for one, has no value at all on a request that carries no client script evidence, and these requests carry none, so asking for the type throws and the test fails with a key entitled to those properties. Both copies of the test now read whether there is a value first, check that the reason was given when there is none, and check the type when there is one. Checked against the live cloud with a key carrying HasWebDriver. Before the change ValueCloudTests reports one error, HasWebDriver has no value because the 51Degrees JavaScript that populates it has not run on this request, and after it the five tests pass. --- .../devicedetection/cloud/ValueTests.java | 19 +++++++++++++++++-- .../shared/testhelpers/data/ValueTests.java | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) 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())); } } }