1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3;
19
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import org.junit.jupiter.api.Test;
23
24
25
26
27
28
29
30
31
32
33
34
35 class ValidateDoublesTest extends AbstractLangTest {
36
37 @Test
38 void exclusiveBetweenRejectsNaN() {
39 assertThrows(IllegalArgumentException.class, () -> Validate.exclusiveBetween(0.0, 10.0, Double.NaN),
40 "NaN should be rejected by exclusiveBetween but is silently accepted");
41 }
42
43 @Test
44 void exclusiveBetweenWithMessageRejectsNaN() {
45 assertThrows(IllegalArgumentException.class, () -> Validate.exclusiveBetween(0.0, 10.0, Double.NaN, "value must be in (0,10)"),
46 "NaN should be rejected by exclusiveBetween(with message)");
47 }
48
49 @Test
50 void inclusiveBetweenRejectsNaN() {
51 assertThrows(IllegalArgumentException.class, () -> Validate.inclusiveBetween(0.0, 10.0, Double.NaN),
52 "NaN should be rejected by inclusiveBetween but is silently accepted");
53 }
54
55 @Test
56 void inclusiveBetweenRejectsNegativeInfinity() {
57 assertThrows(IllegalArgumentException.class, () -> Validate.inclusiveBetween(0.0, 10.0, Double.NEGATIVE_INFINITY),
58 "Positive infinity beyond range end should be rejected");
59 }
60
61 @Test
62 void inclusiveBetweenRejectsPositiveInfinity() {
63 assertThrows(IllegalArgumentException.class, () -> Validate.inclusiveBetween(0.0, 10.0, Double.POSITIVE_INFINITY),
64 "Positive infinity beyond range end should be rejected");
65 }
66
67 @Test
68 void inclusiveBetweenWithMessageRejectsNaN() {
69 assertThrows(IllegalArgumentException.class, () -> Validate.inclusiveBetween(0.0, 10.0, Double.NaN, "value must be in [0,10]"),
70 "NaN should be rejected by inclusiveBetween(with message)");
71 }
72
73 @Test
74 void validFiniteValuesStillAccepted() {
75 Validate.inclusiveBetween(0.0, 10.0, 5.0);
76 Validate.inclusiveBetween(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0);
77 Validate.exclusiveBetween(0.0, 10.0, 5.0);
78 Validate.exclusiveBetween(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0);
79 }
80 }