GeoWidgetUtils { public static double[] getLocationParamsFromStringAnswer(String answer) { double[] gp = new double[4]; if (answer != null && !answer.isEmpty()) { String[] sa = answer.split(" "); try { gp[0] = Double.valueOf(sa[0]); gp[1] = Double.valueOf(sa[1]); gp[2] = Double.valueOf(sa[2]); gp[3] = Double.valueOf(sa[3]); } catch (Exception | Error e) { Timber.w(e); } } return gp; } private  GeoWidgetUtils(); static String convertCoordinatesIntoDegreeFormat(Context context, double coordinate, String type); static double[] getLocationParamsFromStringAnswer(String answer); static String truncateDouble(String s);  }
@Test public void getLocationParamsFromStringAnswerTest() { double[] gp = GeoWidgetUtils.getLocationParamsFromStringAnswer("37.45153333333334 -122.15539166666667 0.0 20.0"); assertEquals(37.45153333333334, gp[0]); assertEquals(-122.15539166666667, gp[1]); assertEquals(0.0, gp[2]); assertEquals(20.0, gp[3]); gp = GeoWidgetUtils.getLocationParamsFromStringAnswer("37.45153333333334"); assertEquals(37.45153333333334, gp[0]); assertEquals(0.0, gp[1]); assertEquals(0.0, gp[2]); assertEquals(0.0, gp[3]); gp = GeoWidgetUtils.getLocationParamsFromStringAnswer(""); assertEquals(0.0, gp[0]); assertEquals(0.0, gp[1]); assertEquals(0.0, gp[2]); assertEquals(0.0, gp[3]); gp = GeoWidgetUtils.getLocationParamsFromStringAnswer(null); assertEquals(0.0, gp[0]); assertEquals(0.0, gp[1]); assertEquals(0.0, gp[2]); assertEquals(0.0, gp[3]); gp = GeoWidgetUtils.getLocationParamsFromStringAnswer("37.45153333333334 -122.15539166666667 0.0 qwerty"); assertEquals(37.45153333333334, gp[0]); assertEquals(-122.15539166666667, gp[1]); assertEquals(0.0, gp[2]); assertEquals(0.0, gp[3]); }