I have a controller
@RestController
public class Create {
@Autowired
private ComponentThatDoesSomething something;
@RequestMapping(\"/greeting\
Use Mockito and inject a mock that you create. I would prefer constructor injection:
@RestController
public class Create {
private ComponentThatDoesSomething something;
@Autowired
public Create(ComponentThatDoesSomething c) {
this.something = c;
}
}
Don't use Spring in your Junit tests.
public CreateTest {
private Create create;
@Before
public void setUp() {
ComponentThatDoesSomething c = Mockito.mock(ComponentThatDoesSomething .class);
this.create = new Create(c);
}
}