From b59a4ff8933f8deb4a3376d021f9ff5bc9a9ecf1 Mon Sep 17 00:00:00 2001 From: Bilyana Gospodinova Date: Tue, 5 Nov 2024 16:51:04 +0200 Subject: [PATCH] Increase code coverage Signed-off-by: Bilyana Gospodinova --- .../state/utils/MapReadableKVStateTest.java | 14 +++++++++++- .../state/utils/MapReadableStatesTest.java | 5 +++++ .../state/utils/MapWritableKVStateTest.java | 16 +++++++++++++- .../state/utils/MapWritableStatesTest.java | 22 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableKVStateTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableKVStateTest.java index fdc51f25cd..eb4f27a2bb 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableKVStateTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableKVStateTest.java @@ -89,6 +89,11 @@ void testEqualsDifferentType() { assertThat(mapReadableKVState).isNotEqualTo("someString"); } + @Test + void testEqualsWithNull() { + assertThat(mapReadableKVState).isNotEqualTo(null); + } + @Test void testEqualsSameValues() { MapReadableKVState other = new MapReadableKVState<>("ACCOUNTS", accountMap); @@ -96,11 +101,18 @@ void testEqualsSameValues() { } @Test - void testEqualsDifferentValues() { + void testEqualsDifferentKeys() { MapReadableKVState other = new MapReadableKVState<>("ALIASES", accountMap); assertThat(mapReadableKVState).isNotEqualTo(other); } + @Test + void testEqualsDifferentValues() { + final var accountMapOther = Map.of(AccountID.newBuilder().accountNum(3L).build(), account); + MapReadableKVState other = new MapReadableKVState<>("ACCOUNTS", accountMapOther); + assertThat(mapReadableKVState).isNotEqualTo(other); + } + @Test void testHashCode() { MapReadableKVState other = new MapReadableKVState<>("ACCOUNTS", accountMap); diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableStatesTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableStatesTest.java index dde0939492..60984b5c9b 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableStatesTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapReadableStatesTest.java @@ -128,6 +128,11 @@ void testEqualsDifferentType() { assertThat(states).isNotEqualTo("someString"); } + @Test + void testEqualsWithNull() { + assertThat(states).isNotEqualTo(null); + } + @Test void testEqualsSameValues() { MapReadableStates other = new MapReadableStates( diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java index 79813f24a0..039edeed85 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java @@ -23,6 +23,7 @@ import com.hedera.hapi.node.state.token.Account; import com.swirlds.state.spi.ReadableKVState; import java.util.Collections; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -103,6 +104,11 @@ void testEqualsDifferentType() { assertThat(mapWritableKVState).isNotEqualTo("someString"); } + @Test + void testEqualsWithNull() { + assertThat(mapWritableKVState).isNotEqualTo(null); + } + @Test void testEqualsSameValues() { MapWritableKVState other = new MapWritableKVState<>("ACCOUNTS", readableKVState); @@ -110,11 +116,19 @@ void testEqualsSameValues() { } @Test - void testEqualsDifferentValues() { + void testEqualsDifferentKeys() { MapWritableKVState other = new MapWritableKVState<>("ALIASES", readableKVState); assertThat(mapWritableKVState).isNotEqualTo(other); } + @Test + void testEqualsDifferentValues() { + final var accountMapOther = Map.of(AccountID.newBuilder().accountNum(3L).build(), account); + final var readableKVStateOther = new MapReadableKVState<>("ACCOUNTS", accountMapOther); + MapWritableKVState other = new MapWritableKVState<>("ACCOUNTS", readableKVStateOther); + assertThat(mapWritableKVState).isNotEqualTo(other); + } + @Test void testHashCode() { MapWritableKVState other = new MapWritableKVState<>("ACCOUNTS", readableKVState); diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java index 9ab6defe74..931c0d67bd 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java @@ -117,4 +117,26 @@ void testStateKeysReturnsUnmodifiableSet() { Set keys = states.stateKeys(); assertThatThrownBy(() -> keys.add("newKey")).isInstanceOf(UnsupportedOperationException.class); } + + @Test + void testEqualsSameInstance() { + assertThat(states).isEqualTo(states); + } + + @Test + void testEqualsDifferentClass() { + assertThat(states).isNotEqualTo("other"); + } + + @Test + void testEqualsWithNull() { + assertThat(states).isNotEqualTo(null); + } + + @Test + void testHashCode() { + MapWritableStates other = new MapWritableStates( + Map.of(KV_STATE_KEY, kvStateMock, SINGLETON_KEY, singletonStateMock, QUEUE_KEY, queueStateMock)); + assertThat(states).hasSameHashCodeAs(other); + } }