@Test public void testExecuteReturningNullFromNoResults() { context.checking(new Expectations() { { oneOf(wrappedMapper).execute(with(any(List.class))); will(returnValue(new ArrayList<String>())); } }); assertNull(new SingleValueCollectionMapperWrapper(wrappedMapper, false).execute("FOO")); context.assertIsSatisfied(); }
@Override public ResponseType execute(final RequestType inRequest) { List<ResponseType> response = wrappedMapper.execute(Collections.singletonList(inRequest)); if (response.size() != 1) { if (throwExceptionWhenSingleResultNotFound) { throw new RuntimeException("Could not found exactly one response for key: " + inRequest + " - found " + response.size() + " results."); } else { return null; } } return response.get(0); }
SingleValueCollectionMapperWrapper implements
        DomainMapper<RequestType, ResponseType> { @Override public ResponseType execute(final RequestType inRequest) { List<ResponseType> response = wrappedMapper.execute(Collections.singletonList(inRequest)); if (response.size() != 1) { if (throwExceptionWhenSingleResultNotFound) { throw new RuntimeException("Could not found exactly one response for key: " + inRequest + " - found " + response.size() + " results."); } else { return null; } } return response.get(0); } }
SingleValueCollectionMapperWrapper implements
        DomainMapper<RequestType, ResponseType> { @Override public ResponseType execute(final RequestType inRequest) { List<ResponseType> response = wrappedMapper.execute(Collections.singletonList(inRequest)); if (response.size() != 1) { if (throwExceptionWhenSingleResultNotFound) { throw new RuntimeException("Could not found exactly one response for key: " + inRequest + " - found " + response.size() + " results."); } else { return null; } } return response.get(0); } SingleValueCollectionMapperWrapper(
            final DomainMapper<List<RequestType>, List<ResponseType>> inWrappedMapper,
            final boolean inThrowExceptionWhenSingleResultNotFound); }
SingleValueCollectionMapperWrapper implements
        DomainMapper<RequestType, ResponseType> { @Override public ResponseType execute(final RequestType inRequest) { List<ResponseType> response = wrappedMapper.execute(Collections.singletonList(inRequest)); if (response.size() != 1) { if (throwExceptionWhenSingleResultNotFound) { throw new RuntimeException("Could not found exactly one response for key: " + inRequest + " - found " + response.size() + " results."); } else { return null; } } return response.get(0); } SingleValueCollectionMapperWrapper(
            final DomainMapper<List<RequestType>, List<ResponseType>> inWrappedMapper,
            final boolean inThrowExceptionWhenSingleResultNotFound); @Override ResponseType execute(final RequestType inRequest); }
SingleValueCollectionMapperWrapper implements
        DomainMapper<RequestType, ResponseType> { @Override public ResponseType execute(final RequestType inRequest) { List<ResponseType> response = wrappedMapper.execute(Collections.singletonList(inRequest)); if (response.size() != 1) { if (throwExceptionWhenSingleResultNotFound) { throw new RuntimeException("Could not found exactly one response for key: " + inRequest + " - found " + response.size() + " results."); } else { return null; } } return response.get(0); } SingleValueCollectionMapperWrapper(
            final DomainMapper<List<RequestType>, List<ResponseType>> inWrappedMapper,
            final boolean inThrowExceptionWhenSingleResultNotFound); @Override ResponseType execute(final RequestType inRequest);  }