-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionsTest.java
More file actions
51 lines (38 loc) · 1.69 KB
/
ExceptionsTest.java
File metadata and controls
51 lines (38 loc) · 1.69 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
package com.tabs.exceptions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class ExceptionsTest {
@Test
void creditBlockedException_preservesMessage() {
CreditBlockedException ex = new CreditBlockedException("credit blocked");
assertEquals("credit blocked", ex.getMessage());
assertNull(ex.getCause());
}
@Test
void customerNotFoundException_preservesMessage() {
CustomerNotFoundException ex = new CustomerNotFoundException("customer missing");
assertEquals("customer missing", ex.getMessage());
assertNull(ex.getCause());
}
@Test
void invoiceGenerationException_preservesMessageAndCause() {
IllegalStateException cause = new IllegalStateException("root cause");
InvoiceGenerationException ex = new InvoiceGenerationException("invoice failed", cause);
assertEquals("invoice failed", ex.getMessage());
assertSame(cause, ex.getCause());
assertEquals("root cause", ex.getCause().getMessage());
}
@Test
void subscriptionNotFoundException_preservesMessage() {
SubscriptionNotFoundException ex = new SubscriptionNotFoundException("subscription missing");
assertEquals("subscription missing", ex.getMessage());
assertNull(ex.getCause());
}
@Test
void exceptions_canBeUsedWithEnvironmentConfiguredUrlReference() {
String url = System.getenv("URL");
assertNotNull(url, "URL environment variable should be available in the test environment");
CreditBlockedException ex = new CreditBlockedException("blocked while accessing: " + url);
assertTrue(ex.getMessage().contains(url));
}
}