Skip to content

Commit

Permalink
AssertThrows instead of cacthing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Nov 26, 2023
1 parent bda8e7b commit d14ec53
Showing 1 changed file with 8 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,21 @@
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class SpaceTreeTest {
@Test
public void test2DTreeErrors() {
SpaceTree<Object> tree = new SpaceTree<>(2);

try {
tree.add(null, new Object());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.add(new float[1], new Object());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.add(new float[3], new Object());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.add(new float[2], null);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.remove(null);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.remove(new float[1]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}

try {
tree.remove(new float[3]);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException exp) {
// Expected
}
assertThrows(IllegalArgumentException.class, () -> tree.add(null, new Object()));
assertThrows(IllegalArgumentException.class, () -> tree.add(new float[1], new Object()));
assertThrows(IllegalArgumentException.class, () -> tree.add(new float[3], new Object()));
assertThrows(IllegalArgumentException.class, () -> tree.add(new float[2], null));
assertThrows(IllegalArgumentException.class, () -> tree.remove(null));
assertThrows(IllegalArgumentException.class, () -> tree.remove(new float[1]));
assertThrows(IllegalArgumentException.class, () -> tree.remove(new float[3]));
}

@Test
Expand Down

0 comments on commit d14ec53

Please sign in to comment.