use of org.mockito.mock.MockCreationSettings in project mockito by mockito.
the class InlineByteBuddyMockMakerTest method should_throw_exception_redefining_unmodifiable_class.
@Test
@SuppressWarnings("unchecked")
public void should_throw_exception_redefining_unmodifiable_class() {
MockCreationSettings settings = settingsFor(int.class);
try {
mockMaker.createMock(settings, new MockHandlerImpl(settings));
fail("Expected a MockitoException");
} catch (MockitoException e) {
e.printStackTrace();
assertThat(e).hasMessageContaining("Could not modify all classes");
}
}
use of org.mockito.mock.MockCreationSettings in project mockito by mockito.
the class MockUtil method resetMock.
public static <T> void resetMock(T mock) {
InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
MockCreationSettings settings = oldHandler.getMockSettings();
MockHandler newHandler = createMockHandler(settings);
mockMaker.resetMock(mock, newHandler, settings);
}
use of org.mockito.mock.MockCreationSettings in project mockito by mockito.
the class MockHandlerFactoryTest method valid_handle_result_is_permitted.
@Test
public //see issue 331
void valid_handle_result_is_permitted() throws Throwable {
//given:
MockCreationSettings<?> settings = (MockCreationSettings<?>) new MockSettingsImpl().defaultAnswer(new Returns(123));
InternalMockHandler<?> handler = createMockHandler(settings);
mock.intReturningMethod();
Invocation invocation = super.getLastInvocation();
//when:
Object result = handler.handle(invocation);
//then
assertEquals(123, result);
}
use of org.mockito.mock.MockCreationSettings in project mockito by mockito.
the class MockHandlerFactoryTest method handle_result_must_not_be_null_for_primitives.
@Test
public //see issue 331
void handle_result_must_not_be_null_for_primitives() throws Throwable {
//given:
MockCreationSettings<?> settings = (MockCreationSettings<?>) new MockSettingsImpl().defaultAnswer(new Returns(null));
InternalMockHandler<?> handler = createMockHandler(settings);
mock.intReturningMethod();
Invocation invocation = super.getLastInvocation();
//when:
Object result = handler.handle(invocation);
//then null value is not a valid result for a primitive
assertNotNull(result);
assertEquals(0, result);
}
use of org.mockito.mock.MockCreationSettings in project mockito by mockito.
the class MockUtil method maybeRedefineMockName.
public static void maybeRedefineMockName(Object mock, String newName) {
MockName mockName = getMockName(mock);
//TODO SF hacky...
MockCreationSettings mockSettings = getMockHandler(mock).getMockSettings();
if (mockName.isDefault() && mockSettings instanceof CreationSettings) {
((CreationSettings) mockSettings).setMockName(new MockNameImpl(newName));
}
}
Aggregations