Author: adc
Date: Mon Aug 22 14:07:41 2011
New Revision: 1160269

URL: http://svn.apache.org/viewvc?rev=1160269&view=rev
Log:
Some unit tests

Added:
    
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumFilterTest.java
    mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilterTest.java
    mina/sandbox/adc/ahc/test/
    mina/sandbox/adc/ahc/test/pom.xml
    mina/sandbox/adc/ahc/test/src/
    mina/sandbox/adc/ahc/test/src/main/
    mina/sandbox/adc/ahc/test/src/main/java/
    mina/sandbox/adc/ahc/test/src/main/java/org/
    mina/sandbox/adc/ahc/test/src/main/java/org/apache/
    mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/
    mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/
    mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/Utils.java
    mina/sandbox/adc/ahc/test/src/test/
    mina/sandbox/adc/ahc/test/src/test/java/
    mina/sandbox/adc/ahc/test/src/test/java/org/
    mina/sandbox/adc/ahc/test/src/test/java/org/apache/
    mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/
    mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/
    mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/Pojo.java
    mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/UtilsTest.java
Modified:
    mina/sandbox/adc/ahc/mina3/pom.xml
    mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumConfig.java
    mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilter.java
    mina/sandbox/adc/ahc/pom.xml

Modified: mina/sandbox/adc/ahc/mina3/pom.xml
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/pom.xml?rev=1160269&r1=1160268&r2=1160269&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/pom.xml (original)
+++ mina/sandbox/adc/ahc/mina3/pom.xml Mon Aug 22 14:07:41 2011
@@ -53,6 +53,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.ahc</groupId>
+            <artifactId>test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

Modified: 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumConfig.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumConfig.java?rev=1160269&r1=1160268&r2=1160269&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumConfig.java 
(original)
+++ mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumConfig.java 
Mon Aug 22 14:07:41 2011
@@ -26,6 +26,17 @@ public class ChecksumConfig
     private String algorithm;
     private String charsetName = "UTF8";
 
