Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* special thanks to
- * https://stackoverflow.com/questions/3467801/mockito-how-to-mock-only-the-call-of-a-method-of-the-superclass
- * I did a few editions
- *
- * The method validate()in BaseService is never called during tests
- */
- class BaseService {
- public void validate() {
- throw new IllegalArgumentException(" I must not be called");
- }
- public void save() {
- // Save method of super will still be called.
- validate();
- }
- }
- class ChildService extends BaseService {
- public void load() {
- }
- public void save() {
- load();
- }
- }
- @RunWith(MockitoJUnitRunner.class)
- public class TrainMlpScheduleSoftSensorService0Test {
- @Test
- public void testSave() {
- ChildService spy = Mockito.spy(new ChildService());
- // Prevent/stub logic in super.save()
- Mockito.doNothing().when((BaseService) spy).validate();
- // When
- spy.validate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement