| 1 |
/* |
| 2 |
* Copyright (c) 2019 Mockito contributors |
| 3 |
* This program is made available under the terms of the MIT License. |
| 4 |
*/ |
| 5 |
package org.mockitoinline.bugs; |
| 6 |
|
| 7 |
import org.junit.Test; |
| 8 |
|
| 9 |
import static org.mockito.Mockito.framework; |
| 10 |
import static org.mockito.Mockito.mock; |
| 11 |
|
| 12 |
public class CyclicMockMethodArgumentMemoryLeakTest { |
| 13 |
private static final int ARRAY_LENGTH = 1 << 20; // 4 MB |
| 14 |
|
| 15 |
@Test |
| 16 |
public void no_memory_leak_when_cyclically_calling_method_with_mocks() { |
| 17 |
for (int i = 0; i < 100; ++i) { |
| 18 |
final A a = mock(A.class); |
| 19 |
a.largeArray = new int[ARRAY_LENGTH]; |
| 20 |
final B b = mock(B.class); |
| 21 |
|
| 22 |
a.accept(b); |
| 23 |
b.accept(a); |
| 24 |
|
| 25 |
framework().clearInlineMocks(); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
private static class A { |
| 30 |
private int[] largeArray; |
| 31 |
|
| 32 |
void accept(B b) {} |
| 33 |
} |
| 34 |
|
| 35 |
private static class B { |
| 36 |
void accept(A a) {} |
| 37 |
} |
| 38 |
} |