GuidanceManeuverUtil { public static String determineNextManeuverStreet(Context context, Maneuver maneuver, BaseGuidancePresenter baseGuidancePresenter) { String nextManeuverStreetValue = null; if (maneuver != null) { nextManeuverStreetValue = getNextStreet(context, maneuver); if (TextUtils.isEmpty(nextManeuverStreetValue)) { nextManeuverStreetValue = getNextToNext(context, maneuver, baseGuidancePresenter); } if (TextUtils.isEmpty(nextManeuverStreetValue)) { final String roadNumber = maneuver.getRoadNumber(); final String roadName = maneuver.getRoadName(); nextManeuverStreetValue = combineRoadNumberAndName(context, maneuver, roadNumber, roadName); } if (TextUtils.isEmpty(nextManeuverStreetValue)) { nextManeuverStreetValue = getSignPostExitText(maneuver); } } return nextManeuverStreetValue; } private  GuidanceManeuverUtil(); static int getIndexOfManeuver(Maneuver maneuver, List<Maneuver> maneuvers); static boolean maneuversEqual(Maneuver maneuverA, Maneuver maneuverB); static String getCurrentManeuverStreet(@NonNull Context context, @NonNull Maneuver maneuver); static String determineNextManeuverStreet(Context context, Maneuver maneuver,
            BaseGuidancePresenter baseGuidancePresenter);  }
@Test public void testNextManeuverStreetName() { final Maneuver maneuver = MockUtils.mockManeuver(); when(maneuver.getNextRoadName()).thenReturn(MockUtils.ROAD_NAME); when(maneuver.getNextRoadNumber()).thenReturn(MockUtils.ROAD_NUMBER); final Context context = mock(Context.class); doAnswer(invocation -> { return invocation.getArguments()[1] + " " + invocation.getArguments()[2]; }).when(context).getString(anyInt(), Matchers.<String>anyVararg()); String street = GuidanceManeuverUtil.determineNextManeuverStreet(context, maneuver, mock(GuidanceManeuverPresenter.class)); assertThat(street, is(MockUtils.ROAD_NUMBER + " " + MockUtils.ROAD_NAME)); }
@Test public void testNextManeuverStreetNameWhenSignPost() { final Maneuver maneuver = MockUtils.mockManeuver(); when(maneuver.getNextRoadName()).thenReturn(MockUtils.ROAD_NAME); when(maneuver.getNextRoadNumber()).thenReturn(MockUtils.ROAD_NUMBER); when(maneuver.getAction()).thenReturn(Maneuver.Action.LEAVE_HIGHWAY); Signpost signpost = mock(Signpost.class); when(signpost.getExitNumber()).thenReturn("52"); when(maneuver.getSignpost()).thenReturn(signpost); final Context context = mock(Context.class); doAnswer(invocation -> { return invocation.getArguments()[1] + " " + invocation.getArguments()[2]; }).when(context).getString(anyInt(), Matchers.<String>anyVararg()); String street = GuidanceManeuverUtil.determineNextManeuverStreet(context, maneuver, mock(GuidanceManeuverPresenter.class)); assertThat(street, is(MockUtils.ROAD_NUMBER + " " + MockUtils.ROAD_NAME)); }
@Test public void testSignPostStreet() { final String signPostExitText = "exitText"; final Maneuver maneuver = MockUtils.mockManeuver(); when(maneuver.getNextRoadName()).thenReturn(""); when(maneuver.getNextRoadNumber()).thenReturn(""); when(maneuver.getRoadName()).thenReturn(""); when(maneuver.getRoadNumber()).thenReturn(""); Signpost signpost = mock(Signpost.class); when(signpost.getExitText()).thenReturn(signPostExitText); when(maneuver.getSignpost()).thenReturn(signpost); final Context context = mock(Context.class); doAnswer(invocation -> { return invocation.getArguments()[1] + " " + invocation.getArguments()[2]; }).when(context).getString(anyInt(), Matchers.<String>anyVararg()); String street = GuidanceManeuverUtil.determineNextManeuverStreet(context, maneuver, mock(GuidanceManeuverPresenter.class)); assertThat(street, is(signPostExitText)); }
@Test public void testCurrentManeuverStreetName() { final Maneuver maneuver = MockUtils.mockManeuver(); when(maneuver.getNextRoadName()).thenReturn(""); when(maneuver.getNextRoadNumber()).thenReturn(""); final Context context = mock(Context.class); doAnswer(invocation -> { return invocation.getArguments()[1] + " " + invocation.getArguments()[2]; }).when(context).getString(anyInt(), Matchers.<String>anyVararg()); String street = GuidanceManeuverUtil.determineNextManeuverStreet(context, maneuver, mock(GuidanceManeuverPresenter.class)); assertThat(street, is(MockUtils.ROAD_NUMBER + " " + MockUtils.ROAD_NAME)); }