title: @TestPropertySource - Values not set / set as null from test properties file
body: <p>My Junit is not picking up properties set in test properties file.
  I get no error, but value returned from properties file is null</p>
  
  <p><strong>CLASS TO BE TESTED:</strong></p>
  
  <pre><code>package com.abc.mysource.mypackage;
  
  @Component
  @ComponentScan
  public class MyHelper {
  
      @Autowired
      @Qualifier("commonProperties")
      private CommonProperties commonProperties;  
  
      public LocalDateTime method1ThatUsesCommonProperties(LocalDateTime startDateTime) throws Exception {
          String customUserType = commonProperties.getUserType(); // Returns null if run as JUnit test
          //Further processing
      }
  }
  </code></pre>
  
  <p><strong>SUPPORTING COMPONENTS - BEANS &amp; CONFIG CLASSES:</strong></p>
  
  <pre><code>package com.abc.mysource.mypackage;
  @Component
  public class CommonProperties {
       @Value("${myhelper.userType}")
       private String userType;
  
           public String getUserType() {
          return userType;
      }
      public void setCalendarType(String userType) {
          this.userType = userType;
      }
  }
  </code></pre>
  
  <p><strong>CONFIG CLASS:</strong></p>
  
  <pre><code>package com.abc.mysource.mypackage;
  @Configuration
  @ComponentScan(basePackages ="com.abc.mysource.mypackage.*")
  @PropertySource("classpath:default.properties")
  public class CommonConfig {}
  </code></pre>
  
  <p><strong>default.properties under src/main/resources</strong></p>
  
  <pre><code>myhelper.userType=PRIORITY
  </code></pre>
  
  <p><strong>MY TEST CLASS:</strong></p>
  
  <pre><code>package com.abc.mysource.mypackage.test;
  @RunWith(SpringRunner.class)
  @ContextConfiguration(classes=MyHelper.class)
  @TestPropertySource("classpath:default-test.properties")
  @EnableConfigurationProperties
  public class MyHelperTest {
      @MockBean(name="commonProperties")
      private CommonProperties commonProperties;
  
      @Autowired
      private MyHelper myHelper;
  
      @Test
      public void testMethod1ThatUsesCommonProperties() {
          myHelper.method1ThatUsesCommonProperties();
      }
  }
  </code></pre>
  
  <p><strong>default-test.properties defined under /src/test/resources:</strong></p>
  
  <pre><code>myhelper.userType=COMMON
  </code></pre>
  
  <p><strong>NOTE:</strong> </p>
  
  <p>I moved default-test.properties to /src/main/resources - commonProperties.getUserType() is null</p>
  
  <p>I even used @TestPropertySource(properties = {"myhelper.userType=COMMON"}). Same result</p>
  
  <p><strong>NOTE 2:</strong></p>
  
  <p>I tried the solution on <a href="https://stackoverflow.com/questions/33371875/testpropertysource-is-not-loading-properties">@TestPropertySource is not loading properties</a>.</p>
  
  <p>This solution requires me to create a duplicate bean called CommonProperties under src/test/java. But @MockBean fails when I do </p>
  
  <pre><code>@MockBean(name="commonProperties")
  private CommonProperties commonProperties;
  </code></pre>
  
  <p>Please do not mark a duplicate.</p>
  
  <p><strong>NOTE 3:</strong>
  Mine is a spring, not a spring boot application.</p>