1 /* 2 * Copyright (c) 2018 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockitoinline; 6 7 import org.junit.Test; 8 9 import static org.junit.Assert.assertEquals; 10 import static org.mockito.Mockito.mock; 11 import static org.mockito.Mockito.when; 12 import static org.mockito.Mockito.withSettings; 13 14 public class StressTest { 15 public class TestClass { getStuff()16 public String getStuff() { 17 return "A"; 18 } 19 } 20 21 @Test call_a_lot_of_mocks()22 public void call_a_lot_of_mocks() { 23 //This requires smaller heap set for the test process, see "inline.gradle" 24 for (int i = 0; i < 40000; i++) { 25 TestClass mock = mock(TestClass.class); 26 when(mock.getStuff()).thenReturn("B"); 27 assertEquals("B", mock.getStuff()); 28 29 TestClass serializableMock = mock(TestClass.class, withSettings().serializable()); 30 when(serializableMock.getStuff()).thenReturn("C"); 31 assertEquals("C", serializableMock.getStuff()); 32 33 if (i % 1024 == 0) { 34 System.out.println(i + "/40000 mocks called"); 35 } 36 } 37 } 38 } 39