<NME> DistanceParserTest.java
<BEF> package cgeo.geocaching.location;

import org.junit.Test;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.offset;


    private static final double MM = 1e-6; // 1mm, in kilometers
    private static final double MM = 1e-6; // 1mm, in kilometers

    @Test
    public void testFormats() {
        assertThat((double) DistanceParser.parseDistance("1200 m", true)).isEqualTo(1.2, offset(MM));
        assertThat((double) DistanceParser.parseDistance("1.2 km", true)).isEqualTo(1.2, offset(MM));
        assertThat((double) DistanceParser.parseDistance("1200 ft", true)).isEqualTo(0.36576, offset(MM));
        assertThat((double) DistanceParser.parseDistance("1200 yd", true)).isEqualTo(1.09728, offset(MM));
        assertThat((double) DistanceParser.parseDistance("1.2 mi", true)).isEqualTo(1.9312128, offset(MM));
    }

    @Test
    public void testImplicit() {
        assertThat((double) DistanceParser.parseDistance("1200", true)).isEqualTo(1.2, offset(MM));
        assertThat((double) DistanceParser.parseDistance("1200", false)).isEqualTo(0.36576, offset(MM));
    }

    @Test
    public void testComma() {
        assertThat((double) DistanceParser.parseDistance("1,2km", true)).isEqualTo(1.2, offset(MM));
    }

    @Test
    public void testFeet() {
        assertThat((double) DistanceParser.parseDistance("1200 FT", false)).isEqualTo(0.36576, offset(MM));
    }

}

<MSG> fix distance parsing in different locales (#7167)

fix distance parsing in different locales

Fixes #6376

* DistanceParser: fix code style and reformat code
* improve code according to review feedback
* add and use parseDistance(String, DistanceUnit) method
* GCConstants: update search distance regexp
* DistanceParser: remove parseDistance(String, boolean)
* creat parseUnit method and used it together with new parseDistance method.

<DFF> @@ -2,6 +2,7 @@ package cgeo.geocaching.location;
 
 import org.junit.Test;
 
+import static org.assertj.core.api.Assertions.fail;
 import static org.assertj.core.api.Java6Assertions.assertThat;
 import static org.assertj.core.api.Assertions.offset;
 
@@ -10,28 +11,85 @@ public class DistanceParserTest {
     private static final double MM = 1e-6; // 1mm, in kilometers
 
     @Test
-    public void testFormats() {
-        assertThat((double) DistanceParser.parseDistance("1200 m", true)).isEqualTo(1.2, offset(MM));
-        assertThat((double) DistanceParser.parseDistance("1.2 km", true)).isEqualTo(1.2, offset(MM));
-        assertThat((double) DistanceParser.parseDistance("1200 ft", true)).isEqualTo(0.36576, offset(MM));
-        assertThat((double) DistanceParser.parseDistance("1200 yd", true)).isEqualTo(1.09728, offset(MM));
-        assertThat((double) DistanceParser.parseDistance("1.2 mi", true)).isEqualTo(1.9312128, offset(MM));
+    public void testCanConvertFromKm() {
+        assertThat((double) DistanceParser.convertDistance(1.2f, DistanceParser.DistanceUnit.KM)).isEqualTo(1.2, offset(MM));
     }
 
     @Test
-    public void testImplicit() {
-        assertThat((double) DistanceParser.parseDistance("1200", true)).isEqualTo(1.2, offset(MM));
-        assertThat((double) DistanceParser.parseDistance("1200", false)).isEqualTo(0.36576, offset(MM));
+    public void testCanConvertFromM() {
+        assertThat((double) DistanceParser.convertDistance(1200, DistanceParser.DistanceUnit.M)).isEqualTo(1.2, offset(MM));
     }
 
     @Test
-    public void testComma() {
-        assertThat((double) DistanceParser.parseDistance("1,2km", true)).isEqualTo(1.2, offset(MM));
+    public void testCanConvertFromFt() {
+        assertThat((double) DistanceParser.convertDistance(1200, DistanceParser.DistanceUnit.FT)).isEqualTo(0.36576, offset(MM));
     }
 
     @Test
-    public void testFeet() {
-        assertThat((double) DistanceParser.parseDistance("1200 FT", false)).isEqualTo(0.36576, offset(MM));
+    public void testCanConvertFromMi() {
+        assertThat((double) DistanceParser.convertDistance(1.2f, DistanceParser.DistanceUnit.MI)).isEqualTo(1.9312128, offset(MM));
+    }
+
+    @Test
+    public void testCanParseWithDot() {
+        assertThat((double) DistanceParser.parseDistance("1.2", DistanceParser.DistanceUnit.MI)).isEqualTo(1.9312128, offset(MM));
+    }
+
+    @Test
+    public void testCanParseWithComma() {
+        assertThat((double) DistanceParser.parseDistance("1,2", DistanceParser.DistanceUnit.MI)).isEqualTo(1.9312128, offset(MM));
+    }
+
+    @Test
+    public void testCanParseUnitKm() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("km")).isEqualTo(DistanceParser.DistanceUnit.KM);
+    }
+
+    @Test
+    public void testCanParseUnitMi() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("mi")).isEqualTo(DistanceParser.DistanceUnit.MI);
+    }
+
+    @Test
+    public void testCanParseUnitYd() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("yd")).isEqualTo(DistanceParser.DistanceUnit.YD);
+    }
+
+    @Test
+    public void testCanParseUnitM() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("m")).isEqualTo(DistanceParser.DistanceUnit.M);
+    }
+
+    @Test
+    public void testCanParseUnitFt() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("ft")).isEqualTo(DistanceParser.DistanceUnit.FT);
+    }
+
+    @Test
+    public void testCanParseCaseSensetiveUnit() {
+        assertThat(DistanceParser.DistanceUnit.parseUnit("yD")).isEqualTo(DistanceParser.DistanceUnit.YD);
+    }
+
+    @Test
+    public void testCannotParseEmptyUnit() {
+        try {
+            DistanceParser.DistanceUnit.parseUnit("");
+            fail("No failure");
+        }
+        catch (final NumberFormatException e) {
+            //Expected
+        }
+    }
+
+    @Test
+    public void testCannotParseBadUnit() {
+        try {
+            DistanceParser.DistanceUnit.parseUnit("custom");
+            fail("No failure");
+        }
+        catch (final NumberFormatException e) {
+            //Expected
+        }
     }
 
 }

fix distance parsing in different locales (#7167)