Search in sources :

Example 1 with MockType

use of org.easymock.MockType in project easymock by easymock.

the class MockTypeTest method fromEasyMockSupportClassWithName.

@Test
public void fromEasyMockSupportClassWithName() {
    IMethods mock = support.createMock("test", MockType.STRICT, IMethods.class);
    MockType type = MocksControl.getControl(mock).getType();
    assertEquals(MockType.STRICT, type);
    assertEquals("test", mock.toString());
}
Also used : MockType(org.easymock.MockType) Test(org.junit.Test)

Example 2 with MockType

use of org.easymock.MockType in project easymock by easymock.

the class MockTypeTest method fromEasyMockClass.

@Test
public void fromEasyMockClass() {
    IMethods mock = EasyMock.createMock(MockType.STRICT, IMethods.class);
    MockType type = MocksControl.getControl(mock).getType();
    assertEquals(MockType.STRICT, type);
    assertEquals("EasyMock for interface " + IMethods.class.getName(), mock.toString());
}
Also used : MockType(org.easymock.MockType) Test(org.junit.Test)

Example 3 with MockType

use of org.easymock.MockType in project easymock by easymock.

the class MockTypeTest method fromEasyMockSupportClass.

@Test
public void fromEasyMockSupportClass() {
    IMethods mock = support.createMock(MockType.STRICT, IMethods.class);
    MockType type = MocksControl.getControl(mock).getType();
    assertEquals(MockType.STRICT, type);
    assertEquals("EasyMock for interface " + IMethods.class.getName(), mock.toString());
}
Also used : MockType(org.easymock.MockType) Test(org.junit.Test)

Example 4 with MockType

use of org.easymock.MockType in project powermock by powermock.

the class EasyMockNewInvocationControl method invoke.

@Override
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
    Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
    if (constructor.isVarArgs()) {
        /*
             * Get the last argument because this contains the actual varargs
             * arguments.
             */
        int length = constructor.getParameterTypes().length;
        args = (Object[]) args[length - 1];
    }
    try {
        final MockType mockType = ((EasyMockMethodInvocationControl<?>) MockRepository.getInstanceMethodInvocationControl(substitute)).getMockType();
        Object result = substitute.performSubstitutionLogic(args);
        if (result == null) {
            if (mockType == MockType.NICE) {
                result = EasyMock.createNiceMock(subsitutionType);
            } else {
                throw new IllegalStateException("Must replay class " + type.getName() + " to get configured expectation.");
            }
        }
        return result;
    } catch (AssertionError e) {
        NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
    }
    // Won't happen
    return null;
}
Also used : MockType(org.easymock.MockType)

Example 5 with MockType

use of org.easymock.MockType in project easymock by easymock.

the class MockTypeTest method fromMockBuilderClass.

// The two following tests are showing a strange behavior. The toString doesn't return the
// default EasyMock implementation. I won't change it right now but it doesn't feel right
@Test
public void fromMockBuilderClass() {
    MockTypeTest mock = builder.addMockedMethod("toString").createMock(MockType.STRICT);
    MockType type = MocksControl.getControl(mock).getType();
    assertEquals(MockType.STRICT, type);
    assertEquals("EasyMock for class " + MockTypeTest.class.getName(), mock.toString());
}
Also used : MockType(org.easymock.MockType) Test(org.junit.Test)

Aggregations

MockType (org.easymock.MockType)7 Test (org.junit.Test)6