From bfe15ee708df5e0cecee38246b5dd1b32008ddd4 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 4 Nov 2023 23:50:27 -0400 Subject: [PATCH] Change to add assertThat and assertThatThrownBy --- .../com/ossez/uuid/UUIDValidatorUnitTest.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/core-java-modules/core-java-uuid/src/test/java/com/ossez/uuid/UUIDValidatorUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/ossez/uuid/UUIDValidatorUnitTest.java index 0cdd05360f..4620cdc195 100644 --- a/core-java-modules/core-java-uuid/src/test/java/com/ossez/uuid/UUIDValidatorUnitTest.java +++ b/core-java-modules/core-java-uuid/src/test/java/com/ossez/uuid/UUIDValidatorUnitTest.java @@ -6,24 +6,31 @@ import org.junit.jupiter.api.Test; import java.util.UUID; import java.util.regex.Pattern; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + public class UUIDValidatorUnitTest { - @Test - public void whenValidUUIDStringIsValidated_thenValidationSucceeds() { - String validUUID = "26929514-237c-11ed-861d-0242ac120002"; - Assertions.assertEquals(UUID.fromString(validUUID).toString(), validUUID); + @Test + public void whenValidUUIDStringIsValidated_thenValidationSucceeds() { + String validUUID = "26929514-237c-11ed-861d-0242ac120002"; + Assertions.assertEquals(UUID.fromString(validUUID).toString(), validUUID); + assertThat(UUID.fromString(validUUID).toString()).isEqualTo(validUUID); - String invalidUUID = "invalid-uuid"; - Assertions.assertThrows(IllegalArgumentException.class, () -> UUID.fromString(invalidUUID)); - } + String invalidUUID = "invalid-uuid"; + Assertions.assertThrows(IllegalArgumentException.class, () -> UUID.fromString(invalidUUID)); + assertThatThrownBy(() -> { + UUID.fromString(invalidUUID); + }).isInstanceOf(IllegalArgumentException.class); - @Test - public void whenUUIDIsValidatedUsingRegex_thenValidationSucceeds() { - Pattern UUID_REGEX = - Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + } - Assertions.assertTrue(UUID_REGEX.matcher("26929514-237c-11ed-861d-0242ac120002").matches()); + @Test + public void whenUUIDIsValidatedUsingRegex_thenValidationSucceeds() { + Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - Assertions.assertFalse(UUID_REGEX.matcher("invalid-uuid").matches()); - } + Assertions.assertTrue(UUID_REGEX.matcher("26929514-237c-11ed-861d-0242ac120002").matches()); + + Assertions.assertFalse(UUID_REGEX.matcher("invalid-uuid").matches()); + } }