/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io.input;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import junit.framework.TestCase;

/**
 * Tests the CountingInputStream.
 *
 * @version $Id$
 */
public class ClassLoaderObjectInputStreamTest extends TestCase {

    public ClassLoaderObjectInputStreamTest(final String name) {
        super(name);
    }

    /* Note: This test case tests the simplest functionality of
     * ObjectInputStream.  IF we really wanted to test ClassLoaderObjectInputStream
     * we would probably need to create a transient Class Loader. -TO
     */

    
    public void testExpected() throws Exception {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);

        final Object input = Boolean.FALSE;
        oos.writeObject( input );

        final InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ClassLoaderObjectInputStream clois = 
            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
        final Object result = clois.readObject();

        assertEquals(input, result );
        clois.close();
    }

    public void testLong() throws Exception {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);

        final Object input = Long.valueOf(123);
        oos.writeObject(input);

        final InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ClassLoaderObjectInputStream clois = 
            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
        final Object result = clois.readObject();

        assertEquals(input, result);
        clois.close();
    }

    public void testPrimitiveLong() throws Exception {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);

        final long input = 12345L;
        oos.writeLong(input);
        oos.close();

        final InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ClassLoaderObjectInputStream clois = 
            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
        final long result = clois.readLong();

        assertEquals(input, result);
        clois.close();
    }

    private static class Test implements Serializable {
        private static final long serialVersionUID = 1L;
        private int i;

        Test(int i) {
            this.i = i;
        }
        @Override
        public boolean equals(Object other) {
            return other instanceof Test & (this.i == ((Test)other).i);
        }
        @Override
        public int hashCode() {
            return super.hashCode();
        }
    }

    public void testObject() throws Exception {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);

        final Object input = new Test(123);
        oos.writeObject(input);
        oos.close();

        final InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ClassLoaderObjectInputStream clois = 
            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
        final Object result = clois.readObject();

        assertEquals(input, result);
        clois.close();
    }

    public void testResolveProxyClass() throws Exception {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject( Boolean.FALSE );
        final InputStream bais = new ByteArrayInputStream(baos.toByteArray());

        final ClassLoaderObjectInputStream clois = 
            new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais);
        final String[] interfaces = new String[] { Comparable.class.getName() };
        final Class<?> result = clois.resolveProxyClass(interfaces);
        assertTrue("Assignable", Comparable.class.isAssignableFrom(result));
        clois.close();
    }
    
}

@@ -3301,24 +3301,60 @@
 e();%0A    %7D%0A%0A
+    private static enum E%7BA, B, C%7D%0A%0A
     private 
@@ -3397,16 +3397,16 @@
 zable %7B%0A
-
         
@@ -3478,16 +3478,38 @@
 int i;%0A%0A
+        private E e;%0A%0A
         
@@ -3546,16 +3546,42 @@
 .i = i;%0A
+            this.e = E.A;%0A
         
@@ -3658,23 +3658,20 @@
         
-return 
+if (
 other in
@@ -3687,39 +3687,212 @@
 Test
- & (this.i == ((Test)other).i);
+) %7B%0A                Test tother = (Test) other;%0A                return (this.i == tother.i)%0A                        & (this.e == tother.e);%0A            %7D else %7B%0A                return false;%0A            %7D
 %0A   

Add some more fields to the test class