1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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          // this test is here only for test coverage ...
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          // Create detector
45          final Detector detector = new Detector();
46          Assert.assertFalse(detector.isInitialized());
47  
48          // Create handler
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