Task implements Serializable { public String getTitleForStep(Context context, Step step) { return step.getStepTitle() != 0 ? context.getString(step.getStepTitle()) : ""; } Task(String identifier); String getIdentifier(); String getTitleForStep(Context context, Step step); abstract Step getStepAfterStep(Step step, TaskResult result); abstract Step getStepBeforeStep(Step step, TaskResult result); abstract Step getStepWithIdentifier(String identifier); abstract TaskProgress getProgressOfCurrentStep(Step step, TaskResult result); abstract void validateParameters(); void onViewChange(ViewChangeType type, ViewTaskActivity activity, Step currentStep);  }
@Test public void testGetTitleForStep() throws Exception { Task task = new TaskImpl("id"); Context mockContext = Mockito.mock(Context.class); Mockito.when(mockContext.getString(R.string.app_name)).thenReturn("title"); Mockito.when(mockContext.getString(0)).thenReturn("title"); Step mockStepWithTitle = Mockito.mock(Step.class); Mockito.when(mockStepWithTitle.getStepTitle()).thenReturn(R.string.app_name); String title = task.getTitleForStep(mockContext, mockStepWithTitle); assertEquals("Gets title from context using step id", "title", title); Step mockStepWithoutTitle = Mockito.mock(Step.class); Mockito.when(mockStepWithoutTitle.getStepTitle()).thenReturn(0); String noTitle = task.getTitleForStep(mockContext, mockStepWithoutTitle); assertEquals("Gets empty string when no title id on step", "", noTitle); }