0

I want to make pure unit test for one of my services:

@Service
public class ResultsNotifierScheduler {
    
    @Autowired
    AppSettingsRepository appSettingsRepository;
...
}

I am trying by test configuration and use a Bean:

public class TestResultsNotifierSchedulerSpec {

    @TestConfiguration
    static class TestResultsNotifierSchedulerSpecConfiguration {
        @Bean
        public AppSettingsRepository appSettingsRepository() {
            return mock(AppSettingsRepository.class);
        }
    }

    TestResultsNotifierScheduler testResultsNotifierScheduler = new TestResultsNotifierScheduler();

    @Test
    void lastCheckOverHourProcessResults() {
        testResultsNotifierScheduler.checkLabTestResultsAvailabilityNew();
    }
}

but still I have an error:

because "this.appSettingsRepository" is null

my question is, how in test I can inject for ResultsNotifierScheduler mocked appSettingsRepository ?

thanks!

FrancMo
  • 1,804
  • 2
  • 15
  • 28

0 Answers0