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.params.ParameterizedTest;
22 import org.junit.jupiter.params.provider.EnumSource;
23 import org.junit.jupiter.params.provider.ValueSource;
24 import org.mockito.Mockito;
25 import org.orekit.propagation.SpacecraftState;
26 import org.orekit.propagation.events.EventDetector;
27
28 class CountingHandlerTest {
29
30 @ParameterizedTest
31 @ValueSource(booleans = {false, true})
32 void testEventOccurred(final boolean countAll) {
33
34 final CountingHandler handler = new TestHandler(countAll, Action.CONTINUE);
35 final SpacecraftState mockedState = Mockito.mock(SpacecraftState.class);
36 final EventDetector mockedDetector = Mockito.mock(EventDetector.class);
37 final int calls = 42;
38
39 for (int i = 0; i < calls; i++) {
40 handler.eventOccurred(mockedState, mockedDetector, true);
41 }
42
43 Assertions.assertEquals(countAll ? calls : 0, handler.getCount());
44 }
45
46 @ParameterizedTest
47 @EnumSource(Action.class)
48 void testEventOccurred(final Action expectedAction) {
49
50 final CountingHandler handler = new TestHandler(true, expectedAction);
51 final SpacecraftState mockedState = Mockito.mock(SpacecraftState.class);
52 final EventDetector mockedDetector = Mockito.mock(EventDetector.class);
53
54 final Action actualAction = handler.eventOccurred(mockedState, mockedDetector, true);
55
56 Assertions.assertEquals(expectedAction, actualAction);
57 }
58
59 private static class TestHandler extends CountingHandler {
60
61 private final boolean countAll;
62
63 TestHandler(final boolean countAll, final Action action) {
64 super(0, action);
65 this.countAll = countAll;
66 }
67
68 @Override
69 protected boolean doesCount(SpacecraftState state, EventDetector detector, boolean increasing) {
70 return countAll;
71 }
72 }
73
74 }