Skip to content

Commit 7d27c1d

Browse files
committed
Fix
1 parent 1661b83 commit 7d27c1d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/test/java/com/thealgorithms/datastructures/caches/MRUCacheTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertNull;
6+
import static org.junit.jupiter.api.Assertions.fail;
67

78
import org.junit.jupiter.api.Test;
89

@@ -132,32 +133,28 @@ public void capacityValidation() {
132133
// Testing for zero capacity
133134
try {
134135
new MRUCache<>(0); // Should throw an exception
136+
// If no exception is thrown, we should fail the test
137+
fail("Expected IllegalArgumentException for capacity 0");
135138
} catch (IllegalArgumentException e) {
136139
exception = e; // Store the exception if caught
137140
}
138141

139-
// Ensure exception is not null before accessing its message
142+
// Ensure exception is not null and check the message
140143
assertNotNull(exception, "Expected IllegalArgumentException for capacity 0");
141-
142-
if (exception != null) {
143-
assertEquals("Capacity must be greater than 0!", exception.getMessage());
144-
}
144+
assertEquals("Capacity must be greater than 0!", exception.getMessage());
145145

146146
// Resetting exception for the next test
147-
exception = null;
148-
149147
// Testing for negative capacity
150148
try {
151149
new MRUCache<>(-1); // Should throw an exception
150+
// If no exception is thrown, we should fail the test
151+
fail("Expected IllegalArgumentException for capacity -1");
152152
} catch (IllegalArgumentException e) {
153153
exception = e; // Store the exception if caught
154154
}
155155

156-
// Ensure exception is not null before accessing its message
156+
// Ensure exception is not null and check the message
157157
assertNotNull(exception, "Expected IllegalArgumentException for capacity -1");
158-
159-
if (exception != null) {
160-
assertEquals("Capacity must be greater than 0!", exception.getMessage());
161-
}
158+
assertEquals("Capacity must be greater than 0!", exception.getMessage());
162159
}
163160
}

0 commit comments

Comments
 (0)