package java7.reflection;

import java.lang.reflect.Array;
import libs.junit.UnitTestRunner;
import org.junit.Test;
import static org.junit.Assert.*;

public class ArrayGetTest {

    public static void main(String[] args) {
        UnitTestRunner.run(ArrayGetTest.class);
    }

    @Test
    public void getNullArray() {
        try {
            Object x = null;
            Array.get(x, 3);
            fail();
        } catch (NullPointerException e) {
            assertNull(e.getMessage());
        }
    }

    @Test
    public void getNonArray() {
        try {
            String str = "abc";
            Array.get(str, 1);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("Argument is not an array", e.getMessage());
        }
    }

    @Test
    public void getArrayBadIndex() {
        try {
            int[] arr = {1, 2, 3};
            Array.get(arr, -1);
            fail();
        } catch (ArrayIndexOutOfBoundsException e) {
            assertEquals(null, e.getMessage());
        }
    }

    @Test
    public void getObjectArray() {
        String[] arr = {"a", "b", "c"};
        assertEquals("c", Array.get(arr, 2));
    }
    
    @Test
    public void getPrimitiveArray() {
        int[] arr = {1, 2, 3};
        Object two = Array.get(arr, 1);
        assertEquals(2, two);
    }

}

@@ -1249,98 +1249,533 @@
     
-int%5B%5D arr = %7B1, 2, 3%7D;%0A        Object two = Array.get(arr, 1);%0A        assertEquals(2, two
+assertEquals(true,     Array.get(new boolean%5B%5D%7Btrue%7D, 0));%0A        assertEquals((byte)2,  Array.get(new byte%5B%5D%7B2%7D,       0));%0A        assertEquals('a',      Array.get(new char%5B%5D%7B'a'%7D,     0));%0A        assertEquals((short)2, Array.get(new short%5B%5D%7B2%7D,      0));%0A        assertEquals(2,        Array.get(new int%5B%5D%7B2%7D,        0));%0A        assertEquals(2L,       Array.get(new long%5B%5D%7B2%7D,       0));%0A        assertEquals(3.14f,    Array.get(new float%5B%5D%7B3.14f%7D,  0));%0A        assertEquals(2.71,     Array.get(new double%5B%5D%7B2.71%7D,  0)
 );%0A 

test Array.get()