1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.events.handlers;
18
19 import org.hipparchus.complex.Complex;
20 import org.hipparchus.complex.ComplexField;
21 import org.hipparchus.ode.events.Action;
22 import org.junit.jupiter.api.Assertions;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.Mockito;
25 import org.orekit.propagation.FieldSpacecraftState;
26 import org.orekit.propagation.events.FieldEventDetector;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.time.FieldAbsoluteDate;
29
30 class FieldRecallLastOccurrenceTest {
31
32 private static final Action ACTION = Action.CONTINUE;
33
34 @Test
35 void testEventOccurred() {
36
37 final TestHandler testHandler = new TestHandler();
38 final FieldRecallLastOccurrence<Complex> recallLastOccurrence = new FieldRecallLastOccurrence<>(testHandler);
39 final FieldAbsoluteDate<Complex> expectedDate = FieldAbsoluteDate.getArbitraryEpoch(ComplexField.getInstance());
40 final FieldSpacecraftState<Complex> mockedState = mockState(expectedDate);
41
42 final Action action = recallLastOccurrence.eventOccurred(mockedState, null, true);
43
44 Assertions.assertEquals(expectedDate, recallLastOccurrence.getLastOccurrence());
45 Assertions.assertEquals(ACTION, action);
46 }
47
48 @Test
49 void testFinish() {
50
51 final TestHandler testHandler = new TestHandler();
52 final FieldRecallLastOccurrence<Complex> recallLastOccurrence = new FieldRecallLastOccurrence<>(testHandler);
53 final FieldAbsoluteDate<Complex> expectedDate = FieldAbsoluteDate.getArbitraryEpoch(ComplexField.getInstance());
54 final FieldSpacecraftState<Complex> mockedState = mockState(expectedDate);
55
56 recallLastOccurrence.finish(mockedState, null);
57
58 Assertions.assertTrue(testHandler.isFinished);
59 }
60
61 @Test
62 void testResetState() {
63
64 final TestHandler testHandler = new TestHandler();
65 final FieldRecallLastOccurrence<Complex> recallLastOccurrence = new FieldRecallLastOccurrence<>(testHandler);
66 final FieldSpacecraftState<Complex> mockedState = mockState(FieldAbsoluteDate.getArbitraryEpoch(ComplexField.getInstance()));
67
68 final FieldSpacecraftState<Complex> actualState = recallLastOccurrence.resetState(null, mockedState);
69
70 Assertions.assertEquals(mockedState, actualState);
71 Assertions.assertNull(recallLastOccurrence.getLastOccurrence());
72 }
73
74 @Test
75 void testInit() {
76
77 final TestHandler testHandler = new TestHandler();
78 final FieldRecallLastOccurrence<Complex> recallLastOccurrence = new FieldRecallLastOccurrence<>(testHandler);
79 final FieldSpacecraftState<Complex> mockedState = mockState(new FieldAbsoluteDate<>(ComplexField.getInstance(),
80 AbsoluteDate.FUTURE_INFINITY));
81
82 recallLastOccurrence.init(mockedState, FieldAbsoluteDate.getArbitraryEpoch(ComplexField.getInstance()), null);
83
84 Assertions.assertTrue(testHandler.isInitialized);
85 }
86
87 @SuppressWarnings("unchecked")
88 private FieldSpacecraftState<Complex> mockState(final FieldAbsoluteDate<Complex> date) {
89 final FieldSpacecraftState<Complex> mockedState = Mockito.mock(FieldSpacecraftState.class);
90 Mockito.when(mockedState.getDate()).thenReturn(date);
91 return mockedState;
92 }
93
94 private static class TestHandler implements FieldEventHandler<Complex> {
95
96 boolean isInitialized = false;
97 boolean isFinished = false;
98
99 @Override
100 public void init(FieldSpacecraftState<Complex> initialState, FieldAbsoluteDate<Complex> target, FieldEventDetector<Complex> detector) {
101 isInitialized = true;
102 }
103
104 @Override
105 public Action eventOccurred(FieldSpacecraftState<Complex> s, FieldEventDetector<Complex> detector, boolean increasing) {
106 return ACTION;
107 }
108
109 @Override
110 public void finish(FieldSpacecraftState<Complex> finalState, FieldEventDetector<Complex> detector) {
111 isFinished = true;
112 }
113 }
114
115 }