@Test public void runtimeExceptionShouldBeTranslatedToError() { Snitch snitchMock = Mockito.mock(Snitch.class); URI uri = URI.create("http: String message = "nope"; Mockito.when(snitchMock.getUri()).thenReturn(uri); RuntimeException exceptionMock = Mockito.mock(RuntimeException.class); Mockito.when(exceptionMock.getMessage()).thenReturn(message); Mockito.when(snitchMock.snitch()).thenThrow(exceptionMock); System actual = resolver.resolve(SYSTEM_NAME, StaticSnitchRegistry.of(snitchMock)); ResolutionError error = ResolutionError.of(uri, "Could not access or process Snitch"); System expected = System.of(SYSTEM_NAME, new HashSet<>(), new HashSet<>(Arrays.asList(error))); Assertions.assertThat(actual).isEqualTo(expected); }
@Override public System resolve(String systemName, SnitchRegistry snitchRegistry) { Set<SystemFragment> frags = new HashSet<>(); Set<ResolutionError> errors = new HashSet<>(); for (Snitch snitch : snitchRegistry.getAll()) { try { frags.add(snitch.snitch()); } catch (SnitchingException e) { LOGGER.error("Snitch error caught while resolving system at URI : " + e.getSnitchUri(), e); errors.add(ResolutionError.translate(e)); } catch (RuntimeException e) { LOGGER.error("Technical error caught while resolving system at URI : " + snitch.getUri(), e); errors.add(ResolutionError.of(snitch.getUri(), DEFAULT_ERROR_MESSAGE)); } } return resolveBuilder(systemName, frags).errors(errors).build(); }
SimpleSystemResolver implements SystemResolver { @Override public System resolve(String systemName, SnitchRegistry snitchRegistry) { Set<SystemFragment> frags = new HashSet<>(); Set<ResolutionError> errors = new HashSet<>(); for (Snitch snitch : snitchRegistry.getAll()) { try { frags.add(snitch.snitch()); } catch (SnitchingException e) { LOGGER.error("Snitch error caught while resolving system at URI : " + e.getSnitchUri(), e); errors.add(ResolutionError.translate(e)); } catch (RuntimeException e) { LOGGER.error("Technical error caught while resolving system at URI : " + snitch.getUri(), e); errors.add(ResolutionError.of(snitch.getUri(), DEFAULT_ERROR_MESSAGE)); } } return resolveBuilder(systemName, frags).errors(errors).build(); } }
SimpleSystemResolver implements SystemResolver { @Override public System resolve(String systemName, SnitchRegistry snitchRegistry) { Set<SystemFragment> frags = new HashSet<>(); Set<ResolutionError> errors = new HashSet<>(); for (Snitch snitch : snitchRegistry.getAll()) { try { frags.add(snitch.snitch()); } catch (SnitchingException e) { LOGGER.error("Snitch error caught while resolving system at URI : " + e.getSnitchUri(), e); errors.add(ResolutionError.translate(e)); } catch (RuntimeException e) { LOGGER.error("Technical error caught while resolving system at URI : " + snitch.getUri(), e); errors.add(ResolutionError.of(snitch.getUri(), DEFAULT_ERROR_MESSAGE)); } } return resolveBuilder(systemName, frags).errors(errors).build(); }  }
SimpleSystemResolver implements SystemResolver { @Override public System resolve(String systemName, SnitchRegistry snitchRegistry) { Set<SystemFragment> frags = new HashSet<>(); Set<ResolutionError> errors = new HashSet<>(); for (Snitch snitch : snitchRegistry.getAll()) { try { frags.add(snitch.snitch()); } catch (SnitchingException e) { LOGGER.error("Snitch error caught while resolving system at URI : " + e.getSnitchUri(), e); errors.add(ResolutionError.translate(e)); } catch (RuntimeException e) { LOGGER.error("Technical error caught while resolving system at URI : " + snitch.getUri(), e); errors.add(ResolutionError.of(snitch.getUri(), DEFAULT_ERROR_MESSAGE)); } } return resolveBuilder(systemName, frags).errors(errors).build(); }  @Override System resolve(String systemName, SnitchRegistry snitchRegistry); @Override System resolve(String systemName, Collection<SystemFragment> fragments); }
SimpleSystemResolver implements SystemResolver { @Override public System resolve(String systemName, SnitchRegistry snitchRegistry) { Set<SystemFragment> frags = new HashSet<>(); Set<ResolutionError> errors = new HashSet<>(); for (Snitch snitch : snitchRegistry.getAll()) { try { frags.add(snitch.snitch()); } catch (SnitchingException e) { LOGGER.error("Snitch error caught while resolving system at URI : " + e.getSnitchUri(), e); errors.add(ResolutionError.translate(e)); } catch (RuntimeException e) { LOGGER.error("Technical error caught while resolving system at URI : " + snitch.getUri(), e); errors.add(ResolutionError.of(snitch.getUri(), DEFAULT_ERROR_MESSAGE)); } } return resolveBuilder(systemName, frags).errors(errors).build(); }  @Override System resolve(String systemName, SnitchRegistry snitchRegistry); @Override System resolve(String systemName, Collection<SystemFragment> fragments);  }