|
| 1 | +package org.openpodcastapi.opa.helpers; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import java.util.UUID; |
| 6 | + |
| 7 | +import static org.junit.jupiter.api.Assertions.*; |
| 8 | +import static org.openpodcastapi.opa.helpers.UUIDHelper.*; |
| 9 | + |
| 10 | +class UUIDHelperTest { |
| 11 | + @Test |
| 12 | + void sanitizeFeedUrl_shouldSanitizeValidUrl() { |
| 13 | + final String feedUrl = "https://test.com/feed1/"; |
| 14 | + final String expectedUrl = "test.com/feed1"; |
| 15 | + String cleanedUrl = sanitizeFeedUrl(feedUrl); |
| 16 | + |
| 17 | + assertEquals(expectedUrl, cleanedUrl); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + void sanitizeFeedUrl_shouldSanitizeUrlWithoutScheme() { |
| 22 | + final String feedUrl = "test.com/feed1"; |
| 23 | + final String expectedUrl = "test.com/feed1"; |
| 24 | + String cleanedUrl = sanitizeFeedUrl(feedUrl); |
| 25 | + |
| 26 | + assertEquals(expectedUrl, cleanedUrl); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + void sanitizeFeedUrl_shouldThrowOnInvalidUrl() { |
| 31 | + final String feedUrl = "ftp://test.com/feed1"; |
| 32 | + final String expectedMessage = "Invalid feed URL passed to function"; |
| 33 | + |
| 34 | + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> sanitizeFeedUrl(feedUrl)); |
| 35 | + |
| 36 | + assertTrue(exception.getMessage().contains(expectedMessage)); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void getFeedUUID_shouldReturnGeneratedUUID() { |
| 41 | + final String feedUrl = "podnews.net/rss"; |
| 42 | + final UUID expectedUUID = UUID.fromString("9b024349-ccf0-5f69-a609-6b82873eab3c"); |
| 43 | + |
| 44 | + UUID calculatedUUID = getFeedUUID(feedUrl); |
| 45 | + |
| 46 | + assertEquals(expectedUUID, calculatedUUID); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void getFeedUUID_shouldReturnDeterministicUUID() { |
| 51 | + final String feedUrl = "podnews.net/rss"; |
| 52 | + final UUID incorrectUUID = UUID.fromString("d5d5520d-81da-474e-928b-5fa66233a1ac"); |
| 53 | + |
| 54 | + UUID calculatedUUID = getFeedUUID(feedUrl); |
| 55 | + |
| 56 | + assertNotEquals(incorrectUUID, calculatedUUID); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void validateSubscriptionUUID_shouldReturnTrueWhenValid() { |
| 61 | + final String feedUrl = "podnews.net/rss"; |
| 62 | + final UUID expectedUUID = UUID.fromString("9b024349-ccf0-5f69-a609-6b82873eab3c"); |
| 63 | + |
| 64 | + assertTrue(validateSubscriptionUUID(feedUrl, expectedUUID)); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void validateSubscriptionUUID_shouldReturnFalseWhenInvalid() { |
| 69 | + final String feedUrl = "podnews.net/rss"; |
| 70 | + final UUID incorrectUUID = UUID.fromString("d5d5520d-81da-474e-928b-5fa66233a1ac"); |
| 71 | + |
| 72 | + assertFalse(validateSubscriptionUUID(feedUrl, incorrectUUID)); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + void validateUUIDString_shouldReturnTrueWhenValid() { |
| 77 | + final String validUUID = "d5d5520d-81da-474e-928b-5fa66233a1ac"; |
| 78 | + |
| 79 | + assertTrue(validateUUIDString(validUUID)); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + void validateUUIDString_shouldReturnFalseWhenInvalid() { |
| 84 | + final String validUUID = "not-a-uuid"; |
| 85 | + |
| 86 | + assertFalse(validateUUIDString(validUUID)); |
| 87 | + } |
| 88 | +} |
0 commit comments