From a1f78c0c0b5b07fb87dc1392a36871369ff6fa69 Mon Sep 17 00:00:00 2001
From: gprat <guylaine.prat@csgroup.eu>
Date: Wed, 15 Jun 2022 11:02:59 +0200
Subject: [PATCH] Changed exception messages to avoid hard-coded string

Fixes #391
---
 src/main/java/org/orekit/rugged/api/Rugged.java        | 10 ++++------
 .../java/org/orekit/rugged/errors/RuggedMessages.java  |  4 +++-
 .../rugged/refraction/AtmosphericRefraction.java       |  5 ++---
 .../assets/org/orekit/rugged/RuggedMessages_da.utf8    |  7 +++++--
 .../assets/org/orekit/rugged/RuggedMessages_de.utf8    |  7 +++++--
 .../assets/org/orekit/rugged/RuggedMessages_en.utf8    |  7 +++++--
 .../assets/org/orekit/rugged/RuggedMessages_es.utf8    |  6 ++++--
 .../assets/org/orekit/rugged/RuggedMessages_fr.utf8    |  7 +++++--
 .../assets/org/orekit/rugged/RuggedMessages_gl.utf8    |  7 +++++--
 .../assets/org/orekit/rugged/RuggedMessages_it.utf8    |  9 ++++++---
 .../assets/org/orekit/rugged/RuggedMessages_no.utf8    |  8 ++++++--
 .../assets/org/orekit/rugged/RuggedMessages_ro.utf8    |  8 ++++++--
 .../org/orekit/rugged/errors/RuggedMessagesTest.java   |  2 +-
 .../rugged/refraction/AtmosphericRefractionTest.java   |  8 ++++----
 14 files changed, 61 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java
index 0a283fc5..de131078 100644
--- a/src/main/java/org/orekit/rugged/api/Rugged.java
+++ b/src/main/java/org/orekit/rugged/api/Rugged.java
@@ -729,8 +729,7 @@ public class Rugged {
             DumpManager.endNicely();
             
             // Impossible to find the sensor pixel in the given range lines (without atmosphere)
-            final String info = "in given range lines (with atmospheric refraction) between lines" + minLine + " and " + maxLine;
-            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, info);
+            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, minLine, maxLine);
         }
 
         // set up the starting point of the fixed point method
@@ -820,13 +819,12 @@ public class Rugged {
                         
                         if (sensorPixelGrid[uIndex][vIndex] == null) {
                             // Impossible to find the sensor pixel in the given range lines
-                            final String info = "in given range lines (with atmospheric refraction) between lines" + minLine + " and " + maxLine;
-                            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, info);
+                            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, minLine, maxLine);
                         } else {
                             // Impossible to find the sensor pixel
                             final double invLocationMargin = atmosphericRefraction.getComputationParameters().getInverseLocMargin();
-                            final String info = ": pixel = " + sensorPixelGrid[uIndex][vIndex].getPixelNumber() + " outside interval [ " + (-invLocationMargin) + " , " + (invLocationMargin + sensor.getNbPixels() - 1) + " [ (with atmospheric refraction margin = " + invLocationMargin + ")";
-                            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, info);
+                            throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE, sensorPixelGrid[uIndex][vIndex].getPixelNumber(),
+                                                      (-invLocationMargin), (invLocationMargin + sensor.getNbPixels() - 1), invLocationMargin);
                         }
                     }
 
