Skip to content

Commit 9956b2c

Browse files
ctruedenclaude
andcommitted
Test Evaluator remove and clear methods
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9d801ca commit 9956b2c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/test/java/org/scijava/parsington/eval/AbstractEvaluatorTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
package org.scijava.parsington.eval;
3232

3333
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertNull;
3435
import static org.junit.jupiter.api.Assertions.assertThrows;
3536
import static org.junit.jupiter.api.Assertions.assertTrue;
3637

@@ -64,6 +65,30 @@ public void testGetSet() {
6465
assertEquals("hello", e.get("x"));
6566
}
6667

68+
/** Tests {@link Evaluator#remove(String)}. */
69+
@Test
70+
public void testRemove() {
71+
final Evaluator e = createEvaluator();
72+
// Removing an absent variable returns null.
73+
assertNull(e.remove("x"));
74+
e.set("x", 99);
75+
assertEquals(99, e.remove("x"));
76+
// Variable is gone after removal.
77+
assertThrows(IllegalArgumentException.class, () -> e.get("x"));
78+
}
79+
80+
/** Tests {@link Evaluator#clear()}. */
81+
@Test
82+
public void testClear() {
83+
final Evaluator e = createEvaluator();
84+
e.set("a", 1);
85+
e.set("b", 2);
86+
e.clear();
87+
assertEquals(new HashMap<>(), e.getAll());
88+
assertThrows(IllegalArgumentException.class, () -> e.get("a"));
89+
assertThrows(IllegalArgumentException.class, () -> e.get("b"));
90+
}
91+
6792
/** Tests {@link Evaluator#getAll()} and {@link Evaluator#setAll(Map)}. */
6893
@Test
6994
public void testGetAllSetAll() {

0 commit comments

Comments
 (0)