From 58d687d9f0c34fd4ab612ed5fcb6e624598fe0a0 Mon Sep 17 00:00:00 2001 From: yashp676 Date: Thu, 29 Oct 2026 19:13:40 +0000 Subject: [PATCH] [java] hold generated BiDi numbers to their declared ranges Part of #18195 --- .../openqa/selenium/bidi/BiDiGenerator.java | 180 ++++++++++++------ .../bidi/generator/FieldValidationTest.java | 127 +++++++++++- .../selenium/bidi/generator/Fragments.java | 7 + .../protocol/input/DeclaredRangeTest.java | 91 +++++++++ .../bidi/protocol/input/JsIntRangeTest.java | 20 +- 5 files changed, 352 insertions(+), 73 deletions(-) create mode 100644 java/test/org/openqa/selenium/bidi/protocol/input/DeclaredRangeTest.java diff --git a/java/src/org/openqa/selenium/bidi/BiDiGenerator.java b/java/src/org/openqa/selenium/bidi/BiDiGenerator.java index 831cae60842cb..8f7b4c2b1f359 100644 --- a/java/src/org/openqa/selenium/bidi/BiDiGenerator.java +++ b/java/src/org/openqa/selenium/bidi/BiDiGenerator.java @@ -891,7 +891,7 @@ private void appendRecordBody( .append(" ") .append(f.name) .append(") {\n"); - appendJsRangeValidation(sb, f, f.name, true, m + " "); + appendRangeValidation(sb, f, f.name, true, m + " "); sb.append(m) .append(" this.") .append(f.name) @@ -1346,14 +1346,69 @@ private String immutableCopyExpr(String varName, Map typeRef) { return null; } - // js-int/js-uint (see resolveJavaType's alias comment) additionally restrict a plain - // "integer" (already resolved to Long/long) to JavaScript's safe-integer range: the browser's - // own numeric type is a double, so a value the wire can represent as a signed 64-bit integer - // may still be one BiDi itself declares invalid — js-uint further requires non-negative. - // Checked here, in the single constructor both directions (an outbound caller-built value and - // an inbound deserialized one) share, so a value outside the range is rejected identically - // either way, the same as appendConstValidation does for a spec'd const value. - private static final long JS_SAFE_INTEGER_MAX = 9007199254740991L; // 2^53 - 1 + // The schema declares numeric bounds both on aliases (js-int/js-uint hold an "integer" to + // JavaScript's safe-integer range, since the browser's own numeric type is a double) and on + // the fields that use them (js-uint .ge 1). A field is held to both: the alias chain's bounds, + // narrowed by each referencing node's own. Checked in the single constructor both directions + // (an outbound caller-built value and an inbound deserialized one) share, so a value outside + // the range is rejected identically either way, the same as appendConstValidation does for a + // spec'd const value. + private static final class Bounds { + private java.math.BigDecimal min; + private boolean exclusiveMin; + private java.math.BigDecimal max; + private boolean exclusiveMax; + + private boolean isEmpty() { + return min == null && max == null; + } + } + + /** The "integer" or "number" a type ref resolves to through aliases, or null. */ + private String numericPrimitive(Map typeRef) { + if (typeRef == null) return null; + String primitive = str(typeRef, "primitive"); + if (primitive != null) { + return "integer".equals(primitive) || "number".equals(primitive) ? primitive : null; + } + String ref = str(typeRef, "ref"); + Map named = ref != null ? types.get(ref) : null; + if (named == null || !"alias".equals(str(named, "kind"))) return null; + return numericPrimitive(mapField(named, "type")); + } + + private Bounds bounds(Map typeRef) { + Bounds bounds = new Bounds(); + if (typeRef == null || numericPrimitive(typeRef) == null) return bounds; + String ref = str(typeRef, "ref"); + if (ref != null) { + bounds = bounds(mapField(types.get(ref), "type")); + } + narrow(bounds, typeRef); + return bounds; + } + + // Each side keeps the tighter of the two; at a tie, the exclusive one. + private static void narrow(Bounds bounds, Map node) { + if (node.get("min") != null) { + java.math.BigDecimal min = new java.math.BigDecimal(node.get("min").toString()); + boolean exclusive = Boolean.TRUE.equals(node.get("exclusiveMin")); + int comparison = bounds.min == null ? 1 : min.compareTo(bounds.min); + if (comparison > 0 || (comparison == 0 && exclusive)) { + bounds.min = min; + bounds.exclusiveMin = exclusive; + } + } + if (node.get("max") != null) { + java.math.BigDecimal max = new java.math.BigDecimal(node.get("max").toString()); + boolean exclusive = Boolean.TRUE.equals(node.get("exclusiveMax")); + int comparison = bounds.max == null ? -1 : max.compareTo(bounds.max); + if (comparison < 0 || (comparison == 0 && exclusive)) { + bounds.max = max; + bounds.exclusiveMax = exclusive; + } + } + } // An inline union of a bare primitive arm and one or more ref arms — e.g. // script.NumberValue.value: a JSON number or a script.SpecialNumber — isn't a scalarUnion @@ -1401,40 +1456,65 @@ private void appendInlineUnionValidation( sb.append(bodyIndent).append("}\n"); } - private void appendJsRangeValidation( + private void appendRangeValidation( StringBuilder sb, FieldInfo f, String varName, boolean nullGuard, String bodyIndent) { - String ref = f.typeRef != null ? str(f.typeRef, "ref") : null; - if (!"js-int".equals(ref) && !"js-uint".equals(ref)) return; - long min = "js-uint".equals(ref) ? 0L : -JS_SAFE_INTEGER_MAX; + appendRangeValidation(sb, f, varName, nullGuard ? varName + " != null" : null, bodyIndent); + } + + private void appendRangeValidation( + StringBuilder sb, FieldInfo f, String value, String guard, String bodyIndent) { + String primitive = numericPrimitive(f.typeRef); + Bounds bounds = bounds(f.typeRef); + if (primitive == null || bounds.isEmpty()) return; + boolean integer = "integer".equals(primitive); + // A Number is compared as a double, and a failed comparison is the out-of-range test, so + // NaN is rejected too; a long has no NaN, so its plain form reads more directly. + String operand = integer ? value : value + ".doubleValue()"; + List inRange = new ArrayList<>(); + List outOfRange = new ArrayList<>(); + List description = new ArrayList<>(); + if (bounds.min != null) { + String limit = numericLiteral(bounds.min, integer, f); + inRange.add(operand + (bounds.exclusiveMin ? " > " : " >= ") + limit); + outOfRange.add(operand + (bounds.exclusiveMin ? " <= " : " < ") + limit); + description.add((bounds.exclusiveMin ? "> " : ">= ") + bounds.min.toPlainString()); + } + if (bounds.max != null) { + String limit = numericLiteral(bounds.max, integer, f); + inRange.add(operand + (bounds.exclusiveMax ? " < " : " <= ") + limit); + outOfRange.add(operand + (bounds.exclusiveMax ? " >= " : " > ") + limit); + description.add((bounds.exclusiveMax ? "< " : "<= ") + bounds.max.toPlainString()); + } + String check = + integer ? String.join(" || ", outOfRange) : "!(" + String.join(" && ", inRange) + ")"; sb.append(bodyIndent).append("if ("); - if (nullGuard) { - sb.append(varName).append(" != null && ("); - } - sb.append(varName) - .append(" < ") - .append(min) - .append("L || ") - .append(varName) - .append(" > ") - .append(JS_SAFE_INTEGER_MAX) - .append("L"); - if (nullGuard) { - sb.append(")"); + if (guard != null) { + sb.append(guard).append(" && ").append(integer ? "(" + check + ")" : check); + } else { + sb.append(check); } sb.append(") {\n"); sb.append(bodyIndent) .append(" throw new BiDiException(\"") .append(f.wire) - .append(" must be between ") - .append(min) - .append(" and ") - .append(JS_SAFE_INTEGER_MAX) + .append(" must be ") + .append(String.join(" and ", description)) .append(", got: \" + ") - .append(varName) + .append(value) .append(");\n"); sb.append(bodyIndent).append("}\n"); } + private static String numericLiteral(java.math.BigDecimal bound, boolean integer, FieldInfo f) { + if (!integer) return bound.toPlainString() + "d"; + try { + return bound.longValueExact() + "L"; + } catch (ArithmeticException e) { + throw new IllegalArgumentException( + "Integer field " + f.wire + " has a non-integral bound: " + bound, e); + } + } + private void appendConstructorAssignment( StringBuilder sb, FieldInfo f, @@ -1445,7 +1525,8 @@ private void appendConstructorAssignment( if (f.required) { boolean nullable = f.typeRef != null && Boolean.TRUE.equals(f.typeRef.get("nullable")); appendConstValidation(sb, f, nullable, bodyIndent); - appendJsRangeValidation(sb, f, f.name, nullable, bodyIndent); + // A non-nullable Number is still a reference: leave a null to the required check below. + appendRangeValidation(sb, f, f.name, nullable || !isPrimitive(f.typeRef), bodyIndent); // Always null-guarded regardless of nullable/required: nullness itself is enforced right // below (Objects.requireNonNull, or simply allowed through for a nullable field) — this // only checks the value's shape when one is actually present, so a missing/null value @@ -1480,35 +1561,12 @@ private void appendConstructorAssignment( .append(" is required\");\n"); } } else { - String ref = f.typeRef != null ? str(f.typeRef, "ref") : null; - if ("js-int".equals(ref) || "js-uint".equals(ref)) { - long min = "js-uint".equals(ref) ? 0L : -JS_SAFE_INTEGER_MAX; - sb.append(bodyIndent) - .append("if (") - .append(f.name) - .append(" != null && ") - .append(f.name) - .append(".isPresent() && (") - .append(f.name) - .append(".get() < ") - .append(min) - .append("L || ") - .append(f.name) - .append(".get() > ") - .append(JS_SAFE_INTEGER_MAX) - .append("L)) {\n"); - sb.append(bodyIndent) - .append(" throw new BiDiException(\"") - .append(f.wire) - .append(" must be between ") - .append(min) - .append(" and ") - .append(JS_SAFE_INTEGER_MAX) - .append(", got: \" + ") - .append(f.name) - .append(".get());\n"); - sb.append(bodyIndent).append("}\n"); - } + appendRangeValidation( + sb, + f, + f.name + ".get()", + f.name + " != null && " + f.name + ".isPresent()", + bodyIndent); String copyExpr = isReceivable ? immutableCopyExpr("v", f.typeRef) : null; if (copyExpr != null) { // A plain (a != null ? a : Optional.empty()).map(...) infers fine on its own, but once diff --git a/java/test/org/openqa/selenium/bidi/generator/FieldValidationTest.java b/java/test/org/openqa/selenium/bidi/generator/FieldValidationTest.java index 96ec9b0a65952..b115160d35f8e 100644 --- a/java/test/org/openqa/selenium/bidi/generator/FieldValidationTest.java +++ b/java/test/org/openqa/selenium/bidi/generator/FieldValidationTest.java @@ -20,6 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.openqa.selenium.bidi.generator.Fragments.FORCED_COLORS_MODE_THEME; import static org.openqa.selenium.bidi.generator.Fragments.INTEGER_ALIAS; +import static org.openqa.selenium.bidi.generator.Fragments.JS_INT; +import static org.openqa.selenium.bidi.generator.Fragments.JS_UINT; import static org.openqa.selenium.bidi.generator.Fragments.SET_FORCED_COLORS_MODE_THEME_OVERRIDE_PARAMETERS; import static org.openqa.selenium.bidi.generator.Fragments.SET_VIEWPORT_PARAMETERS; import static org.openqa.selenium.bidi.generator.Fragments.STRING_ALIAS; @@ -28,7 +30,7 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -/** Per-field validation: required, nullable, const, inline-union and JS-integer range checks. */ +/** Per-field validation: required, nullable, const, inline-union and numeric range checks. */ @Tag("UnitTests") class FieldValidationTest { @@ -154,15 +156,17 @@ void jsIntegerAliasesAreRangeChecked() { + "{'name': 'height', 'wire': 'height', 'required': true," + " 'type': {'ref': 'js-uint'}}," + "{'name': 'x', 'wire': 'x', 'required': true, 'type': {'ref': 'js-int'}}]}") - .type("js-uint", INTEGER_ALIAS) - .type("js-int", INTEGER_ALIAS) + .type("js-uint", JS_UINT) + .type("js-int", JS_INT) .generate(); assertThat(out.type("browser.ClientWindowInfo")) .contains("private final long height;") .contains("if (height < 0L || height > 9007199254740991L) {") .contains("if (x < -9007199254740991L || x > 9007199254740991L) {") - .contains("throw new BiDiException(\"x must be between -9007199254740991 and"); + .contains( + "throw new BiDiException(\"x must be >= -9007199254740991 and <= 9007199254740991," + + " got: \" + x);"); } @Test @@ -174,7 +178,7 @@ void optionalJsIntegerIsRangeCheckedInItsSetter() { "input.PointerMoveAction", "{'kind': 'record', 'fields': [{'name': 'duration', 'wire': 'duration'," + " 'required': false, 'type': {'ref': 'js-uint'}}]}") - .type("js-uint", INTEGER_ALIAS) + .type("js-uint", JS_UINT) .generate(); assertThat(out.type("input.PointerMoveAction")) @@ -191,7 +195,7 @@ void optionalJsIntegerIsRangeCheckedOnReceipt() { "network.Initiator", "{'kind': 'record', 'fields': [{'name': 'columnNumber', 'wire': 'columnNumber'," + " 'required': false, 'type': {'ref': 'js-uint'}}]}") - .type("js-uint", INTEGER_ALIAS) + .type("js-uint", JS_UINT) .generate(); assertThat(out.type("network.Initiator")) @@ -199,4 +203,115 @@ void optionalJsIntegerIsRangeCheckedOnReceipt() { "if (columnNumber != null && columnNumber.isPresent() && (columnNumber.get() < 0L ||" + " columnNumber.get() > 9007199254740991L)) {"); } + + @Test + void fieldBoundNarrowsItsAliasBound() { + Generated out = + new Schema() + .sends("browsingContext.LocateNodesParameters") + .type( + "browsingContext.LocateNodesParameters", + "{'kind': 'record', 'fields': [{'name': 'maxNodeCount', 'wire': 'maxNodeCount'," + + " 'required': false, 'type': {'ref': 'js-uint', 'min': 1}}]}") + .type("js-uint", JS_UINT) + .generate(); + + assertThat(out.type("browsingContext.LocateNodesParameters")) + .contains( + "if (maxNodeCount != null && (maxNodeCount < 1L || maxNodeCount >" + + " 9007199254740991L)) {") + .contains( + "if (maxNodeCount != null && maxNodeCount.isPresent() && (maxNodeCount.get() < 1L ||" + + " maxNodeCount.get() > 9007199254740991L)) {"); + } + + @Test + void fieldBoundLooserThanItsAliasBoundDoesNotWidenIt() { + Generated out = + new Schema() + .receives("network.ResponseData") + .type( + "network.ResponseData", + "{'kind': 'record', 'fields': [{'name': 'status', 'wire': 'status'," + + " 'required': true, 'type': {'ref': 'js-uint', 'min': -5}}]}") + .type("js-uint", JS_UINT) + .generate(); + + assertThat(out.type("network.ResponseData")) + .contains("if (status < 0L || status > 9007199254740991L) {"); + } + + @Test + void integerWithItsOwnBoundsIsRangeChecked() { + Generated out = + new Schema() + .sends("session.SocksProxyConfiguration") + .type( + "session.SocksProxyConfiguration", + "{'kind': 'record', 'fields': [{'name': 'socksVersion', 'wire': 'socksVersion'," + + " 'required': true, 'type': {'primitive': 'integer', 'min': 0, 'max':" + + " 255}}]}") + .generate(); + + assertThat(out.type("session.SocksProxyConfiguration")) + .contains("if (socksVersion < 0L || socksVersion > 255L) {") + .contains( + "throw new BiDiException(\"socksVersion must be >= 0 and <= 255, got: \" +" + + " socksVersion);"); + } + + @Test + void numberBoundsAreComparedAsDoublesSoNaNFails() { + Generated out = + new Schema() + .sends("emulation.GeolocationCoordinates") + .type( + "emulation.GeolocationCoordinates", + "{'kind': 'record', 'fields': [{'name': 'latitude', 'wire': 'latitude'," + + " 'required': true, 'type': {'primitive': 'number', 'min': -90, 'max':" + + " 90}}]}") + .generate(); + + assertThat(out.type("emulation.GeolocationCoordinates")) + .contains( + "if (latitude != null && !(latitude.doubleValue() >= -90d && latitude.doubleValue()" + + " <= 90d)) {") + .contains("this.latitude = Objects.requireNonNull(latitude, \"latitude is required\");"); + } + + @Test + void exclusiveBoundsUseStrictComparisons() { + Generated out = + new Schema() + .sends("emulation.GeolocationCoordinates") + .type( + "emulation.GeolocationCoordinates", + "{'kind': 'record', 'fields': [" + + "{'name': 'heading', 'wire': 'heading', 'required': false, 'type':" + + " {'primitive': 'number', 'min': 0, 'max': 360, 'exclusiveMax': true," + + " 'nullable': true}}," + + "{'name': 'devicePixelRatio', 'wire': 'devicePixelRatio', 'required': false," + + " 'type': {'primitive': 'number', 'min': 0, 'exclusiveMin': true}}]}") + .generate(); + + assertThat(out.type("emulation.GeolocationCoordinates")) + .contains("heading.get().doubleValue() >= 0d && heading.get().doubleValue() < 360d") + .contains("throw new BiDiException(\"heading must be >= 0 and < 360, got: \"") + .contains("!(devicePixelRatio.get().doubleValue() > 0d)") + .contains("throw new BiDiException(\"devicePixelRatio must be > 0, got: \""); + } + + @Test + void unboundedNumberIsNotRangeChecked() { + Generated out = + new Schema() + .sends("browsingContext.BoxClipRectangle") + .type( + "browsingContext.BoxClipRectangle", + "{'kind': 'record', 'fields': [{'name': 'x', 'wire': 'x', 'required': true," + + " 'type': {'primitive': 'number'}}]}") + .generate(); + + assertThat(out.type("browsingContext.BoxClipRectangle")).doesNotContain("must be"); + } } diff --git a/java/test/org/openqa/selenium/bidi/generator/Fragments.java b/java/test/org/openqa/selenium/bidi/generator/Fragments.java index ffff35cd19630..3a5d8efc56b10 100644 --- a/java/test/org/openqa/selenium/bidi/generator/Fragments.java +++ b/java/test/org/openqa/selenium/bidi/generator/Fragments.java @@ -29,6 +29,13 @@ private Fragments() {} static final String INTEGER_ALIAS = "{'kind': 'alias', 'type': {'primitive': 'integer'}}"; + static final String JS_INT = + "{'kind': 'alias', 'type': {'primitive': 'integer', 'min': -9007199254740991," + + " 'max': 9007199254740991}}"; + + static final String JS_UINT = + "{'kind': 'alias', 'type': {'primitive': 'integer', 'min': 0, 'max': 9007199254740991}}"; + static final String SET_FORCED_COLORS_MODE_THEME_OVERRIDE_PARAMETERS = "{'kind': 'record', 'fields': [" + "{'name': 'theme', 'wire': 'theme', 'required': true," diff --git a/java/test/org/openqa/selenium/bidi/protocol/input/DeclaredRangeTest.java b/java/test/org/openqa/selenium/bidi/protocol/input/DeclaredRangeTest.java new file mode 100644 index 0000000000000..8923f42ee8e1a --- /dev/null +++ b/java/test/org/openqa/selenium/bidi/protocol/input/DeclaredRangeTest.java @@ -0,0 +1,91 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.openqa.selenium.bidi.protocol.input; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.bidi.BiDiException; +import org.openqa.selenium.bidi.ConverterFunctions; +import org.openqa.selenium.bidi.protocol.browsingcontext.SetViewportParameters; +import org.openqa.selenium.bidi.protocol.emulation.GeolocationCoordinates; +import org.openqa.selenium.bidi.protocol.network.ResponseData; +import org.openqa.selenium.json.JsonException; + +/** Numbers held to the bounds the schema declares on the field itself, not only on js-int/uint. */ +@Tag("UnitTests") +class DeclaredRangeTest { + + @Test + void exclusiveMinimumRejectsTheBoundItself() { + assertThatThrownBy(() -> new SetViewportParameters().setDevicePixelRatio(0)) + .isInstanceOf(BiDiException.class) + .hasMessageContaining("devicePixelRatio must be > 0"); + } + + @Test + void exclusiveMinimumAcceptsAValueJustAboveIt() { + assertThat(new SetViewportParameters().setDevicePixelRatio(0.5).getDevicePixelRatio()) + .contains(0.5); + } + + @Test + void notANumberIsOutOfEveryRange() { + assertThatThrownBy(() -> new SetViewportParameters().setDevicePixelRatio(Double.NaN)) + .isInstanceOf(BiDiException.class); + } + + @Test + void explicitNullIsStillAllowedForANullableBoundedField() { + assertThat(new SetViewportParameters().setDevicePixelRatio(null).toMap()) + .containsEntry("devicePixelRatio", null); + } + + @Test + void exclusiveMaximumRejectsTheBoundItself() { + assertThatThrownBy(() -> new GeolocationCoordinates(0, 0).setHeading(360)) + .isInstanceOf(BiDiException.class) + .hasMessageContaining("heading must be >= 0 and < 360"); + } + + @Test + void exclusiveMaximumAcceptsAValueJustBelowIt() { + assertThat(new GeolocationCoordinates(0, 0).setHeading(359.9).getHeading()).contains(359.9); + } + + @Test + void requiredNumberIsCheckedAtConstruction() { + assertThatThrownBy(() -> new GeolocationCoordinates(90.0001, 0)) + .isInstanceOf(BiDiException.class) + .hasMessageContaining("latitude"); + } + + @Test + void negativeStatusIsRejectedOnReceipt() { + String raw = + "{\"url\":\"u\",\"protocol\":\"http/1.1\",\"status\":-1,\"statusText\":\"\"," + + "\"fromCache\":false,\"headers\":[],\"mimeType\":\"\",\"bytesReceived\":0," + + "\"headersSize\":null,\"bodySize\":null,\"content\":{\"size\":0}}"; + + assertThatThrownBy(() -> ConverterFunctions.JSON.toType(raw, ResponseData.class)) + .isInstanceOf(JsonException.class) + .hasStackTraceContaining("status must be"); + } +} diff --git a/java/test/org/openqa/selenium/bidi/protocol/input/JsIntRangeTest.java b/java/test/org/openqa/selenium/bidi/protocol/input/JsIntRangeTest.java index 409cd8d8f1dbd..bae01c60e794b 100644 --- a/java/test/org/openqa/selenium/bidi/protocol/input/JsIntRangeTest.java +++ b/java/test/org/openqa/selenium/bidi/protocol/input/JsIntRangeTest.java @@ -62,9 +62,10 @@ void jsIntRejectsAValueOnePastTheNegativeBoundary() { .hasMessageContaining("x"); } - // browsingContext.LocateNodesParameters.maxNodeCount is js-uint (unsigned) — same upper bound - // as js-int, but 0 is the floor instead of -(2^53 - 1). It's optional, so this also exercises - // the fluent setter path (a caller-created value), not just the constructor. + // browsingContext.LocateNodesParameters.maxNodeCount is js-uint (unsigned) narrowed by its own + // ".ge 1" — same upper bound as js-int, but 1 is the floor instead of -(2^53 - 1). It's + // optional, so this also exercises the fluent setter path (a caller-created value), not just + // the constructor. private static LocateNodesParameters params() { return new LocateNodesParameters("context-1", new CssLocator("css", "div")); @@ -78,10 +79,17 @@ void jsUintRejectsANegativeValue() { } @Test - void jsUintAcceptsZero() { - LocateNodesParameters p = params().setMaxNodeCount(0L); + void fieldBoundRejectsZeroThatTheAliasAloneWouldAllow() { + assertThatThrownBy(() -> params().setMaxNodeCount(0L)) + .isInstanceOf(BiDiException.class) + .hasMessageContaining("maxNodeCount"); + } + + @Test + void fieldBoundAcceptsItsOwnFloor() { + LocateNodesParameters p = params().setMaxNodeCount(1L); - assertThat(p.getMaxNodeCount()).contains(0L); + assertThat(p.getMaxNodeCount()).contains(1L); } @Test