+    public ChecksumConfig()
+    {
+        this("MD5", "UTF8");
+    }
+
+    public ChecksumConfig(String algorithm, String charsetName)
+    {
+        this.algorithm = algorithm;
+        this.charsetName = charsetName;
+    }
+
     public String getAlgorithm()
     {
         return algorithm;

Added: 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumFilterTest.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumFilterTest.java?rev=1160269&view=auto
==============================================================================
--- 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumFilterTest.java 
(added)
+++ 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/ChecksumFilterTest.java 
Mon Aug 22 14:07:41 2011
@@ -0,0 +1,80 @@
+/**
+ * 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 com.acme.chain;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import static org.apache.ahc.test.Utils.inject;
+import org.apache.commons.codec.binary.Hex;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.mina.core.api.IoDown;
+import org.apache.mina.core.api.IoUp;
+
+
+/**
+ * @author <a href="http://mina.apache.org";>Apache MINA Project</a>
+ */
+public class ChecksumFilterTest
+{
+    protected static MessageDigest md;
+
+    @Test
+    public void test() throws Exception
+    {
+        ChecksumFilter filter = new ChecksumFilter();
+
+        IoDown<String> down = mock(IoDown.class);
+        IoUp<String> up = mock(IoUp.class);
+        inject(filter, "child", down);
+        inject(filter, "parent", up);
+        inject(filter, "config", new ChecksumConfig());
+
+        filter.init();
+        filter.send("TEST");
+        filter.receive(encode("REPLY"));
+
+        verify(down).send(encode("TEST"));
+        verify(up).receive("REPLY");
+    }
+
+    protected String encode(String message) throws UnsupportedEncodingException
+    {
+        md.reset();
+        byte[] digest = md.digest(message.getBytes("UTF-8"));
+
+        StringBuilder builder = new StringBuilder();
+        builder.append(String.valueOf(Hex.encodeHex(digest)));
+        builder.append(":");
+        builder.append(message);
+
+        return builder.toString();
+    }
+
+    @BeforeClass
+    public static void setup() throws NoSuchAlgorithmException
+    {
+        md = MessageDigest.getInstance("MD5");
+    }
+}

Modified: 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilter.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilter.java?rev=1160269&r1=1160268&r2=1160269&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilter.java 
(original)
+++ mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilter.java Mon 
Aug 22 14:07:41 2011
@@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
 import org.apache.mina.core.AbstractIoFilter;
 import org.apache.mina.core.api.IoChild;
 import org.apache.mina.core.api.IoDown;
-import org.apache.mina.core.api.IoParent;
 import org.apache.mina.core.api.IoUp;
 
 
@@ -34,19 +33,8 @@ import org.apache.mina.core.api.IoUp;
 public class EchoFilter extends AbstractIoFilter implements IoUp<String>, 
IoDown<String>
 {
     static final Logger LOG = LoggerFactory.getLogger(EchoFilter.class);
-    @IoParent protected IoUp<String> parent;
     @IoChild protected IoDown<String> child;
 
-    public IoUp<String> getParent()
-    {
-        return parent;
-    }
-
-    public void setParent(IoUp<String> parent)
-    {
-        this.parent = parent;
-    }
-
     public IoDown<String> getChild()
     {
         return child;
@@ -60,12 +48,14 @@ public class EchoFilter extends Abstract
     @Override
     public void send(String message) throws Exception
     {
+        LOG.trace("Sending message {}", message);
         child.send(message);
     }
 
     @Override
     public void receive(String message) throws Exception
     {
+        LOG.trace("Echoing message {}", message);
         child.send(message);
     }
 }

Added: 
mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilterTest.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilterTest.java?rev=1160269&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilterTest.java 
(added)
+++ mina/sandbox/adc/ahc/mina3/src/test/java/com/acme/chain/EchoFilterTest.java 
Mon Aug 22 14:07:41 2011
@@ -0,0 +1,54 @@
+/**
+ * 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 com.acme.chain;
+
+import static org.apache.ahc.test.Utils.inject;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Matchers;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import org.apache.mina.core.api.IoDown;
+import org.apache.mina.core.api.IoUp;
+
+
+/**
+ * @author <a href="http://mina.apache.org";>Apache MINA Project</a>
+ */
+public class EchoFilterTest
+{
+    @Test
+    public void test() throws Exception
+    {
+        EchoFilter filter = new EchoFilter();
+
+        IoDown<String> down = mock(IoDown.class);
+        inject(filter, "child", down);
+
+        filter.send("DOWN");
+        filter.receive("ECHO");
+
+        InOrder order = inOrder(down);
+        order.verify(down).send("DOWN");
+        order.verify(down).send("ECHO");
+    }
+}

Modified: mina/sandbox/adc/ahc/pom.xml
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/pom.xml?rev=1160269&r1=1160268&r2=1160269&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/pom.xml (original)
+++ mina/sandbox/adc/ahc/pom.xml Mon Aug 22 14:07:41 2011
@@ -40,6 +40,7 @@
         <module>common</module>
         <module>mina2</module>
         <module>mina3</module>
+        <module>test</module>
     </modules>
 
     <build>
@@ -64,6 +65,7 @@
         <log4jVersion>1.2.14</log4jVersion>
         <slf4jVersion>1.6.1</slf4jVersion>
     </properties>
+
     <dependencies>
 
         <dependency>
@@ -104,6 +106,12 @@
             </dependency>
 
             <dependency>
+                <groupId>org.apache.ahc</groupId>
+                <artifactId>test</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-api</artifactId>
                 <version>${slf4jVersion}</version>

Added: mina/sandbox/adc/ahc/test/pom.xml
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/test/pom.xml?rev=1160269&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/test/pom.xml (added)
+++ mina/sandbox/adc/ahc/test/pom.xml Mon Aug 22 14:07:41 2011
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ahc</groupId>
+        <artifactId>ahc-project</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>test</artifactId>
+    <name>Apache Asynchronous HTTP Client :: Test</name>
+    <packaging>jar</packaging>
+    <description>Code to assist in testing</description>
+
+    <build/>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/Utils.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/Utils.java?rev=1160269&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/Utils.java 
(added)
+++ mina/sandbox/adc/ahc/test/src/main/java/org/apache/ahc/test/Utils.java Mon 
Aug 22 14:07:41 2011
@@ -0,0 +1,94 @@
+/**
+ * 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.ahc.test;
+
+import java.lang.reflect.Field;
+
+
+/**
+ * @author <a href="http://mina.apache.org";>Apache MINA Project</a>
+ */
+public class Utils
+{
+    public static <T> void inject(Object object, String property, T value) 
throws NoSuchFieldException
+    {
+        if (object == null) throw new IllegalArgumentException("Object cannot 
be null");
+        if (property == null) throw new IllegalArgumentException("Property 
name cannot be null");
+        if (value == null) throw new IllegalArgumentException("Value cannot be 
null");
+
+        Field field = object.getClass().getDeclaredField(property);
+
+        boolean accessible = field.isAccessible();
+        if (!accessible) field.setAccessible(true);
+
+        try
+        {
+            if (value instanceof Boolean) field.setBoolean(object, 
(Boolean)value);
+            else if (value instanceof Byte) field.setByte(object, (Byte)value);
+            else if (value instanceof Character) field.setChar(object, 
(Character)value);
+            else if (value instanceof Double) field.setDouble(object, 
(Double)value);
+            else if (value instanceof Float) field.setFloat(object, 
(Float)value);
+            else if (value instanceof Integer) field.setInt(object, 
(Integer)value);
+            else if (value instanceof Long) field.setLong(object, (Long)value);
+            else field.set(object, value);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new Error("Should have been able to inject a value");
+        }
+        finally
+        {
+            if (!accessible) field.setAccessible(false);
+        }
+    }
+
+    public static Object extract(Object object, String property) throws 
NoSuchFieldException
+    {
+        if (object == null) throw new IllegalArgumentException("Object cannot 
be null");
+        if (property == null) throw new IllegalArgumentException("Property 
name cannot be null");
+
+        Field field = object.getClass().getDeclaredField(property);
+
+        boolean accessible = field.isAccessible();
+        if (!accessible) field.setAccessible(true);
+
+        try
+        {
+            Class type = field.getType();
+            if (type == Boolean.class) return field.get(object);
+            else if (type == Byte.class) return field.getByte(object);
+            else if (type == Character.class) return field.getChar(object);
+            else if (type == Double.class) return field.getDouble(object);
+            else if (type == Float.class) return field.getFloat(object);
+            else if (type == Integer.class) return field.getInt(object);
+            else if (type == Long.class) return field.getLong(object);
+            else return field.get(object);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new Error("Should have been able to inject a value");
+        }
+        finally
+        {
+            if (!accessible) field.setAccessible(false);
+        }
+    }
+
+    private Utils() { }
+}

Added: mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/Pojo.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/Pojo.java?rev=1160269&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/Pojo.java 
(added)
+++ mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/Pojo.java Mon 
Aug 22 14:07:41 2011
@@ -0,0 +1,114 @@
+/**
+ * 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.ahc.test;
+
+/**
+ * @author <a href="http://mina.apache.org";>Apache MINA Project</a>
+ */
+public class Pojo
+{
+    private boolean booleanValue;
+    private byte byteValue;
+    private char charValue;
+    private double doubleValue;
+    private float floatValue;
+    private int intValue;
+    private long longValue;
+    private Object objectValue;
+
+    public boolean isBooleanValue()
+    {
+        return booleanValue;
+    }
+
+    public void setBooleanValue(boolean booleanValue)
+    {
+        this.booleanValue = booleanValue;
+    }
+
+    public byte getByteValue()
+    {
+        return byteValue;
+    }
+
+    public void setByteValue(byte byteValue)
+    {
+        this.byteValue = byteValue;
+    }
+
+    public char getCharValue()
+    {
+        return charValue;
+    }
+
+    public void setCharValue(char charValue)
+    {
+        this.charValue = charValue;
+    }
+
+    public double getDoubleValue()
+    {
+        return doubleValue;
+    }
+
+    public void setDoubleValue(double doubleValue)
+    {
+        this.doubleValue = doubleValue;
+    }
+
+    public float getFloatValue()
+    {
+        return floatValue;
+    }
+
+    public void setFloatValue(float floatValue)
+    {
+        this.floatValue = floatValue;
+    }
+
+    public int getIntValue()
+    {
+        return intValue;
+    }
+
+    public void setIntValue(int intValue)
+    {
+        this.intValue = intValue;
+    }
+
+    public long getLongValue()
+    {
+        return longValue;
+    }
+
+    public void setLongValue(long longValue)
+    {
+        this.longValue = longValue;
+    }
+
+    public Object getObjectValue()
+    {
+        return objectValue;
+    }
+
+    public void setObjectValue(Object objectValue)
+    {
+        this.objectValue = objectValue;
+    }
+}

Added: 
mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/UtilsTest.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/UtilsTest.java?rev=1160269&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/UtilsTest.java 
(added)
+++ mina/sandbox/adc/ahc/test/src/test/java/org/apache/ahc/test/UtilsTest.java 
Mon Aug 22 14:07:41 2011
@@ -0,0 +1,80 @@
+/**
+ * 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.ahc.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+
+/**
+ * @author <a href="http://mina.apache.org";>Apache MINA Project</a>
+ */
+public class UtilsTest
+{
+    @Test
+    public void testInject() throws Exception
+    {
+        String name = "Yoko";
+        Pojo pojo = new Pojo();
+
+        Utils.inject(pojo, "booleanValue", true);
+        Utils.inject(pojo, "byteValue", (byte)0xCA);
+        Utils.inject(pojo, "charValue", 'x');
+        Utils.inject(pojo, "doubleValue", Double.MAX_VALUE);
+        Utils.inject(pojo, "floatValue", Float.MAX_VALUE);
+        Utils.inject(pojo, "intValue", Integer.MAX_VALUE);
+        Utils.inject(pojo, "longValue", Long.MAX_VALUE);
+        Utils.inject(pojo, "objectValue", name);
+
+        assertTrue(pojo.isBooleanValue());
+        assertEquals((Byte)pojo.getByteValue(), Byte.valueOf((byte)0xCA));
+        assertEquals(pojo.getCharValue(), 'x');
+        assertEquals(pojo.getDoubleValue(), Double.MAX_VALUE, 0.0000001);
+        assertEquals(pojo.getFloatValue(), Float.MAX_VALUE, 0.0000001);
+        assertEquals(pojo.getIntValue(), Integer.MAX_VALUE);
+        assertEquals(pojo.getLongValue(), Long.MAX_VALUE);
+        assertEquals(pojo.getObjectValue(), name);
+    }
+
+    @Test
+    public void testExtract() throws Exception
+    {
+        String name = "Yoko";
+        Pojo pojo = new Pojo();
+
+        pojo.setBooleanValue(true);
+        pojo.setByteValue((byte)0xCA);
+        pojo.setCharValue('x');
+        pojo.setDoubleValue(Double.MAX_VALUE);
+        pojo.setFloatValue(Float.MAX_VALUE);
+        pojo.setIntValue(Integer.MAX_VALUE);
+        pojo.setLongValue(Long.MAX_VALUE);
+        pojo.setObjectValue(name);
+
+        assertTrue((Boolean)Utils.extract(pojo, "booleanValue"));
+        assertEquals((Byte)Utils.extract(pojo, "byteValue"), 
Byte.valueOf((byte)0xCA));
+        assertEquals(Utils.extract(pojo, "charValue"), 'x');
+        assertEquals(Utils.extract(pojo, "doubleValue"), Double.MAX_VALUE);
+        assertEquals(Utils.extract(pojo, "floatValue"), Float.MAX_VALUE);
+        assertEquals(Utils.extract(pojo, "intValue"), Integer.MAX_VALUE);
+        assertEquals(Utils.extract(pojo, "longValue"), Long.MAX_VALUE);
+        assertEquals(Utils.extract(pojo, "objectValue"), name);
+    }
+}


Reply via email to