1   /* Copyright 2022-2025 Romain Serra
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.forces.gravity;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.mockito.Mockito;
25  import org.orekit.bodies.CelestialBody;
26  import org.orekit.frames.Frame;
27  import org.orekit.propagation.FieldSpacecraftState;
28  import org.orekit.propagation.SpacecraftState;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.FieldAbsoluteDate;
31  import org.orekit.utils.PVCoordinates;
32  import org.orekit.utils.TimeStampedPVCoordinates;
33  
34  class AbstractBodyAttractionTest {
35  
36      @Test
37      void testDependsOnPositionOnly() {
38          // GIVEN
39          final AbstractBodyAttraction mockedAttraction = Mockito.mock(AbstractBodyAttraction.class);
40          Mockito.when(mockedAttraction.dependsOnPositionOnly()).thenCallRealMethod();
41          // WHEN
42          final boolean actualDependsOnPositionOnly = mockedAttraction.dependsOnPositionOnly();
43          // THEN
44          Assertions.assertTrue(actualDependsOnPositionOnly);
45      }
46  
47      @Test
48      void TestGetBodyName() {
49          // GIVEN
50          final String expectedName = "Moon";
51          final CelestialBody mockedBody = Mockito.mock(CelestialBody.class);
52          Mockito.when(mockedBody.getName()).thenReturn(expectedName);
53          final TestBodyAttraction testBodyAttraction = new TestBodyAttraction(mockedBody);
54          // WHEN
55          final String actualName = testBodyAttraction.getBodyName();
56          // THEN
57          Assertions.assertEquals(expectedName, actualName);
58      }
59  
60      @Test
61      void testGetPV() {
62          // GIVEN
63          final CelestialBody mockedBody = Mockito.mock(CelestialBody.class);
64          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
65          final Frame mockedFrame = Mockito.mock(Frame.class);
66          final TimeStampedPVCoordinates expectedPV = Mockito.mock(TimeStampedPVCoordinates.class);
67          Mockito.when(mockedBody.getPVCoordinates(date, mockedFrame)).thenReturn(expectedPV);
68          final TestBodyAttraction testBodyAttraction = new TestBodyAttraction(mockedBody);
69          // WHEN
70          final PVCoordinates actualPV = testBodyAttraction.getBodyPVCoordinates(date, mockedFrame);
71          // THEN
72          Assertions.assertEquals(expectedPV, actualPV);
73      }
74  
75      @Test
76      void testGetPosition() {
77          // GIVEN
78          final CelestialBody mockedBody = Mockito.mock(CelestialBody.class);
79          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
80          final Frame mockedFrame = Mockito.mock(Frame.class);
81          final Vector3D expectedPosition = new Vector3D(1, 2, 3);
82          Mockito.when(mockedBody.getPosition(date, mockedFrame)).thenReturn(expectedPosition);
83          final TestBodyAttraction testBodyAttraction = new TestBodyAttraction(mockedBody);
84          // WHEN
85          final Vector3D actualPosition = testBodyAttraction.getBodyPosition(date, mockedFrame);
86          // THEN
87          Assertions.assertEquals(expectedPosition, actualPosition);
88      }
89  
90      @Test
91      @SuppressWarnings("unchecked")
92      void testGetFieldPosition() {
93          // GIVEN
94          final CelestialBody mockedBody = Mockito.mock(CelestialBody.class);
95          final FieldAbsoluteDate<?> mockedDate = Mockito.mock(FieldAbsoluteDate.class);
96          final Frame mockedFrame = Mockito.mock(Frame.class);
97          final FieldVector3D expectedPosition = Mockito.mock(FieldVector3D.class);
98          Mockito.when(mockedBody.getPosition(mockedDate, mockedFrame)).thenReturn(expectedPosition);
99          final TestBodyAttraction testBodyAttraction = new TestBodyAttraction(mockedBody);
100         // WHEN
101         final FieldVector3D<?> actualPosition = testBodyAttraction.getBodyPosition(mockedDate, mockedFrame);
102         // THEN
103         Assertions.assertEquals(expectedPosition, actualPosition);
104     }
105 
106     private static class TestBodyAttraction extends AbstractBodyAttraction {
107 
108         protected TestBodyAttraction(CelestialBody body) {
109             super(body, body.getName(), body.getGM());
110         }
111 
112         @Override
113         public Vector3D acceleration(SpacecraftState s, double[] parameters) {
114             return null;
115         }
116 
117         @Override
118         public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters) {
119             return null;
120         }
121     }
122 
123 }