1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.core;
18
19 import java.util.regex.Pattern;
20
21 import org.junit.jupiter.api.Assertions;
22 import org.junit.jupiter.api.function.Executable;
23
24
25
26 public final class GeometryTestUtils {
27
28
29 private GeometryTestUtils() {}
30
31
32
33
34 public static void assertPositiveInfinity(final double value) {
35 final String msg = "Expected value to be positive infinity but was " + value;
36 Assertions.assertTrue(Double.isInfinite(value), msg);
37 Assertions.assertTrue(value > 0, msg);
38 }
39
40
41
42
43 public static void assertNegativeInfinity(final double value) {
44 final String msg = "Expected value to be negative infinity but was " + value;
45 Assertions.assertTrue(Double.isInfinite(value), msg);
46 Assertions.assertTrue(value < 0, msg);
47 }
48
49
50
51
52
53
54 public static <T extends Throwable> void assertThrowsWithMessage(final Executable executable,
55 final Class<T> exceptionType, final String message) {
56 Assertions.assertEquals(message, Assertions.assertThrows(exceptionType, executable).getMessage());
57 }
58
59
60
61
62
63
64
65 public static <T extends Throwable> void assertThrowsWithMessage(final Executable executable,
66 final Class<T> exceptionType, final Pattern pattern) {
67 final String message = Assertions.assertThrows(exceptionType, executable).getMessage();
68 Assertions.assertTrue(pattern.matcher(message).matches(),
69 "Expected exception message to match /" + pattern + "/ but was [" + message + "]");
70 }
71
72
73
74
75
76 public static void assertContains(final String substr, final String actual) {
77 final String msg = "Expected string to contain [" + substr + "] but was [" + actual + "]";
78 Assertions.assertTrue(actual.contains(substr), msg);
79 }
80
81
82
83
84
85
86
87
88
89 public static void assertSimpleEqualsCases(final Object obj) {
90
91
92
93 Assertions.assertFalse(obj.equals(null), "Object should not equal null");
94
95 if (obj.getClass().getSuperclass() != null) {
96 Assertions.assertFalse(obj.equals(new Object()), "Object should not equal an instance of different type");
97 }
98
99 Assertions.assertTrue(obj.equals(obj), "Object should equal itself");
100 }
101 }