### Question:
Tracee { public static TraceeBackend getBackend() { return getBackend(new BackendProviderResolver()); } private  Tracee(); static TraceeBackend getBackend();  }### Answer:
@Test(expected = TraceeException.class) public void backendRetrievalShouldWrapRuntimeExceptionIfItOccurs() { try { final BackendProviderResolver testBackendProvider = Mockito.mock(BackendProviderResolver.class); when(testBackendProvider.getBackendProviders()).thenThrow(new RuntimeException()); Tracee.getBackend(testBackendProvider); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), equalTo("Unable to load available backend providers")); throw e; } }
@Test(expected = TraceeException.class) public void backendRetrievalShouldThrowExceptionWithoutProviders() { final BackendProviderResolver resolver = createTestBackendResolverWith(new HashSet<TraceeBackendProvider>()); try { Tracee.getBackend(resolver); fail(); } catch (TraceeException e) { assertThat(e.getMessage(), equalTo("Unable to find a TracEE backend provider. Make sure that you have tracee-core (for slf4j) or any other backend implementation on the classpath.")); throw e; } }
@Test(expected = TraceeException.class) public void backendRetrievalShouldThrowExceptionWithMoreThenOneProvider() { final Set<TraceeBackendProvider> backendProvider = new HashSet<>(); backendProvider.add(new TestBackendProvider()); backendProvider.add(new TestBackendProvider()); final BackendProviderResolver resolver = createTestBackendResolverWith(backendProvider); try { Tracee.getBackend(resolver); } catch (TraceeException e) { assertThat(e.getMessage(), allOf(startsWith("Multiple TracEE backend providers found. Don't know which one of the following to use:"), containsString(TestBackendProvider.class.getSimpleName()))); throw e; } }
@Test public void backendRetrievalShouldReturnBackendWithOneGivenProvider() { final Set<TraceeBackendProvider> backendProvider = new HashSet<>(); backendProvider.add(new TestBackendProvider()); final TraceeBackend resolvedBackend = Tracee.getBackend(createTestBackendResolverWith(backendProvider)); assertThat(resolvedBackend, is(not(nullValue()))); }
@Test(expected = TraceeException.class) public void backendRetrievalShouldThrowTraceeExceptionWithDefaultResolver() { try { Tracee.getBackend(); fail(); } catch (TraceeException e) { assertThat(e.getMessage(), equalTo("Unable to find a TracEE backend provider. Make sure that you have tracee-core (for slf4j) or any other backend implementation on the classpath.")); throw e; } }