### Question:
KeyValuePairRelay implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if (!(request instanceof KeyValueRequest)) { return new NoSpecimen(); } KeyValueRequest kvRequest = (KeyValueRequest)request; Object keyResult = context.resolve(kvRequest.getKeyType()); if(keyResult instanceof NoSpecimen) return new NoSpecimen(); Object valueResult = context.resolve(kvRequest.getValueType()); if(valueResult instanceof NoSpecimen) return new NoSpecimen(); return new KeyValuePair(keyResult, valueResult); }  @Override Object create(Object request, SpecimenContext context);  }### Answer:
@Test public void non_KeyValueRequest_request_type_returns_no_specimen() { Object result = this.relay.create(String.class, mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Test public void KeyValueRequest_request_resolves_both_items_and_returns_as_a_KeyValuePair() { when(mockSpecimenContext.resolve(String.class)).thenReturn("string"); when(mockSpecimenContext.resolve(int.class)).thenReturn(1); Object result = this.relay.create(new KeyValueRequest(String.class, int.class), mockSpecimenContext); assertEquals("string", ((KeyValuePair) result).getKey()); assertEquals(1, ((KeyValuePair) result).getValue()); }
@Test public void resolving_first_request_as_no_specimen_returns_no_specimen() { when(mockSpecimenContext.resolve(String.class)).thenReturn(new NoSpecimen()); when(mockSpecimenContext.resolve(int.class)).thenReturn(1); Object result = this.relay.create(new KeyValueRequest(String.class, int.class), mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Test public void resolving_second_request_as_no_specimen_returns_no_specimen() { when(mockSpecimenContext.resolve(String.class)).thenReturn("string"); when(mockSpecimenContext.resolve(int.class)).thenReturn(new NoSpecimen()); Object result = this.relay.create(new KeyValueRequest(String.class, int.class), mockSpecimenContext); assertEquals(new NoSpecimen(), result); }