public void testReturnsEmpty() { mockery.checking( new Expectations() { { allowing(geoCodeURL).get(); will(returnValue("")); } }); GeocodeInformation info = geo.getGeocodeInformation(); assertTrue(info.isEmpty()); }
public void testSimple() throws InterruptedException { final HttpResponse response = mockery.mock(HttpResponse.class); final StatusLine statusLine = mockery.mock(StatusLine.class); final HttpEntity httpEntity = mockery.mock(HttpEntity.class); mockery.checking( new Expectations() { { allowing(geoCodeURL).get(); will(returnValue("http://foo.com")); try { allowing(httpClient).execute(with(any(HttpUriRequest.class))); } catch (IOException e) { throw new RuntimeException(e); } will(returnValue(response)); allowing(response).getStatusLine(); will(returnValue(statusLine)); allowing(statusLine).getStatusCode(); will(returnValue(HttpStatus.SC_OK)); allowing(response).getEntity(); will(returnValue(httpEntity)); try { allowing(httpEntity).getContent(); } catch (IOException e) { throw new RuntimeException(e); } will(returnValue(new StringInputStream(testS))); allowing(httpEntity).getContentType(); will(returnValue(new BasicHeader("Content-Type", HTTP.DEFAULT_CONTENT_TYPE))); allowing(httpClient).releaseConnection(with(same(response))); } }); GeocodeInformation info = geo.getGeocodeInformation(); // Make sure we have all the correct properties for (GeocodeInformation.Property p : GeocodeInformation.getStrings2Properties().values()) { assertEquals( p.getValue() + " should be in " + info, props.get(p.getValue()), info.getProperty(p)); } }