title: How to mock property source in spring test?
body: <p>I'm writing unit tests for my controller and faced an issue that <code>desktop.properties</code> file doesn't exist on my build server and shouldn't exist there.</p>
  
  <p>I have this main SpringBoot class:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages="com.xxx")
  @EnableJpaRepositories(basePackages = "com.xxx")
  @PropertySources(value = {@PropertySource("classpath:desktop.properties")})
  @EnableAutoConfiguration(exclude={JmsAutoConfiguration.class, SecurityAutoConfiguration.class, MultipartAutoConfiguration.class})
  @ImportResource(value = {"classpath:multipart.xml","classpath:column-maps-config.xml","classpath:model-ui-name-maps-config.xml"})
  public class ApplicationConfig extends WebMvcConfigurerAdapter implements EnvironmentAware, WebApplicationInitializer {
  }
  </code></pre>
  
  <p>This class imports <code>desktop.properties</code> as you can notice.</p>
  
  <p>And I have a test class that starts with:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = ApplicationConfig.class)
  @WebAppConfiguration
  public class SomeControllerTest {
  }
  </code></pre>
  
  <p>If I my environment doesn't have the <code>desktop.properties</code> file or I simply delete it then tests couldn't be run because <code>ApplicationConfig</code> class can't be instantiated without the dependency.</p>
  
  <p>My question is how can I mock <code>desktop.properties</code> or create a custom configuration for test purposes in order to replace <code>@ContextConfiguration(classes = ApplicationConfig.class)</code> with my test context?</p>
  
  <p>Could you be so kind to give me any hints about it?</p>
  
  <p>P.S. the current project is a quite old one with old versions so this is only one way I found to create tests for controllers with minimum changes to <code>pom.xml</code></p>