/*
 * Copyright (C) 2017 Information Management Services, Inc.
 */
package com.imsweb.geocoder;

import org.junit.Assert;
import org.junit.Test;

import junitx.util.PrivateAccessor;

public class GeocodeOutputTest {

    // The important behavior in the GeocodeOutput class is tested in GeocoderTest, but wanted a test for some of the helper methods
    @Test
    public void testIntValue() throws Throwable {
        GeocodeOutput go = new GeocodeOutput();
        Class[] clazz = {String.class};

        Object[] param = {"7"};
        Object result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertTrue(result instanceof Integer);       //Probably not necessary but should definitely fail if not true
        Assert.assertEquals(7, result);

        param = new Object[] {"2222"};
        result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertEquals(2222, result);

        param = new Object[] {"2222.7"};
        result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertNull(result);

        param = new Object[] {""};
        result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertNull(result);

        param = new Object[] {"not a number"};
        result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertNull(result);

        param = new Object[] {null};
        result = PrivateAccessor.invoke(go, "intValue", clazz, param);
        Assert.assertNull(result);
    }

    @Test
    public void testdoubleValue() throws Throwable {
        GeocodeOutput go = new GeocodeOutput();
        Class[] clazz = {String.class};

        Object[] param = {"7"};
        Object result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertTrue(result instanceof Double);       //Probably not necessary but should definitely fail if not true
        Assert.assertEquals(7D, result);

        param = new Object[] {"2222"};
        result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertEquals(2222D, result);

        param = new Object[] {"2222.7"};
        result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertEquals(2222.7, result);

        param = new Object[] {""};
        result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertNull(result);

        param = new Object[] {"not a number"};
        result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertNull(result);

        param = new Object[] {null};
        result = PrivateAccessor.invoke(go, "doubleValue", clazz, param);
        Assert.assertNull(result);
    }

}

@@ -407,56 +407,8 @@
 e %7B%0A
-        GeocodeOutput go = new GeocodeOutput();%0A
     
@@ -408,32 +408,35 @@
  %7B%0A        Class
+%3C?%3E
 %5B%5D clazz = %7BStri
@@ -518,34 +518,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22intValue%22, cl
@@ -810,34 +810,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22intValue%22, cl
@@ -983,34 +983,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22intValue%22, cl
@@ -1142,34 +1142,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22intValue%22, cl
@@ -1313,34 +1313,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22intValue%22, cl
@@ -1482,18 +1482,35 @@
 .invoke(
-go
+GeocodeOutput.class
 , %22intVa
@@ -1639,56 +1639,8 @@
 e %7B%0A
-        GeocodeOutput go = new GeocodeOutput();%0A
     
@@ -1648,16 +1648,19 @@
    Class
+%3C?%3E
 %5B%5D clazz
@@ -1750,34 +1750,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22doubleValue%22,
@@ -2045,34 +2045,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22doubleValue%22,
@@ -2222,34 +2222,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22doubleValue%22,
@@ -2394,34 +2394,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22doubleValue%22,
@@ -2568,34 +2568,51 @@
 Accessor.invoke(
-go
+GeocodeOutput.class
 , %22doubleValue%22,
@@ -2744,10 +2744,27 @@
 oke(
-go
+GeocodeOutput.class
 , %22d

Fix raw type warning