FormService { public void downloadPublishedFormSections() throws IOException { FluentResponse formSectionsResponse = http() .context(context) .path(API_FORM_SECTIONS_PATH) .get(); if (formSectionsResponse.isSuccess()) { String formSectionJson = CharStreams.toString(new InputStreamReader(formSectionsResponse.getEntity().getContent())); saveFormSections(formSectionJson); loadFormSections(); } } @Inject  FormService(RapidFtrApplication context); void downloadPublishedFormSections(); List<FormSection> getFormSections(String formName); void setFormSections(List<FormSection> formSections); List<FormField> getHighlightedFields(String formName); List<FormField> getTitleFields(String formName); static final String FORM_SECTIONS_PREF; static final String API_FORM_SECTIONS_PATH; }
@Test public void shouldDownloadAndSaveFormSections() throws Exception { FluentRequest request = Mockito.mock(FluentRequest.class); PowerMockito.mockStatic(FluentRequest.class); when(FluentRequest.http()).thenReturn(request); when(request.context(any(RapidFtrApplication.class))).thenReturn(request); when(request.path(anyString())).thenReturn(request); when(request.get()).thenReturn(new FluentResponse(buildResponse())); when(sharedPreferences.getString(FormService.FORM_SECTIONS_PREF, null)).thenReturn(jsonResponse); formService.downloadPublishedFormSections(); verify(editor, times(1)).putString(eq(FormService.FORM_SECTIONS_PREF), eq(jsonResponse)); verify(editor, times(1)).commit(); }