1   /* Copyright 2013-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.rugged.errors;
18  
19  
20  import java.util.Locale;
21  
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  
25  public class RuggedExceptionTest {
26  
27      @Test
28      public void testTranslation() {
29          RuggedException re = new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy");
30          Assertions.assertFalse(re.getMessage(Locale.FRENCH).contains("parameter"));
31          Assertions.assertTrue(re.getMessage(Locale.FRENCH).contains("paramètre"));
32          Assertions.assertTrue(re.getMessage(Locale.FRENCH).contains("dummy"));
33          Assertions.assertTrue(re.getMessage(Locale.US).contains("parameter"));
34          Assertions.assertFalse(re.getMessage(Locale.US).contains("paramètre"));
35          Assertions.assertTrue(re.getMessage(Locale.US).contains("dummy"));
36          Assertions.assertEquals(re.getMessage(), re.getMessage(Locale.US));
37      }
38  
39      @Test
40      public void testParameters() {
41          RuggedException re = new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy");
42          Assertions.assertEquals(RuggedMessages.DUPLICATED_PARAMETER_NAME, re.getSpecifier());
43          Assertions.assertEquals("dummy", re.getParts()[0]);
44      }
45  
46      @Test
47      public void testNullSpecifier() {
48          RuggedException re = new RuggedException(null, (Object[]) null);
49          Assertions.assertEquals("", re.getMessage());
50      }
51  
52      @Test
53      public void testNullParts() {
54          RuggedException re1 = new RuggedException(RuggedMessages.NO_PARAMETERS_SELECTED, (Object[]) null);
55          Assertions.assertEquals(RuggedMessages.NO_PARAMETERS_SELECTED, re1.getSpecifier());
56          Assertions.assertEquals(0, re1.getParts().length);
57          RuggedException re2 = new RuggedException(new RuntimeException(),
58                                                    RuggedMessages.NO_PARAMETERS_SELECTED, (Object[]) null);
59          Assertions.assertEquals(RuggedMessages.NO_PARAMETERS_SELECTED, re2.getSpecifier());
60          Assertions.assertEquals(0, re2.getParts().length);
61      }
62  
63      @Test
64      public void testInternalError() {
65          RuggedException re = new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy");
66          RuntimeException rte = new RuggedInternalError(re);
67          Assertions.assertFalse(re.getLocalizedMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues"));
68          Assertions.assertTrue(rte.getLocalizedMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues"));
69          Assertions.assertTrue(rte.getMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues"));
70      }
71  
72      @Deprecated
73      @Test
74      public void testCoverage() {
75          RuggedExceptionWrapper rew = new RuggedExceptionWrapper(new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy"));
76          RuggedException re = rew.getException();
77          Assertions.assertEquals(RuggedMessages.DUPLICATED_PARAMETER_NAME, re.getSpecifier());
78          Assertions.assertEquals("dummy", re.getParts()[0]);
79      }
80  }