1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.events;
18
19 import org.hamcrest.CoreMatchers;
20 import org.hamcrest.MatcherAssert;
21 import org.junit.jupiter.api.Assertions;
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mockito;
24 import org.orekit.propagation.SpacecraftState;
25 import org.orekit.time.AbsoluteDate;
26
27
28
29
30
31
32 class NegateDetectorTest {
33
34 @Test
35 void testInitBackward() {
36
37 final DateDetector dateDetector = new DateDetector();
38 final NegateDetector negateDetector = new NegateDetector(dateDetector);
39 final SpacecraftState state = Mockito.mock(SpacecraftState.class);
40 Mockito.when(state.getDate()).thenReturn(AbsoluteDate.ARBITRARY_EPOCH);
41
42
43 negateDetector.init(state, AbsoluteDate.PAST_INFINITY);
44
45
46 Assertions.assertEquals(dateDetector.isForward(), negateDetector.isForward());
47 }
48
49 @Test
50 void testInitForward() {
51
52 final DateDetector dateDetector = new DateDetector();
53 final NegateDetector negateDetector = new NegateDetector(dateDetector);
54 final SpacecraftState state = Mockito.mock(SpacecraftState.class);
55 Mockito.when(state.getDate()).thenReturn(AbsoluteDate.ARBITRARY_EPOCH);
56
57
58 negateDetector.init(state, AbsoluteDate.FUTURE_INFINITY);
59
60
61 Assertions.assertEquals(dateDetector.isForward(), negateDetector.isForward());
62 }
63
64 @Test
65 void testGetDetector() {
66
67 EventDetector expectedDetector = new DateDetector();
68
69
70 NegateDetector detector = new NegateDetector(expectedDetector);
71
72
73 Assertions.assertEquals(expectedDetector, detector.getDetector());
74 Assertions.assertEquals(expectedDetector, detector.getOriginal());
75 }
76
77
78
79
80 @Test
81 void testG() {
82
83 EventDetector a = Mockito.mock(EventDetector.class);
84 Mockito.when(a.getDetectionSettings()).thenReturn(EventDetectionSettings.getDefaultEventDetectionSettings());
85 NegateDetector detector = new NegateDetector(a);
86 SpacecraftState s = Mockito.mock(SpacecraftState.class);
87
88
89 Mockito.when(a.g(s)).thenReturn(1.0);
90 MatcherAssert.assertThat(detector.g(s), CoreMatchers.is(-1.0));
91
92 Mockito.when(a.g(s)).thenReturn(-1.0);
93 MatcherAssert.assertThat(detector.g(s), CoreMatchers.is(1.0));
94 }
95
96
97 @Test
98 void testCreate() {
99
100 EventDetector a = Mockito.mock(EventDetector.class);
101 Mockito.when(a.getDetectionSettings()).thenReturn(EventDetectionSettings.getDefaultEventDetectionSettings());
102 NegateDetector detector = new NegateDetector(a);
103
104
105 NegateDetector actual = detector.withMaxCheck(100);
106
107
108 MatcherAssert.assertThat(actual.getMaxCheckInterval().currentInterval(null, true), CoreMatchers.is(100.0));
109 Assertions.assertSame(actual.getOriginal(), a);
110 }
111 }