Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2389 : Get existing stubbings with thread-safe method.
- Loading branch information
Mikaël Francoeur
committed
Oct 12, 2021
1 parent
e8f26b3
commit 8ef1562
Showing
2 changed files
with
33 additions
and
7 deletions.
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
29 changes: 29 additions & 0 deletions
29
...est/java/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubsConcurrentTest.java
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,29 @@ | ||
/* | ||
* Copyright (c) 2021 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.stubbing.defaultanswers; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Answers; | ||
|
||
public class ReturnsDeepStubsConcurrentTest { | ||
|
||
@Test | ||
public void | ||
given_mock_with_returns_deep_stubs__when_called_concurrently__then_does_not_throw_concurrent_modification_exception() { | ||
for (int i = 0; i < 1000; i++) { | ||
Service mock = mock(Service.class, Answers.RETURNS_DEEP_STUBS); | ||
IntStream.range(1, 100).parallel().forEach(index -> mock.doSomething()); | ||
} | ||
} | ||
|
||
interface Service { | ||
List<String> doSomething(); | ||
} | ||
} |