RouteUtil { public static Spannable getTrafficDelayed(final Context context, final Route route) { final SpannableStringBuilder builder = new SpannableStringBuilder(" "); if (!isTrafficAvailable(route)) { return builder; } final boolean isBlockedRoad = route.getTtaIncludingTraffic(WHOLE_ROUTE).isBlocked(); if (isBlockedRoad) { appendDrawable(context, builder, R.drawable.ic_warning, R.attr.colorAlert); appendText(context, builder, context.getString(R.string.msdkui_traffic_blocked), R.attr.colorAlert); return builder; } final long durationWithTraffic = route.getTtaIncludingTraffic(WHOLE_ROUTE) .getDuration(); final long durationWithoutTraffic = route.getTtaExcludingTraffic(WHOLE_ROUTE) .getDuration(); final long delayInSeconds = durationWithTraffic > durationWithoutTraffic ? durationWithTraffic - durationWithoutTraffic : 0; final long delayInMinutes = (long) (delayInSeconds / 60); if (delayInMinutes > 0) { appendDrawable(context, builder, R.drawable.ic_warning, R.attr.colorAlert); appendText(context, builder, context.getString(R.string.msdkui_incl_traffic_delay, TimeFormatterUtil.format(context, TimeUnit.MINUTES.toMillis(delayInMinutes))), R.attr.colorAlert); return builder; } else { appendText(context, builder, context.getString(R.string.msdkui_no_traffic_delays), R.attr.colorForegroundSecondary); } return builder; } private  RouteUtil(); static String getLongestRoadSegments(final Route route); static Spannable getTrafficDelayed(final Context context, final Route route); static String getArrivalTime(final Context context, final Route route, final boolean isTraffic); static String getRouteLength(final Context context, final Route route,
                                        final UnitSystem unitSystem); static Spannable getDetails(final Context context, final Route route,
                                       final UnitSystem unitSystem); static Spannable getTimeToArrive(final Context context, final Route route, final boolean isTraffic); static Integer getIcon(final Route route); static List<SectionModel> getSectionBar(final Context context, final Route route);  }
@Test public void testTrafficDelayed() { Context context = getApplicationContext(); Route route = new MockUtils.MockRouteBuilder().getRoute(); Spannable spannable = RouteUtil.getTrafficDelayed(context, route); assertThat(spannable.toString().trim(), equalTo(getContextWithTheme().getString(R.string.msdkui_no_traffic_delays))); route = new MockUtils.MockRouteBuilder().setBlockedRoad().getRoute(); spannable = RouteUtil.getTrafficDelayed(context, route); assertThat(spannable.toString().trim(), equalTo(getContextWithTheme().getString(R.string.msdkui_traffic_blocked))); int delayInMinutes = 10; route = new MockUtils.MockRouteBuilder().setTrafficPenaltyMinutes(10).getRoute(); spannable = RouteUtil.getTrafficDelayed(context, route); assertThat(spannable.toString().trim(), equalTo(getContextWithTheme().getString(R.string.msdkui_incl_traffic_delay, TimeFormatterUtil.format(getContextWithTheme(), TimeUnit.MINUTES.toMillis(delayInMinutes))))); route = new MockUtils.MockRouteBuilder().setArrivalTimeOption().getRoute(); spannable = RouteUtil.getTrafficDelayed(context, route); assertTrue(spannable.toString().trim().isEmpty()); }