I can't get it to work, any ideas? Thanks.
class UnderTest
{
String test()
{
String s = getString();
System.out.println(s);
return s;
}
String getString() { return "REAL VALUE"; }
}
import org.junit.*;
import org.junit.runner.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import org.powermock.modules.junit4.*;
import org.powermock.core.classloader.annotations.*;
import org.powermock.api.mockito.powermocklistener.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest(UnderTest.class)
@PowerMockListener(AnnotationEnabler.class)
public class Tester
{
@org.powermock.core.classloader.annotations.Mock({"getString"})
private UnderTest underTest;
@Test
public void partialMockitoMock() throws Exception
{
when(underTest.getString()).thenReturn("TEST VALUE");
assertEquals("TEST VALUE", underTest.test());
verify(underTest).getString();
}
}
Getting this exception:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be a method call on a mock.
For example:
when(mock.getArticles()).thenReturn(articles);
at com.netledger.core.reporting.components.Tester.partialMockitoMock
(Tester.java:23)
On Apr 8, 11:26 pm, Jan Kronquist <
jan.kronqu...@gmail.com> wrote:
> PowerMock's @Mock annotation allows partial mocking. Take a look here:
>
>
http://code.google.com/p/powermock/source/browse/tags/powermock-1.2/m...
>
> Please let me know if you have any problems!
>
> /Jan
>