@Test public void saveProxy_modify() { when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32"))) .thenReturn(new Proxy("10.0.0.0/32", "")); final Proxy proxy = new Proxy("10.0.0.0/32", "some"); final Response response = subject.saveProxy(proxy); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), instanceOf(Proxy.class)); assertThat(((Proxy) response.getEntity()).getPrefix(), is("10.0.0.0/32")); verify(aclServiceDao).updateProxy(proxy); }
@Test public void saveProxy_create() { when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32"))) .thenThrow(EmptyResultDataAccessException.class); final Proxy proxy = new Proxy("10.0.0.0/32", "some"); final Response response = subject.saveProxy(proxy); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), instanceOf(Proxy.class)); assertThat(((Proxy) response.getEntity()).getPrefix(), is("10.0.0.0/32")); verify(aclServiceDao).createProxy(proxy); }