### Question:
RegistrationManager { public boolean isRegistered() { return registrationLocation.isPresent(); } RegistrationManager(CoapServer server, URI registrationUri, ScheduledExecutorService scheduledExecutor,
            Duration minRetryDelay, Duration maxRetryDelay);  RegistrationManager(CoapServer server, URI registrationUri, ScheduledExecutorService scheduledExecutor); void register(); void removeRegistration(); boolean isRegistered();  }### Answer:
@Test public void update() throws Exception { RegistrationManager reg = registered(); trnsport.when(newCoapPacket(2).post().uriPath("/stub/0001")) .then(newCoapPacket(2).ack(Code.C204_CHANGED).maxAge(101)); runScheduledTask(); assertTrue(reg.isRegistered()); verifyScheduledInSec(71L); }
@Test public void update_failedFromServer_immediately_reRegister() throws Exception { RegistrationManager reg = registered(); trnsport.when(newCoapPacket(2).post().uriPath("/stub/0001")) .then(newCoapPacket(2).ack(Code.C404_NOT_FOUND)); trnsport.when(newCoapPacket(3).post().uriPath("/rd").uriQuery("ep=stub-device-01&lt=100").contFormat(CT_APPLICATION_LINK__FORMAT)) .then(newCoapPacket(3).ack(Code.C201_CREATED).locPath("/stub/0001").maxAge(102)); runScheduledTask(); assertTrue(reg.isRegistered()); verifyScheduledInSec(72L); }
@Test public void update_failedConnection_immediately_reRegister() throws Exception { RegistrationManager reg = registered(); trnsport.when(newCoapPacket(2).post().uriPath("/stub/0001")) .thenThrow(new IOException()); trnsport.when(newCoapPacket(3).post().uriPath("/rd").uriQuery("ep=stub-device-01&lt=100").contFormat(CT_APPLICATION_LINK__FORMAT)) .then(newCoapPacket(3).ack(Code.C201_CREATED).locPath("/stub/0001").maxAge(102)); runScheduledTask(); assertTrue(reg.isRegistered()); verifyScheduledInSec(72L); }
@Test public void reRegister_after_disconnection() throws IOException { RegistrationManager reg = tcpRegistered(); trnsport.when(newCoapPacket().post().uriPath("/stub/0001")) .then(newCoapPacket().ack(Code.C204_CHANGED).maxAge(130)); trnsport.mockOnConnected(); assertTrue(reg.isRegistered()); verifyScheduledInSec(100L); }