I have below test which works successfully while executing in IDE but when I do mvn install it fails with below msg
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
Below is the test class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = SpringockitoContextLoader.class,locations={"classpath:conf/test-context.xml"})
public class ServiceTest
{
@ReplaceWithMock
@Autowired
private Object1 object1
@Autowired
private Service service;
@Before
public void setup()
{
MockitoAnnotations.initMocks(this);
}
@Test
public void test()
{//below line is failing while doing mvn install
String validateMe="1234"
Mockito.when(object1.validate(validateMe)).thenReturn(true)
}
}
Do I need any other extra configuration to have it work in maven ?
update Upon further analysis between the behaviour of the results from IDE and maven.I added below code in test method and found that while running from IDE object1 is coming as mock and is returning true but while running from maven test it is printing as false. Any idea why this would be haappening
new MockUtil().isMock(object1)