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.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.DisplayName;
21  import org.junit.jupiter.api.Test;
22  import org.mockito.Mockito;
23  import org.orekit.Utils;
24  import org.orekit.errors.OrekitIllegalArgumentException;
25  
26  class TimeStampedPairTest {
27      @Test
28      @DisplayName("test error thrown when using different dates")
29      void testErrorThrownWhenUsingDifferentDates() {
30          // Given
31          Utils.setDataRoot("regular-data");
32  
33          final TimeStamped value1 = Mockito.mock(TimeStamped.class);
34          final TimeStamped value2 = Mockito.mock(TimeStamped.class);
35  
36          Mockito.when(value1.getDate()).thenReturn(new AbsoluteDate());
37          Mockito.when(value2.getDate()).thenReturn(new AbsoluteDate().shiftedBy(1));
38  
39          // When & Then
40          Exception thrown = Assertions.assertThrows(OrekitIllegalArgumentException.class,
41                                                     () -> new TimeStampedPair<>(value1, value2));
42  
43          Assertions.assertEquals(
44                  "first date 2000-01-01T11:58:55.816Z does not match second date 2000-01-01T11:58:56.816Z",
45                  thrown.getMessage());
46      }
47  
48      @Test
49      @DisplayName("Test getters")
50      void testGetters() {
51          // Given
52          final TimeStamped value1 = Mockito.mock(TimeStamped.class);
53          final TimeStamped value2 = Mockito.mock(TimeStamped.class);
54  
55          final AbsoluteDate defaultDate = new AbsoluteDate();
56  
57          Mockito.when(value1.getDate()).thenReturn(defaultDate);
58          Mockito.when(value2.getDate()).thenReturn(defaultDate);
59  
60          // When
61          final TimeStampedPair<TimeStamped, TimeStamped> pair = new TimeStampedPair<>(value1, value2);
62  
63          // Then
64          Assertions.assertEquals(defaultDate, pair.getDate());
65          Assertions.assertEquals(value1, pair.getFirst());
66          Assertions.assertEquals(value2, pair.getSecond());
67      }
68  }