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