コード例 #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());
   }
 }
コード例 #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());
 }
コード例 #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));
 }
コード例 #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))));
 }
コード例 #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));
 }
コード例 #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);
             });
       });
 }
コード例 #7
0
 @Test
 public void getService_MUST_return_a_new_instance_WHEN_in_test_mode() throws Exception {
   assertNotSame(serviceLoader.getService(), serviceLoader.getService());
 }
コード例 #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());
 }
コード例 #9
0
 @Test
 public void getService_MUST_return_the_configured_instance() throws Exception {
   assertThat(serviceLoader.getService(), is(instanceOf(DerivedTestPlessServiceA.class)));
 }
コード例 #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();
 }