diff --git a/src/main/java/org/orekit/rugged/errors/RuggedMessages.java b/src/main/java/org/orekit/rugged/errors/RuggedMessages.java
index 190decac..f6b6f3bc 100644
--- a/src/main/java/org/orekit/rugged/errors/RuggedMessages.java
+++ b/src/main/java/org/orekit/rugged/errors/RuggedMessages.java
@@ -85,7 +85,9 @@ public enum RuggedMessages implements Localizable {
     NO_LAYER_DATA("no atmospheric layer data at altitude {0} (lowest altitude: {1})"),
     INVALID_STEP("step {0} is not valid : {1}"),
     INVALID_RANGE_FOR_LINES("range between min line {0} and max line {1} is invalid {2}"),
-    SENSOR_PIXEL_NOT_FOUND("impossible to find sensor pixel {0}");
+    SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES("impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}"),
+    SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE("impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})");
+
 
     // CHECKSTYLE: resume JavadocVariable check
 
diff --git a/src/main/java/org/orekit/rugged/refraction/AtmosphericRefraction.java b/src/main/java/org/orekit/rugged/refraction/AtmosphericRefraction.java
index 8e5639a3..65e3cae3 100644
--- a/src/main/java/org/orekit/rugged/refraction/AtmosphericRefraction.java
+++ b/src/main/java/org/orekit/rugged/refraction/AtmosphericRefraction.java
@@ -186,9 +186,8 @@ public abstract class AtmosphericRefraction {
 
                 } else {
                     // Impossible to find the sensor pixel in the given range lines
-                    final String info = "in given range lines (with atmospheric refraction) between lines" + 
-                                         atmosphericParams.getMinLineSensor() + " and " + atmosphericParams.getMaxLineSensor();
-                    throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, info);
+                    throw new RuggedException(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, 
+                                              atmosphericParams.getMinLineSensor(), atmosphericParams.getMaxLineSensor());
                 }
             }
         }
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_da.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_da.utf8
index a7c75c85..ecb9bd7e 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_da.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_da.utf8
@@ -97,5 +97,8 @@ INVALID_STEP = skridt {0} er ikke gyldigt : {1}
 # range between min line {0} and max line {1} too small {2}
 INVALID_RANGE_FOR_LINES = interval mellem minimumslinje {0} og maksimumslinje {1} for lille {2}
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_de.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_de.utf8
index a8b2fb56..9cda208b 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_de.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_de.utf8
@@ -97,5 +97,8 @@ INVALID_STEP = <MISSING TRANSLATION>
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = <MISSING TRANSLATION>
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_en.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_en.utf8
index 9e0acd4f..97b94dfc 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_en.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_en.utf8
@@ -97,5 +97,8 @@ INVALID_STEP = step {0} is not valid : {1}
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = range between min line {0} and max line {1} is invalid {2}
 
