|
6 | 6 | import java.util.UUID; |
7 | 7 | import java.util.regex.Pattern; |
8 | 8 |
|
| 9 | +import static org.assertj.core.api.Assertions.assertThat; |
| 10 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 11 | + |
9 | 12 | public class UUIDValidatorUnitTest { |
10 | 13 |
|
11 | | - @Test |
12 | | - public void whenValidUUIDStringIsValidated_thenValidationSucceeds() { |
13 | | - String validUUID = "26929514-237c-11ed-861d-0242ac120002"; |
14 | | - Assertions.assertEquals(UUID.fromString(validUUID).toString(), validUUID); |
| 14 | + @Test |
| 15 | + public void whenValidUUIDStringIsValidated_thenValidationSucceeds() { |
| 16 | + String validUUID = "26929514-237c-11ed-861d-0242ac120002"; |
| 17 | + Assertions.assertEquals(UUID.fromString(validUUID).toString(), validUUID); |
| 18 | + assertThat(UUID.fromString(validUUID).toString()).isEqualTo(validUUID); |
| 19 | + |
| 20 | + String invalidUUID = "invalid-uuid"; |
| 21 | + Assertions.assertThrows(IllegalArgumentException.class, () -> UUID.fromString(invalidUUID)); |
| 22 | + assertThatThrownBy(() -> { |
| 23 | + UUID.fromString(invalidUUID); |
| 24 | + }).isInstanceOf(IllegalArgumentException.class); |
15 | 25 |
|
16 | | - String invalidUUID = "invalid-uuid"; |
17 | | - Assertions.assertThrows(IllegalArgumentException.class, () -> UUID.fromString(invalidUUID)); |
18 | | - } |
| 26 | + } |
19 | 27 |
|
20 | | - @Test |
21 | | - public void whenUUIDIsValidatedUsingRegex_thenValidationSucceeds() { |
22 | | - Pattern UUID_REGEX = |
23 | | - 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}$"); |
| 28 | + @Test |
| 29 | + public void whenUUIDIsValidatedUsingRegex_thenValidationSucceeds() { |
| 30 | + 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}$"); |
24 | 31 |
|
25 | | - Assertions.assertTrue(UUID_REGEX.matcher("26929514-237c-11ed-861d-0242ac120002").matches()); |
| 32 | + Assertions.assertTrue(UUID_REGEX.matcher("26929514-237c-11ed-861d-0242ac120002").matches()); |
26 | 33 |
|
27 | | - Assertions.assertFalse(UUID_REGEX.matcher("invalid-uuid").matches()); |
28 | | - } |
| 34 | + Assertions.assertFalse(UUID_REGEX.matcher("invalid-uuid").matches()); |
| 35 | + } |
29 | 36 | } |
0 commit comments