RoutingService { public ResponseDescriptorDTO getResponseDescriptorDTOAndRemove(final String key) { ResponseDescriptorDTO responseDescriptor = responseDescriptorMap.get(key); if (responseDescriptor != null) { responseDescriptorMap.remove(key); } return responseDescriptor; }  boolean redirectRequestToStub(final WilmaHttpRequest request); ResponseDescriptorDTO getResponseDescriptorDTOAndRemove(final String key); void setOperationMode(final OperationMode operationMode); Map<String, StubDescriptor> getStubDescriptors(); boolean isStubModeOn(); void performModification(final StubDescriptorModificationCommand command);  }
@Test public void testGetResponseDescriptorDTOAndRemoveShouldFindResponseDescriptorWithKey() { Map<String, ResponseDescriptorDTO> responseDescriptorMap = new HashMap<>(); String key = "key"; responseDescriptorMap.put(key, new ResponseDescriptorDTO(null, "", MSG_ID)); Whitebox.setInternalState(underTest, "responseDescriptorMap", responseDescriptorMap); ResponseDescriptorDTO actual = underTest.getResponseDescriptorDTOAndRemove(key); assertEquals(actual.getRequestBody(), MSG_ID); }
@Test public void testGetResponseDescriptorDTOAndRemoveShouldReturnNullWhenKeyNotFound() { Map<String, ResponseDescriptor> responseDescriptorMap = new HashMap<>(); String key = "key"; Whitebox.setInternalState(underTest, "responseDescriptorMap", responseDescriptorMap); ResponseDescriptorDTO actual = underTest.getResponseDescriptorDTOAndRemove(key); assertNull(actual); }
@Test public void testGetResponseDescriptorAndRemoveShouldNotDeleteEntryWhenKeyNotFound() { Map<String, ResponseDescriptorDTO> responseDescriptorMap = new HashMap<>(); String key = "key"; responseDescriptorMap.put("someOtherKey", new ResponseDescriptorDTO(null, "", MSG_ID)); Whitebox.setInternalState(underTest, "responseDescriptorMap", responseDescriptorMap); underTest.getResponseDescriptorDTOAndRemove(key); @SuppressWarnings("unchecked") Map<String, ResponseDescriptorDTO> newDescriptorMap = (Map<String, ResponseDescriptorDTO>) Whitebox.getInternalState(underTest, "responseDescriptorMap"); assertEquals(newDescriptorMap.get("someOtherKey").getRequestBody(), MSG_ID); }
@Test public void testGetResponseDescriptorAndRemoveShouldReturnWithEntry() { Map<String, ResponseDescriptorDTO> responseDescriptorMap = new HashMap<>(); String key = "key"; ResponseDescriptorDTO expected = new ResponseDescriptorDTO(null, "", MSG_ID); responseDescriptorMap.put(key, expected); Whitebox.setInternalState(underTest, "responseDescriptorMap", responseDescriptorMap); ResponseDescriptorDTO actual = underTest.getResponseDescriptorDTOAndRemove(key); assertEquals(actual, expected); }