Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Bilyana Gospodinova <[email protected]>
  • Loading branch information
bilyana-gospodinova committed Nov 5, 2024
1 parent ef676f2 commit b59a4ff
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,30 @@ void testEqualsDifferentType() {
assertThat(mapReadableKVState).isNotEqualTo("someString");
}

@Test
void testEqualsWithNull() {
assertThat(mapReadableKVState).isNotEqualTo(null);
}

@Test
void testEqualsSameValues() {
MapReadableKVState<AccountID, Account> other = new MapReadableKVState<>("ACCOUNTS", accountMap);
assertThat(mapReadableKVState).isEqualTo(other);
}

@Test
void testEqualsDifferentValues() {
void testEqualsDifferentKeys() {
MapReadableKVState<AccountID, Account> other = new MapReadableKVState<>("ALIASES", accountMap);
assertThat(mapReadableKVState).isNotEqualTo(other);
}

@Test
void testEqualsDifferentValues() {
final var accountMapOther = Map.of(AccountID.newBuilder().accountNum(3L).build(), account);
MapReadableKVState<AccountID, Account> other = new MapReadableKVState<>("ACCOUNTS", accountMapOther);
assertThat(mapReadableKVState).isNotEqualTo(other);
}

@Test
void testHashCode() {
MapReadableKVState<AccountID, Account> other = new MapReadableKVState<>("ACCOUNTS", accountMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ void testEqualsDifferentType() {
assertThat(states).isNotEqualTo("someString");
}

@Test
void testEqualsWithNull() {
assertThat(states).isNotEqualTo(null);
}

@Test
void testEqualsSameValues() {
MapReadableStates other = new MapReadableStates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,18 +104,31 @@ void testEqualsDifferentType() {
assertThat(mapWritableKVState).isNotEqualTo("someString");
}

@Test
void testEqualsWithNull() {
assertThat(mapWritableKVState).isNotEqualTo(null);
}

@Test
void testEqualsSameValues() {
MapWritableKVState<AccountID, Account> other = new MapWritableKVState<>("ACCOUNTS", readableKVState);
assertThat(mapWritableKVState).isEqualTo(other);
}

@Test
void testEqualsDifferentValues() {
void testEqualsDifferentKeys() {
MapWritableKVState<AccountID, Account> 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<AccountID, Account> other = new MapWritableKVState<>("ACCOUNTS", readableKVStateOther);
assertThat(mapWritableKVState).isNotEqualTo(other);
}

@Test
void testHashCode() {
MapWritableKVState<AccountID, Account> other = new MapWritableKVState<>("ACCOUNTS", readableKVState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,26 @@ void testStateKeysReturnsUnmodifiableSet() {
Set<String> 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);
}
}

0 comments on commit b59a4ff

Please sign in to comment.