Home | History | Annotate | Download | only in performance
      1 package org.mockitousage.performance;
      2 
      3 import org.junit.Ignore;
      4 import org.junit.Test;
      5 
      6 import static org.mockito.Mockito.*;
      7 
      8 public class StubOnlyAvoidMemoryConsumptionTest {
      9 
     10     @Test
     11     public void using_stub_only_wont_thrown_an_OutOfMemoryError() {
     12         Object obj = mock(Object.class, withSettings().stubOnly());
     13         when(obj.toString()).thenReturn("asdf");
     14 
     15         for (int i = 0; i < 1000000; i++) {
     16             obj.toString();
     17         }
     18     }
     19 
     20     @Test
     21     @Ignore("ignored because it will detonate our test suite with an OOM for real")
     22     public void without_stub_only_mocks_will_store_invocations_leading_to_an_OutOfMemoryError() {
     23         Object obj = mock(Object.class, withSettings());
     24         when(obj.toString()).thenReturn("asdf");
     25 
     26         for (int i = 0; i < 1000000; i++) {
     27             obj.toString();
     28         }
     29     }
     30 }
     31