Exemplo n.º 1
0
 @Test
 public void getService_MUST_return_the_same_instance_WHEN_in_dev_mode() throws Exception {
   doReturn(Mode.DEV).when(configurationSource()).runMode();
   try (TemporaryPlayApplication ignored = new TemporaryPlayApplication()) {
     assertSame(serviceLoader.getService(), serviceLoader.getService());
   }
 }
Exemplo n.º 2
0
 @Test
 public void
     getService_MUST_return_the_fallback_service_instance_WHEN_the_service_is_not_configured()
         throws Exception {
   configureService(null);
   assertEquals(FALLBACK_SERVICE_INSTANCE, serviceLoader.getService());
 }
Exemplo n.º 3
0
 @Test
 public void
     getService_MUST_not_use_the_default_instance_creator_AFTER_temporary_services_were_closed()
         throws Exception {
   withDefaultService(DEFAULT_SERVICE_A_INSTANCE, () -> {});
   assertThat(serviceLoader.getService(), instanceOf(CUSTOM_SERVICE_CLASS));
 }
Exemplo n.º 4
0
 @Test
 public void getService_MUST_return_the_configured_service_WHEN_default_service_is_specified()
     throws Exception {
   withDefaultService(
       DEFAULT_SERVICE_A_INSTANCE,
       () ->
           assertThat(serviceLoader.getService(), is(instanceOf(DerivedTestPlessServiceA.class))));
 }
Exemplo n.º 5
0
 @Test
 public void getService_MUST_return_the_default_service_WHEN_no_service_is_configured()
     throws Exception {
   configureService(null);
   withDefaultService(
       DEFAULT_SERVICE_A_INSTANCE,
       () -> assertSame(serviceLoader.getService(), DEFAULT_SERVICE_A_INSTANCE));
 }
Exemplo n.º 6
0
 @Test
 public void getService_MUST_return_the_fallback_service_WHEN_default_service_is_removed()
     throws Exception {
   configureService(null);
   withDefaultService(
       DEFAULT_SERVICE_A_INSTANCE,
       () -> {
         withDefaultService(
             TestPlessServiceA.class,
             null,
             () -> {
               assertSame(serviceLoader.getService(), FALLBACK_SERVICE_INSTANCE);
             });
       });
 }
Exemplo n.º 7
0
 @Test
 public void getService_MUST_return_a_new_instance_WHEN_in_test_mode() throws Exception {
   assertNotSame(serviceLoader.getService(), serviceLoader.getService());
 }
Exemplo n.º 8
0
 @Test
 public void getService_MUST_return_the_same_instance_WHEN_in_production_mode() throws Exception {
   doReturn(Mode.PROD).when(configurationSource()).runMode();
   assertSame(serviceLoader.getService(), serviceLoader.getService());
 }
Exemplo n.º 9
0
 @Test
 public void getService_MUST_return_the_configured_instance() throws Exception {
   assertThat(serviceLoader.getService(), is(instanceOf(DerivedTestPlessServiceA.class)));
 }
Exemplo n.º 10
0
 @Test(expected = RuntimeException.class)
 public void getService_MUST_throw_an_exception_WHEN_the_service_class_does_not_exist()
     throws Exception {
   configureService("not a valid class name");
   serviceLoader.getService();
 }