66import java .io .FileInputStream ;
77import java .io .InputStream ;
88import java .io .InputStreamReader ;
9+ import java .lang .reflect .Method ;
910import java .util .ArrayList ;
1011import java .util .List ;
1112
@@ -72,9 +73,14 @@ public void testEncodeFromLatLong() {
7273 }
7374
7475 @ Test
75- public void testDegreesToIntegers () {
76+ public void testDegreesToIntegers () throws Exception {
77+ // The method to test is private, we use reflection to get it to avoid changing the visibility.
78+ OpenLocationCode olcClass = new OpenLocationCode (null );
79+ Method privateMethod = OpenLocationCode .class .getDeclaredMethod ("degreesToIntegers" , int .class , int .class );
80+ privateMethod .setAccessible (true );
81+
7682 for (TestData testData : testDataList ) {
77- long [] got = OpenLocationCode . degreesToIntegers ( testData .latitudeDegrees , testData .longitudeDegrees );
83+ long [] got = ( long []) privateMethod . invoke ( olcClass , testData .latitudeDegrees , testData .longitudeDegrees );
7884 Assert .assertEquals (
7985 String .format ("Latitude %f integer conversion is incorrect" , testData .latitudeDegrees ),
8086 testData .latitudeInteger ,
@@ -87,14 +93,20 @@ public void testDegreesToIntegers() {
8793 }
8894
8995 @ Test
90- public void testEncodeIntegers () {
96+ public void testEncodeIntegers () throws Exception {
97+ // The method to test is private, we use reflection to get it to avoid changing the visibility.
98+ OpenLocationCode olcClass = new OpenLocationCode (null );
99+ Method privateMethod = OpenLocationCode .class .getDeclaredMethod ("encodeIntegers" , int .class , int .class );
100+ privateMethod .setAccessible (true );
101+
91102 for (TestData testData : testDataList ) {
103+ String got = (String ) privateMethod .invoke (olcClass , testData .latitudeInteger , testData .longitudeInteger , testData .length );
92104 Assert .assertEquals (
93105 String .format (
94106 "Latitude %d, longitude %d and length %d were wrongly encoded." ,
95107 testData .latitudeInteger , testData .longitudeInteger , testData .length ),
96108 testData .code ,
97- OpenLocationCode . encodeIntegers ( testData . latitudeInteger , testData . longitudeInteger , testData . length ) );
109+ got );
98110 }
99111 }
100112}
0 commit comments