AuditorFactory { public static synchronized Auditor createAuditor() { final SPIAuditorProvider spiProv = new SPIAuditorProvider(); final Provider<Auditor> provider = spiProv.isImplementationAvailable() ? spiProv : new LoggingAuditorProvider(); return createAuditor(provider); }  static synchronized Auditor createAuditor(); static synchronized Auditor createAuditor(Provider<Auditor> provider); static synchronized Auditor createAuditor(Collection<Module> modules);  }
@Test public void testCreateAuditor_NullProvider_AssertException() throws Exception { boolean exeptionOccured = false; try { AuditorFactory.createAuditor((Provider<Auditor>)null); } catch (IllegalArgumentException e) { exeptionOccured = true; } assertTrue(exeptionOccured); }
@Test public void testCreateAuditor_SingleModule_AssertCreatedAuditor() throws Exception { LoggingAuditorProvider provider = new LoggingAuditorProvider(); ProviderAuditorModule module = ProviderAuditorModule.create(provider); Collection<Module> modules = new ArrayList<Module>(); modules.add(module); Auditor auditor = AuditorFactory.createAuditor(modules); assertNotNull(auditor); assertTrue(auditor instanceof LoggingAuditor); }
@Test public void testCreateAuditor_NullModule_AssertException() throws Exception { boolean exeptionOccured = false; try { AuditorFactory.createAuditor((Collection<Module>)null); } catch (IllegalArgumentException e) { exeptionOccured = true; } assertTrue(exeptionOccured); }
@Test public void testCreateAuditor_EmptyModule_AssertException() throws Exception { boolean exeptionOccured = false; try { AuditorFactory.createAuditor(new ArrayList<Module>()); } catch (IllegalArgumentException e) { exeptionOccured = true; } assertTrue(exeptionOccured); }
@Test public void testCreateAuditor_SingleSPIImplementation_AssertCreatedSPIAuditor() throws Exception { setupSPIImplementation(NoOpAuditor.class); Auditor auditor = AuditorFactory.createAuditor(); assertNotNull(auditor); assertTrue(auditor instanceof NoOpAuditor); }
@Test public void testCreateAuditor_NoSPI_AssertCreatedDefaultAuditor() { Auditor auditor = AuditorFactory.createAuditor(); assertNotNull(auditor); assertTrue(auditor instanceof LoggingAuditor); }
@Test public void testCreateAuditor_MultiSPIImplementation_AssertCreatedSPIAuditor() throws Exception { setupSPIImplementation(NoOpAuditor.class); setupSPIImplementation(LoggingAuditor.class); Auditor auditor = AuditorFactory.createAuditor(); assertNotNull(auditor); assertTrue(auditor instanceof MultiProviderAuditor); }
@Test public void testCreateAuditor_SingleProvider_AssertCreatedAuditor() throws Exception { LoggingAuditorProvider proviver = new LoggingAuditorProvider(); Auditor auditor = AuditorFactory.createAuditor(proviver); assertNotNull(auditor); assertTrue(auditor instanceof LoggingAuditor); }