@Test(expected = TermLookupServiceException.class) public void createAndIgnoreTermNoMapper() throws TermLookupServiceException, IOException { ResourceService resourceService = Mockito.mock(ResourceService.class); when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))) .thenReturn(IOUtils.toInputStream("observation_field_id\nshouldBeIgnored", StandardCharsets.UTF_8)) .thenReturn(IOUtils.toInputStream("observation_field_id\nshouldBeIgnored", StandardCharsets.UTF_8)); when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))) .thenReturn(IOUtils.toInputStream("", StandardCharsets.UTF_8)); InteractTypeMapper interactTypeMapper = new InteractTypeMapperFactoryWithFallback().create(); assertNull(interactTypeMapper); }
@Override public InteractTypeMapper create() throws TermLookupServiceException { InteractTypeMapper mapper = null; TermLookupServiceException lastException = null; for (InteractTypeMapperFactory factory : factoryAlternatives) { try { mapper = factory.create(); if (mapper != null) { break; } } catch (TermLookupServiceException ex) { lastException = ex; } } if (mapper == null) { throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException; } return mapper; }
InteractTypeMapperFactoryWithFallback implements InteractTypeMapperFactory { @Override public InteractTypeMapper create() throws TermLookupServiceException { InteractTypeMapper mapper = null; TermLookupServiceException lastException = null; for (InteractTypeMapperFactory factory : factoryAlternatives) { try { mapper = factory.create(); if (mapper != null) { break; } } catch (TermLookupServiceException ex) { lastException = ex; } } if (mapper == null) { throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException; } return mapper; } }
InteractTypeMapperFactoryWithFallback implements InteractTypeMapperFactory { @Override public InteractTypeMapper create() throws TermLookupServiceException { InteractTypeMapper mapper = null; TermLookupServiceException lastException = null; for (InteractTypeMapperFactory factory : factoryAlternatives) { try { mapper = factory.create(); if (mapper != null) { break; } } catch (TermLookupServiceException ex) { lastException = ex; } } if (mapper == null) { throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException; } return mapper; } InteractTypeMapperFactoryWithFallback(InteractTypeMapperFactory... factory); }
InteractTypeMapperFactoryWithFallback implements InteractTypeMapperFactory { @Override public InteractTypeMapper create() throws TermLookupServiceException { InteractTypeMapper mapper = null; TermLookupServiceException lastException = null; for (InteractTypeMapperFactory factory : factoryAlternatives) { try { mapper = factory.create(); if (mapper != null) { break; } } catch (TermLookupServiceException ex) { lastException = ex; } } if (mapper == null) { throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException; } return mapper; } InteractTypeMapperFactoryWithFallback(InteractTypeMapperFactory... factory); @Override InteractTypeMapper create(); }
InteractTypeMapperFactoryWithFallback implements InteractTypeMapperFactory { @Override public InteractTypeMapper create() throws TermLookupServiceException { InteractTypeMapper mapper = null; TermLookupServiceException lastException = null; for (InteractTypeMapperFactory factory : factoryAlternatives) { try { mapper = factory.create(); if (mapper != null) { break; } } catch (TermLookupServiceException ex) { lastException = ex; } } if (mapper == null) { throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException; } return mapper; } InteractTypeMapperFactoryWithFallback(InteractTypeMapperFactory... factory); @Override InteractTypeMapper create();  }