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.ode.events.Action;
20 import org.junit.jupiter.api.Assertions;
21 import org.junit.jupiter.api.Test;
22 import org.mockito.Mockito;
23 import org.orekit.propagation.SpacecraftState;
24 import org.orekit.propagation.events.EventDetectionSettings;
25 import org.orekit.propagation.events.EventDetector;
26 import org.orekit.time.AbsoluteDate;
27
28 public class EventHandlerTest {
29
30 @Test
31 public void testEnums() {
32
33
34 Assertions.assertEquals(5, Action.values().length);
35 Assertions.assertSame(Action.STOP, Action.valueOf("STOP"));
36 Assertions.assertSame(Action.RESET_STATE, Action.valueOf("RESET_STATE"));
37 Assertions.assertSame(Action.RESET_DERIVATIVES, Action.valueOf("RESET_DERIVATIVES"));
38 Assertions.assertSame(Action.RESET_EVENTS, Action.valueOf("RESET_EVENTS"));
39 Assertions.assertSame(Action.CONTINUE, Action.valueOf("CONTINUE"));
40
41 }
42
43 @Test
44 public void testIssue721() {
45
46
47 final Detector detector = new Detector();
48 Assertions.assertFalse(detector.isInitialized());
49
50
51 final Handler handler = new Handler();
52 handler.init(null, null, detector);
53 Assertions.assertTrue(detector.isInitialized());
54
55 }
56
57 @Test
58 void testFinish() {
59
60 final Handler handler = new Handler();
61
62 Assertions.assertDoesNotThrow(() -> handler.finish(Mockito.mock(SpacecraftState.class),
63 Mockito.mock(EventDetector.class)));
64 }
65
66 private static class Detector implements EventDetector {
67
68 private boolean initialized;
69
70 public Detector() {
71 this.initialized = false;
72 }
73
74 public boolean isInitialized() {
75 return initialized;
76 }
77
78 @Override
79 public void init(SpacecraftState s0, AbsoluteDate t) {
80 initialized = true;
81 }
82
83 @Override
84 public double g(SpacecraftState s) {
85 return 0;
86 }
87
88 @Override
89 public EventDetectionSettings getDetectionSettings() {
90 return new EventDetectionSettings(0, 0, 0);
91 }
92
93 @Override
94 public EventHandler getHandler() {
95 return new Handler();
96 }
97 }
98
99 private static class Handler implements EventHandler {
100
101 @Override
102 public void init(SpacecraftState initialState, AbsoluteDate target, EventDetector detector) {
103 detector.init(initialState, target);
104 }
105
106 @Override
107 public Action eventOccurred(SpacecraftState s, EventDetector detector, boolean increasing) {
108 return Action.CONTINUE;
109 }
110
111 }
112 }
113