1   /* Copyright 2002-2025 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.time;
18  
19  import org.hipparchus.Field;
20  import org.hipparchus.util.Binary64;
21  import org.hipparchus.util.Binary64Field;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.DisplayName;
24  import org.junit.jupiter.api.Test;
25  import org.mockito.Mockito;
26  import org.orekit.Utils;
27  import org.orekit.errors.OrekitIllegalArgumentException;
28  
29  class FieldTimeStampedPairTest {
30      final Field<Binary64> field = Binary64Field.getInstance();
31  
32      @Test
33      @DisplayName("test error thrown when using different dates")
34      void testErrorThrownWhenUsingDifferentDates() {
35          // Given
36          Utils.setDataRoot("regular-data");
37  
38          @SuppressWarnings("unchecked")
39          final FieldTimeStamped<Binary64> value1 = Mockito.mock(FieldTimeStamped.class);
40          @SuppressWarnings("unchecked")
41          final FieldTimeStamped<Binary64> value2 = Mockito.mock(FieldTimeStamped.class);
42  
43          final FieldAbsoluteDate<Binary64> defaultDate = new FieldAbsoluteDate<>(field, new AbsoluteDate());
44  
45          Mockito.when(value1.getDate()).thenReturn(defaultDate);
46          Mockito.when(value2.getDate()).thenReturn(defaultDate.shiftedBy(1));
47  
48          // When & Then
49          Exception thrown = Assertions.assertThrows(OrekitIllegalArgumentException.class,
50                                                     () -> new FieldTimeStampedPair<>(value1, value2));
51  
52          Assertions.assertEquals(
53                  "first date 2000-01-01T11:58:55.816Z does not match second date 2000-01-01T11:58:56.816Z",
54                  thrown.getMessage());
55      }
56  
57      @Test
58      @DisplayName("Test getters")
59      void testGetters() {
60          // Given
61          @SuppressWarnings("unchecked")
62          final FieldTimeStamped<Binary64> value1 = Mockito.mock(FieldTimeStamped.class);
63          @SuppressWarnings("unchecked")
64          final FieldTimeStamped<Binary64> value2 = Mockito.mock(FieldTimeStamped.class);
65  
66          final FieldAbsoluteDate<Binary64> defaultDate = new FieldAbsoluteDate<>(field, new AbsoluteDate());
67  
68          Mockito.when(value1.getDate()).thenReturn(defaultDate);
69          Mockito.when(value2.getDate()).thenReturn(defaultDate);
70  
71          // When
72          final FieldTimeStampedPair<FieldTimeStamped<Binary64>, FieldTimeStamped<Binary64>, Binary64> pair =
73                  new FieldTimeStampedPair<>(value1, value2);
74  
75          // Then
76          Assertions.assertEquals(defaultDate, pair.getDate());
77          Assertions.assertEquals(value1, pair.getFirst());
78          Assertions.assertEquals(value2, pair.getSecond());
79      }
80  }