vendredi 4 mars 2016

PowerMock mocks MoreAsserts

I'm writing a unit test in android studio and using PowerMock

The test looks like this

@RunWith(PowerMockRunner.class)
@PrepareOnlyThisForTest({Typeface.class})
public class ExtendedTextViewTest {

    ...

    @Test
    public void ctor_context_attributeSet_ShouldSetTypeface() throws Exception {
        // Act
        final LinkedList<Typeface> actualTypefaces = new LinkedList<Typeface>();
        ExtendedTextView textView = spy(new ExtendedTextView(contextMock, attributeSet) {
            @Override
            public void setTypeface(Typeface typeface) {
                actualTypefaces.add(typeface);
            }
        });

        // Assert
        MoreAsserts.assertEquals(new Typeface[]{typefaceMock}, actualTypefaces.toArray());
        verify(typedArrayMock, times(1)).recycle();
    }

}

When I run the test I get an error:

java.lang.RuntimeException: Method assertEquals in android.test.MoreAsserts not mocked. See http://ift.tt/1N5LezE for details.
    at android.test.MoreAsserts.assertEquals(MoreAsserts.java)
    at com.loka.loka.common.ExtendedTextViewTest.ctor_context_attributeSet_ShouldSetTypeface(ExtendedTextViewTest.java:130)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)

It seems that mockito mocks the MoreAsserts without me asking it to...what am I missing?

Thanks, Slava

Aucun commentaire:

Enregistrer un commentaire