How to use SerializationTest class of org.easymock.tests2 package

Best Easymock code snippet using org.easymock.tests2.SerializationTest

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/**
2 * Copyright 2001-2013 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.easymock.tests2;
17
18import static org.easymock.EasyMock.*;
19import static org.junit.Assert.*;
20
21import java.io.*;
22import java.util.ArrayList;
23import java.util.List;
24
25import org.junit.Ignore;
26import org.junit.Test;
27
28/**
29 * @author Henri Tremblay
30 */
31public class SerializationTest implements Serializable {
32
33    private static final long serialVersionUID = -774994679161263654L;
34
35    @SuppressWarnings("unchecked")
36    @Test
37    public void test() throws Exception {
38
39        List<String> mock = createMock(List.class);
40
41        mock = serialize(mock);
42
43        expect(mock.get(1)).andReturn("a");
44
45        mock = serialize(mock);
46
47        replay(mock);
48
49        mock = serialize(mock);
50
51        assertEquals("a", mock.get(1));
52
53        mock = serialize(mock);
54
55        verify(mock);
56    }
57
58    @SuppressWarnings("unchecked")
59    @Test
60    public void testClass() throws Exception {
61
62        ArrayList<String> mock = createMockBuilder(ArrayList.class).addMockedMethod("get").withConstructor()
63                .createMock();
64
65        mock = serialize(mock);
66
67        expect(mock.get(1)).andReturn("a");
68
69        mock = serialize(mock);
70
71        replay(mock);
72
73        mock = serialize(mock);
74
75        assertEquals("a", mock.get(1));
76
77        mock = serialize(mock);
78
79        verify(mock);
80    }
81
82    @Test
83    public void testAllMockedMethod() throws Exception {
84
85        SerializationTest mock = createMock(SerializationTest.class);
86
87        mock = serialize(mock);
88
89        mock.test();
90
91        mock = serialize(mock);
92
93        replay(mock);
94
95        mock = serialize(mock);
96
97        mock.test();
98
99        mock = serialize(mock);
100
101        verify(mock);
102    }
103
104    @Test
105    @Ignore
106    // to code one day to make sure we can recreate a mock in another class loader
107    public void testChangingClassLoader() {
108
109    }
110
111    @SuppressWarnings("unchecked")
112    private <T> T serialize(T o) throws IOException, ClassNotFoundException {
113        final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
114        final ObjectOutputStream out = new ObjectOutputStream(bOut);
115        out.writeObject(o);
116        out.close();
117
118        final ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
119        final ObjectInputStream in = new ObjectInputStream(bIn);
120        o = (T) in.readObject();
121        in.close();
122
123        return o;
124    }
125}
126
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on SerializationTest

    No relevant questions found for this class 😞

Most used methods in SerializationTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)