-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2905 Co-authored-by: Roberto Trunfio <Roberto.Trunfio@appway.com>
- Loading branch information
1 parent
d6e39b8
commit 5153526
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2007 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockitousage.bugs; | ||
|
||
import static org.mockito.Mockito.RETURNS_MOCKS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
import org.mockitoutil.TestBase; | ||
|
||
/** | ||
* This was an issue reported in #2905. Mocking {@link ThreadLocal} or classes extending {@link ThreadLocal} was | ||
* throwing a {@link StackOverflowError}. | ||
*/ | ||
public class ThreadLocalTest extends TestBase { | ||
|
||
@Test | ||
public void mock_ThreadLocal_does_not_raise_StackOverflowError() { | ||
StackOverflowError stackOverflowError = | ||
Assertions.catchThrowableOfType( | ||
() -> { | ||
mock(ThreadLocal.class, RETURNS_MOCKS); | ||
}, | ||
StackOverflowError.class); | ||
Assertions.assertThat(stackOverflowError).isNull(); | ||
} | ||
|
||
@Test | ||
public void mock_class_extending_ThreadLocal_does_not_raise_StackOverflowError() { | ||
StackOverflowError stackOverflowError = | ||
Assertions.catchThrowableOfType( | ||
() -> { | ||
mock(SomeThreadLocal.class, RETURNS_MOCKS); | ||
}, | ||
StackOverflowError.class); | ||
Assertions.assertThat(stackOverflowError).isNull(); | ||
} | ||
|
||
@Test | ||
public void spy_ThreadLocal_does_not_raise_StackOverflowError() { | ||
StackOverflowError stackOverflowError = | ||
Assertions.catchThrowableOfType( | ||
() -> { | ||
spy(ThreadLocal.class); | ||
}, | ||
StackOverflowError.class); | ||
Assertions.assertThat(stackOverflowError).isNull(); | ||
} | ||
|
||
@Test | ||
public void spy_class_extending_ThreadLocal_does_not_raise_StackOverflowError() { | ||
StackOverflowError stackOverflowError = | ||
Assertions.catchThrowableOfType( | ||
() -> { | ||
spy(SomeThreadLocal.class); | ||
}, | ||
StackOverflowError.class); | ||
Assertions.assertThat(stackOverflowError).isNull(); | ||
} | ||
|
||
static class SomeThreadLocal<T> extends ThreadLocal<T> {} | ||
} |