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;
18  
19  import org.hamcrest.CoreMatchers;
20  import org.hamcrest.MatcherAssert;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.mockito.Mockito;
24  import org.orekit.propagation.SpacecraftState;
25  import org.orekit.propagation.events.handlers.EventHandler;
26  import org.orekit.time.AbsoluteDate;
27  
28  /**
29   * Unit tests for {@link NegateDetector}.
30   *
31   * @author Evan Ward
32   */
33  public class NegateDetectorTest {
34  
35      /**
36       * check {@link NegateDetector#init(SpacecraftState, AbsoluteDate)}.
37       */
38      @Test
39      public void testInit() {
40          //setup
41          EventDetector a = Mockito.mock(EventDetector.class);
42          @SuppressWarnings("unchecked")
43          EventHandler<EventDetector> c = Mockito.mock(EventHandler.class);
44          NegateDetector detector = new NegateDetector(a).withHandler(c);
45          AbsoluteDate t = AbsoluteDate.GPS_EPOCH;
46          SpacecraftState s = Mockito.mock(SpacecraftState.class);
47          Mockito.when(s.getDate()).thenReturn(t.shiftedBy(60.0));
48  
49          //action
50          detector.init(s, t);
51  
52          //verify
53          Mockito.verify(a).init(s, t);
54          Mockito.verify(c).init(s, t, detector);
55      }
56  
57      /**
58       * check g function is negated.
59       */
60      @Test
61      public void testG() {
62          //setup
63          EventDetector a = Mockito.mock(EventDetector.class);
64          NegateDetector detector = new NegateDetector(a);
65          SpacecraftState s = Mockito.mock(SpacecraftState.class);
66  
67          // verify + to -
68          Mockito.when(a.g(s)).thenReturn(1.0);
69          MatcherAssert.assertThat(detector.g(s), CoreMatchers.is(-1.0));
70          // verify - to +
71          Mockito.when(a.g(s)).thenReturn(-1.0);
72          MatcherAssert.assertThat(detector.g(s), CoreMatchers.is(1.0));
73      }
74  
75      /** Check a with___ method. */
76      @Test
77      public void testCreate() {
78          //setup
79          EventDetector a = Mockito.mock(EventDetector.class);
80          NegateDetector detector = new NegateDetector(a);
81  
82          // action
83          NegateDetector actual = detector.withMaxCheck(100);
84  
85          //verify
86          MatcherAssert.assertThat(actual.getMaxCheckInterval(), CoreMatchers.is(100.0));
87          Assert.assertTrue(actual.getOriginal() == a);
88      }
89  }