View Javadoc
1   /*
2    * This file is part of dependency-check-core.
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   *
16   * Copyright (c) 2016 Jeremy Long. All Rights Reserved.
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   * @author jeremy
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       * Test of resolveClass method, of class ExpectedOjectInputStream.
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       * Test of resolveClass method, of class ExpectedOjectInputStream.
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  }