Skip to content

Commit

Permalink
Fixes #2154 : instrument java.lang.Object to fix toString invocations…
Browse files Browse the repository at this point in the history
… on inline mocks (#2193)
  • Loading branch information
JanMosigItemis committed Feb 1, 2021
1 parent fbe5058 commit 8a19d46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -269,9 +269,6 @@ private <T> void triggerRetransformation(Set<Class<?>> types, boolean flat) {
throw t;
}

// The object type does not ever need instrumentation.
targets.remove(Object.class);

if (!targets.isEmpty()) {
try {
assureCanReadMockito(targets);
Expand Down
Expand Up @@ -220,6 +220,20 @@ public void should_mock_interface_to_string() {
assertThat(proxy.toString()).isEqualTo("foo");
}

/**
* @see <a href="https://github.com/mockito/mockito/issues/2154">https://github.com/mockito/mockito/issues/2154</a>
*/
@Test
public void should_mock_class_to_string() {
MockSettingsImpl<Object> mockSettings = new MockSettingsImpl<Object>();
mockSettings.setTypeToMock(Object.class);
mockSettings.defaultAnswer(new Returns("foo"));
Object proxy =
mockMaker.createMock(mockSettings, new MockHandlerImpl<Object>(mockSettings));

assertThat(proxy.toString()).isEqualTo("foo");
}

@Test
public void should_remove_recursive_self_call_from_stack_trace() throws Exception {
StackTraceElement[] stack =
Expand Down

0 comments on commit 8a19d46

Please sign in to comment.