dhamini-poornachandra / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Deep Stubs are not serializable #399

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Map;

public class DeepStubsAreNotSerializableTest {

  @Test
  public void name() throws Exception {
    Map map = Mockito.mock(Map.class, Mockito.RETURNS_DEEP_STUBS);

    Mockito.when(map.entrySet().contains(Matchers.anyString())).thenReturn(false);

    ByteArrayOutputStream serialized = new ByteArrayOutputStream();
    new ObjectOutputStream(serialized).writeObject(map);
  }
}

What is the expected output? What do you see instead?
java.io.NotSerializableException: 
org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs$1
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
        ...

Please use labels and text to provide additional information.
Mockito 1.9.5, and earlier versions

Original issue reported on code.google.com by brice.du...@gmail.com on 19 Nov 2012 at 10:02

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 27 Nov 2012 at 5:07

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 27 Nov 2012 at 5:08

GoogleCodeExporter commented 8 years ago
Have you been working on that or is it possible to start this one?

Original comment by marcin.g...@gmail.com on 23 Dec 2013 at 7:49

GoogleCodeExporter commented 8 years ago
You can start this one, but it's gonna be a challenging one, as it involves 
some new code regarding generics.

Anyway ou can still work on serialization when generics are not involved. 
That'll be very helpful.

And if you feel to do the complete job that will be even more awesome. Also 
feel free to discuss the design with me as the generics discovery code is kind 
of tricky.

Original comment by brice.du...@gmail.com on 24 Dec 2013 at 11:26

GoogleCodeExporter commented 8 years ago
Ok - thought that it will be faster ;) Will try to work on this in free time.

Original comment by marcin.g...@gmail.com on 24 Dec 2013 at 11:29

GoogleCodeExporter commented 8 years ago
PR for the non generic work - https://github.com/mockito/mockito/pull/30

Original comment by marcin.g...@gmail.com on 27 Dec 2013 at 12:37

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 24 Aug 2014 at 3:48