Skip to content

Commit

Permalink
Throw illegal arg exception if invalid input
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 19, 2024
1 parent 4193a81 commit 6134bdb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private Optional<String> updateGraffiti(final BLSPublicKey publicKey) {
private Optional<String> updateGraffiti(final BLSPublicKey publicKey, final String graffiti) {
final int graffitiSize = graffiti.getBytes(StandardCharsets.UTF_8).length;
if (graffitiSize > 32) {
return Optional.of(
throw new IllegalArgumentException(
String.format(
"'%s' converts to %s bytes. Input must be 32 bytes or less.",
graffiti, graffitiSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ void setGraffiti_shouldThrowExceptionWhenGraffitiTooBig(@TempDir final Path temp
manager = new GraffitiManager(dataDirLayout);
assertThat(getGraffitiManagementDir().toFile().exists()).isTrue();

assertThat(manager.setGraffiti(publicKey, invalidGraffiti))
.hasValue(
assertThatThrownBy(() -> manager.setGraffiti(publicKey, invalidGraffiti))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(
"'This graffiti is a bit too long!!' converts to 33 bytes. Input must be 32 bytes or less.");
}

Expand Down

0 comments on commit 6134bdb

Please sign in to comment.