From 025a89706a787608fc176804d7d32403c008f15b Mon Sep 17 00:00:00 2001 From: Felipe Fumero Date: Mon, 2 Nov 2026 14:30:34 -0600 Subject: [PATCH] test: make B2Json Container.equals check all fields and test the version-range upper bound Compare the serialized-name field during Container equality checks and provide a matching hash code. Exercise version 6 in the version-range upper-bound case. --- .../java/com/backblaze/b2/json/B2JsonTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/backblaze/b2/json/B2JsonTest.java b/core/src/test/java/com/backblaze/b2/json/B2JsonTest.java index 340733003..6f1276ec3 100644 --- a/core/src/test/java/com/backblaze/b2/json/B2JsonTest.java +++ b/core/src/test/java/com/backblaze/b2/json/B2JsonTest.java @@ -85,7 +85,12 @@ public boolean equals(Object o) { return false; } Container other = (Container) o; - return a == other.a && (b == null ? other.b == null : b.equals(other.b)); + return a == other.a && Objects.equals(b, other.b) && Objects.equals(d, other.d); + } + + @Override + public int hashCode() { + return Objects.hash(a, b, d); } } @@ -174,7 +179,10 @@ public void testObject() throws B2JsonException { " \"b\": \"hello\",\n" + " \"\\u0040d\": \"goodbye\"\n" + "}"; - assertEquals(obj, b2Json.fromJson(alternateJson, Container.class)); + final Container decodedAlternate = b2Json.fromJson(alternateJson, Container.class); + assertEquals("goodbye", decodedAlternate.d); + assertEquals(obj, decodedAlternate); + assertFalse(new Container(41, "hello", "not-goodbye").equals(decodedAlternate)); } @Test @@ -2157,7 +2165,7 @@ public void testSerializeSkipFieldNotInVersion() throws B2JsonException { // Version 6 is the last version where it's present { - final B2JsonOptions options = B2JsonOptions.builder().setVersion(4).build(); + final B2JsonOptions options = B2JsonOptions.builder().setVersion(6).build(); assertEquals( "{\n \"x\": 3\n}", b2Json.toJson(new VersionedContainer(3, 5), options)