-# Impossible to find sensor pixel {0}
-SENSOR_PIXEL_NOT_FOUND = impossible to find sensor pixel {0}
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_es.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_es.utf8
index 96a452f2..b29c953a 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_es.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_es.utf8
@@ -97,6 +97,8 @@ INVALID_STEP = <MISSING TRANSLATION>
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = <MISSING TRANSLATION>
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
 
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_fr.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_fr.utf8
index 410304d0..7c9f324e 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_fr.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_fr.utf8
@@ -97,5 +97,8 @@ INVALID_STEP = le pas {0} n''est pas valable : {1}
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = l''écart entre la ligne min {0} et la ligne max {1} est non valide {2}
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = impossible de trouver le pixel senseur {0}
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = impossible de trouver le pixel senseur dans l''intervalle de lignes (avec réfraction atmosphérique) entre les lignes {0} et {1}
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = impossible de trouver le pixel senseur: pixel {0} en dehors de l''intervalle  [ {1} , {2} [ (avec la marge pour la réfraction atmosphérique = {3})
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_gl.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_gl.utf8
index 891edfa8..a459e9b0 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_gl.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_gl.utf8
@@ -97,5 +97,8 @@ INVALID_STEP = <MISSING TRANSLATION>
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = <MISSING TRANSLATION>
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
\ No newline at end of file
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_it.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_it.utf8
index 19ee2263..7d55d0fa 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_it.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_it.utf8
@@ -95,7 +95,10 @@ NO_LAYER_DATA = nessun dato atmosferico all''altitudine {0} (altitudine più bas
 INVALID_STEP = Step {0} non valido: {1}
 
 # range between min line {0} and max line {1} too small {2}
- INVALID_RANGE_FOR_LINES = Scarto fra la linea min {0} e la linea max {1} troppo piccolo {2}
+INVALID_RANGE_FOR_LINES = Scarto fra la linea min {0} e la linea max {1} troppo piccolo {2}
 
- # Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
\ No newline at end of file
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_no.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_no.utf8
index 70220984..e8bd4039 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_no.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_no.utf8
@@ -97,5 +97,9 @@ INVALID_STEP = steget {0} er ikke gyldig: {1}
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = avstanden mellom min linje {0} og max linje {1} er ugyldig {2}
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
+
diff --git a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_ro.utf8 b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_ro.utf8
index ce0190cd..b77290b0 100644
--- a/src/main/resources/assets/org/orekit/rugged/RuggedMessages_ro.utf8
+++ b/src/main/resources/assets/org/orekit/rugged/RuggedMessages_ro.utf8
@@ -97,5 +97,9 @@ INVALID_STEP = <MISSING TRANSLATION>
 # range between min line {0} and max line {1} is invalid {2}
 INVALID_RANGE_FOR_LINES = <MISSING TRANSLATION>
 
-# Impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
-SENSOR_PIXEL_NOT_FOUND = <MISSING TRANSLATION>
+# impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}
+SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES = <MISSING TRANSLATION>
+
+# impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})
+SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE = <MISSING TRANSLATION>
+
diff --git a/src/test/java/org/orekit/rugged/errors/RuggedMessagesTest.java b/src/test/java/org/orekit/rugged/errors/RuggedMessagesTest.java
index b3366efd..d70b430c 100644
--- a/src/test/java/org/orekit/rugged/errors/RuggedMessagesTest.java
+++ b/src/test/java/org/orekit/rugged/errors/RuggedMessagesTest.java
@@ -30,7 +30,7 @@ public class RuggedMessagesTest {
     private final String[] LANGUAGES_LIST = { "da", "de", "en", "es", "fr", "gl", "it", "no", "ro" } ;
     @Test
     public void testMessageNumber() {
-        Assert.assertEquals(34, RuggedMessages.values().length);
+        Assert.assertEquals(35, RuggedMessages.values().length);
     }
 
     @Test
diff --git a/src/test/java/org/orekit/rugged/refraction/AtmosphericRefractionTest.java b/src/test/java/org/orekit/rugged/refraction/AtmosphericRefractionTest.java
index a5fa46c9..5a270b7a 100644
--- a/src/test/java/org/orekit/rugged/refraction/AtmosphericRefractionTest.java
+++ b/src/test/java/org/orekit/rugged/refraction/AtmosphericRefractionTest.java
@@ -135,7 +135,7 @@ public class AtmosphericRefractionTest {
             ruggedWith.inverseLocation(sensorName, dummyGP, minLine, maxLine);
             Assert.fail("an exeption should have been thrown");
         } catch (RuggedException re) {
-            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, re.getSpecifier());
+            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, re.getSpecifier());
         }
 
         try {
@@ -144,7 +144,7 @@ public class AtmosphericRefractionTest {
                                        210, maxLine);
             Assert.fail("an exeption should have been thrown");
         } catch (RuggedException re) {
-            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, re.getSpecifier());
+            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, re.getSpecifier());
         }
 
         try {
@@ -153,7 +153,7 @@ public class AtmosphericRefractionTest {
                                        minLine, 190);
             Assert.fail("an exeption should have been thrown");
         } catch (RuggedException re) {
-            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND, re.getSpecifier());
+            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES, re.getSpecifier());
         }
 
     }
@@ -298,7 +298,7 @@ public class AtmosphericRefractionTest {
             Assert.fail("An exception should have been thrown");
 
         } catch (RuggedException re) {
-            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND,re.getSpecifier());
+            Assert.assertEquals(RuggedMessages.SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE,re.getSpecifier());
         }
 
         // Check the default margin is equal to the used one
-- 
GitLab