@SuppressWarnings("unchecked") public void testSearchHappyPath() throws IOException, URISyntaxException { // mock the POST and response RestResponse searchRestResponse = mock(RestResponse.class); when(restClient.doPost( eq(Const.USE_HTTPS), eq(HostName.PLAY), eq(Path.MUSIC_SEARCH), isA((Map.class)), isA(Map.class), (Map<String, String>) isNull(), isA(Map.class))) .thenReturn(searchRestResponse); String searchResultBody = "searchResultBody"; when(searchRestResponse.getBody()).thenReturn(searchResultBody); when(searchRestResponse.getStatusCode()).thenReturn(HttpStatus.SC_OK); SearchResponse searchResponse = mock(SearchResponse.class); when(gsonWrapper.fromJson(searchResultBody, SearchResponse.class)).thenReturn(searchResponse); SearchResults searchResults = mock(SearchResults.class); when(searchResponse.getResults()).thenReturn(searchResults); // do the call and compare results assertEquals(searchResults, playClient.search(query, playSession)); }
public void testSearchFailsDueToNullPlaySession() throws IOException, URISyntaxException { try { playClient.search(query, null); fail("should have thrown exception"); } catch (IllegalArgumentException e) { } }
public void testSearchFailsDueToEmptyQuery() throws IOException, URISyntaxException { try { playClient.search("", playSession); fail("should have thrown exception"); } catch (IllegalArgumentException e) { } }