@@ -0,0 +1,2734 @@
+/*%0A * Copyright 2006-2017 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.springframework.cloud.context.scope.refresh;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;%0Aimport org.springframework.cloud.context.config.annotation.RefreshScope;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.context.annotation.Import;%0Aimport org.springframework.test.annotation.DirtiesContext;%0Aimport org.springframework.test.context.junit4.SpringRunner;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0A@RunWith(SpringRunner.class)%0A@SpringBootTest(classes = %7BRefreshScopeNullBeanIntegrationTests.TestConfiguration.class%7D)%0Apublic class RefreshScopeNullBeanIntegrationTests %7B%0A%0A%09@Autowired%0A%09private MyCustomComponent myCustomComponent;%0A%0A%09@Autowired%0A%09private org.springframework.cloud.context.scope.refresh.RefreshScope scope;%0A%0A%09@Test%0A%09@DirtiesContext%0A%09public void testRefreshBean() %7B%0A%09%09assertThat(this.myCustomComponent).isNotNull();%0A%09%09// ...and then refresh, so the bean is re-initialized:%0A%09%09// this.scope.refreshAll();%0A%09%7D%0A%0A%09protected static class OptionalService %7B %7D%0A%0A%09public static class MyCustomComponent %7B%0A%0A%09%09private final OptionalService optionalService;%0A%0A%09%09public MyCustomComponent(OptionalService optionalService) %7B%0A%09%09%09this.optionalService = optionalService;%0A%09%09%7D%0A%09%7D%0A%0A%09@Configuration%0A%09protected static class OptionalConfiguration %7B%0A%0A%09%09@Bean%0A%09%09@RefreshScope%0A%09%09public OptionalService service() %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%0A%09@Configuration%0A%09@Import(%7B RefreshAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, OptionalConfiguration.class %7D)%0A%09protected static class TestConfiguration %7B%0A%0A%09%09@Autowired(required = false)%0A%09%09private OptionalService optionalService;%0A%0A%09%09@Bean%0A%09%09public MyCustomComponent myCustomComponent() %7B%0A%09%09%09return new MyCustomComponent(optionalService);%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Test for NPE when calling getClass() in RefreshScope