AcmeResource implements Serializable { public void rebind(Login login) { if (this.login != null) { throw new IllegalStateException("Resource is already bound to a login"); } this.login = Objects.requireNonNull(login, "login"); } protected  AcmeResource(Login login, URL location); void rebind(Login login); URL getLocation();  }
@Test(expected = IllegalStateException.class) public void testRebind() throws Exception { Login login = TestUtils.login(); URL location = new URL("http: AcmeResource resource = new DummyResource(login, location); assertThat(resource.getLogin(), is(login)); Login login2 = TestUtils.login(); resource.rebind(login2); }