Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve NoNulls map code coverage #1758

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/test/java/org/cactoos/map/NoNullsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,50 @@ void putThrowsErrorIfPreviousValueNull() {
)
).affirm();
}

@Test
void putThrowsErrorIfKeyIsNull() {
new Assertion<>(
"Should throw an error if key is null",
() -> new NoNulls<Integer, Integer>(
new HashMap<>()
).put(null, 1),
new Throws<>(
"Key at #put(K,1) is NULL",
IllegalStateException.class
)
).affirm();
}

@Test
void removeThrowsErrorIfKeyIsNull() {
new Assertion<>(
"Should throw an error if key is null",
() -> new NoNulls<Integer, Integer>(
new HashMap<>()
).remove(null),
new Throws<>(
"Key at #remove(K) is NULL",
IllegalStateException.class
)
).affirm();
}

@Test
void removeThrowsErrorIfValueIsNull() {
new Assertion<>(
"Should throw an error if removed value is null",
() -> new NoNulls<>(
new HashMap<Integer, Integer>() {
{
put(1, null);
}
}
).remove(1),
new Throws<>(
"Value returned by #remove(1) is NULL",
IllegalStateException.class
)
).affirm();
}
}