1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.utils;
19
20 import java.io.BufferedOutputStream;
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.ObjectOutputStream;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.After;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31
32
33
34
35
36 public class ExpectedOjectInputStreamTest {
37
38 public ExpectedOjectInputStreamTest() {
39 }
40
41 @BeforeClass
42 public static void setUpClass() {
43 }
44
45 @AfterClass
46 public static void tearDownClass() {
47 }
48
49 @Before
50 public void setUp() {
51 }
52
53 @After
54 public void tearDown() {
55 }
56
57
58
59
60 @Test
61 public void testResolveClass() throws Exception {
62 List<SimplePojo> data = new ArrayList<SimplePojo>();
63 data.add(new SimplePojo());
64
65 ByteArrayOutputStream mem = new ByteArrayOutputStream();
66 ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(mem));
67 out.writeObject(data);
68 out.flush();
69 byte[] buf = mem.toByteArray();
70 out.close();
71 ByteArrayInputStream in = new ByteArrayInputStream(buf);
72
73 ExpectedOjectInputStream instance = new ExpectedOjectInputStream(in, "java.util.ArrayList", "org.owasp.dependencycheck.utils.SimplePojo", "java.lang.Integer", "java.lang.Number");
74 instance.readObject();
75 }
76
77
78
79
80 @Test(expected = java.io.InvalidClassException.class)
81 public void testResolveClassException() throws Exception {
82 List<SimplePojo> data = new ArrayList<SimplePojo>();
83 data.add(new SimplePojo());
84
85 ByteArrayOutputStream mem = new ByteArrayOutputStream();
86 ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(mem));
87 out.writeObject(data);
88 out.flush();
89 byte[] buf = mem.toByteArray();
90 out.close();
91 ByteArrayInputStream in = new ByteArrayInputStream(buf);
92
93 ExpectedOjectInputStream instance = new ExpectedOjectInputStream(in, "java.util.ArrayList", "org.owasp.dependencycheck.utils.SimplePojo");
94 instance.readObject();
95 }
96 }