Versions:
Java: 1.8
Spring Boot: 1.5.4.RELEASE
Application Main:
@SpringBootApplication
public class SpringbootMockitoApplication implements CommandLineRunner {
@Autowired
MyCoolService myCoolService;
public static void main(String[] args) {
SpringApplication.run(SpringbootMockitoApplication.class, args);
}
@Override
public void run(String... strings) throws Exception {
System.out.println(myCoolService.talkToMe());
}
}
My Service Interface:
public interface MyCoolService {
public String talkToMe();
}
My Service Implementation:
@Service
public class MyCoolServiceImpl implements MyCoolService {
@Override
public String talkToMe() {
return "Epic Win";
}
}
My Test class:
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootMockitoApplicationTests {
@MockBean
private MyCoolService myCoolService;
@Test
public void test() {
when(myCoolService.talkToMe()).thenReturn("I am greater than epic");
}
}
Expected Output: I am greater than epic Actual Output: null
I simply want to replace the bean instance in the context with a mock that will return "I am greater than epic". Have I misconfigured something here?