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