### Question:
RepositoryRequestFactory { public HttpUriRequest create(String url, DownloadOptions options) { try { if (options.isAuthenticationNeeded()) { return requestFactory.authenticatedGet(url, options.getUsername(), options.getPassword()); } else { return requestFactory.get(url); } } catch (Exception e) { throw new RuntimeException("Error while creating the http request", e); } }  HttpUriRequest create(String url, DownloadOptions options);  }### Answer:
@Test public void testCreateShouldReturnUnauthenticatedRequestWhenAuthenticationIsNeeded() throws MalformedURLException, URISyntaxException { String url = "url"; DownloadOptions options = new DownloadOptions(); HttpGet expected = mock(HttpGet.class); given(requestFactory.get(url)).willReturn(expected); HttpUriRequest result = underTest.create(url, options); assertThat(result).isEqualTo(expected); }
@Test(expected = RuntimeException.class) public void testCreateShouldThrowExceptionWhenRequestCannotBeCreated() throws MalformedURLException, URISyntaxException { String url = "url"; DownloadOptions options = new DownloadOptions(); given(requestFactory.get(url)).willThrow(MalformedURLException.class); underTest.create(url, options); }
@Test public void testCreateShouldReturnAuthenticatedRequestWhenAuthenticationIsNeeded() throws MalformedURLException, URISyntaxException { String url = "url"; String username = "username"; String password = "password"; DownloadOptions options = new DownloadOptions(); options.setUsername(username); options.setPassword(password); HttpGet expected = mock(HttpGet.class); given(requestFactory.authenticatedGet(url, username, password)).willReturn(expected); HttpUriRequest result = underTest.create(url, options); assertThat(result).isEqualTo(expected); }