There are times you want to Mock the superclass & test only the subclass. Superclass that should not be invoked The BaseService.java:
|
|
package com.myapp; public class BaseService { public BaseService(){ throw new IllegalArgumentException("Should not reach here"); } } |
Subclass to be tested The MyService.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
package com.myapp; public class MyService extends BaseService { private int num1; private int num2; public MyService(int num1, int num2) { super(); this.num1 = num1; this.num2 = num2; } public int eval() { return num1 + num2; } } |
JUnit test class The BaseService.java will be mocked as shown below. … Read more ›...