Home | History | Annotate | Download | only in reflect
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package tests.api.java.lang.reflect;
     19 
     20 import dalvik.annotation.TestTargets;
     21 import dalvik.annotation.TestLevel;
     22 import dalvik.annotation.TestTargetNew;
     23 import dalvik.annotation.TestTargetClass;
     24 
     25 import java.lang.reflect.Array;
     26 
     27 @TestTargetClass(Array.class)
     28 public class ArrayTest extends junit.framework.TestCase {
     29 
     30     /**
     31      * @tests java.lang.reflect.Array#get(java.lang.Object, int)
     32      */
     33     @TestTargetNew(
     34         level = TestLevel.COMPLETE,
     35         notes = "",
     36         method = "get",
     37         args = {java.lang.Object.class, int.class}
     38     )
     39     public void test_getLjava_lang_ObjectI() {
     40         // Test for method java.lang.Object
     41         // java.lang.reflect.Array.get(java.lang.Object, int)
     42 
     43         int[] x = { 1 };
     44         Object ret = null;
     45         boolean thrown = false;
     46         try {
     47             ret = Array.get(x, 0);
     48         } catch (Exception e) {
     49             fail("Exception during get test : " + e.getMessage());
     50         }
     51         assertEquals("Get returned incorrect value",
     52                 1, ((Integer) ret).intValue());
     53         try {
     54             ret = Array.get(new Object(), 0);
     55         } catch (IllegalArgumentException e) {
     56             // Correct behaviour
     57             thrown = true;
     58         }
     59         if (!thrown) {
     60             fail("Passing non-array failed to throw exception");
     61         }
     62         thrown = false;
     63         try {
     64             ret = Array.get(x, 4);
     65         } catch (ArrayIndexOutOfBoundsException e) {
     66             // Correct behaviour
     67             thrown = true;
     68         }
     69         if (!thrown) {
     70             fail("Invalid index failed to throw exception");
     71         }
     72 
     73         //same test with non primitive component type
     74         Integer[] y = new Integer[]{ 1 };
     75         ret = null;
     76         thrown = false;
     77         try {
     78             ret = Array.get(y, 0);
     79         } catch (Exception e) {
     80             fail("Exception during get test : " + e.getMessage());
     81         }
     82         assertEquals("Get returned incorrect value",
     83                 1, ((Integer) ret).intValue());
     84         try {
     85             ret = Array.get(new Object(), 0);
     86         } catch (IllegalArgumentException e) {
     87             // Correct behaviour
     88             thrown = true;
     89         }
     90         if (!thrown) {
     91             fail("Passing non-array failed to throw exception");
     92         }
     93         thrown = false;
     94         try {
     95             ret = Array.get(y, 4);
     96         } catch (ArrayIndexOutOfBoundsException e) {
     97             // Correct behaviour
     98             thrown = true;
     99         }
    100         if (!thrown) {
    101             fail("Invalid index failed to throw exception");
    102         }
    103     }
    104 
    105     /**
    106      * @tests java.lang.reflect.Array#getBoolean(java.lang.Object, int)
    107      */
    108     @TestTargetNew(
    109         level = TestLevel.COMPLETE,
    110         notes = "",
    111         method = "getBoolean",
    112         args = {java.lang.Object.class, int.class}
    113     )
    114     public void test_getBooleanLjava_lang_ObjectI() {
    115         // Test for method boolean
    116         // java.lang.reflect.Array.getBoolean(java.lang.Object, int)
    117         boolean[] x = { true };
    118         boolean ret = false;
    119         boolean thrown = false;
    120         try {
    121             ret = Array.getBoolean(x, 0);
    122         } catch (Exception e) {
    123             fail("Exception during get test : " + e.getMessage());
    124         }
    125         assertTrue("Get returned incorrect value", ret);
    126         try {
    127             ret = Array.getBoolean(new Object(), 0);
    128         } catch (IllegalArgumentException e) {
    129             // Correct behaviour
    130             thrown = true;
    131         }
    132         if (!thrown) {
    133             fail("Passing non-array failed to throw exception");
    134         }
    135         thrown = false;
    136         try {
    137             ret = Array.getBoolean(x, 4);
    138         } catch (ArrayIndexOutOfBoundsException e) {
    139             // Correct behaviour
    140             thrown = true;
    141         }
    142         if (!thrown) {
    143             fail("Invalid index failed to throw exception");
    144         }
    145         thrown = false;
    146         try {
    147             ret = Array.getBoolean(null, 0);
    148         } catch (NullPointerException e) {
    149             // Correct behaviour
    150             thrown = true;
    151         }
    152         if (!thrown) {
    153             fail("Null argument failed to throw NPE");
    154         }
    155     }
    156 
    157     /**
    158      * @tests java.lang.reflect.Array#getByte(java.lang.Object, int)
    159      */
    160     @TestTargetNew(
    161         level = TestLevel.COMPLETE,
    162         notes = "",
    163         method = "getByte",
    164         args = {java.lang.Object.class, int.class}
    165     )
    166     public void test_getByteLjava_lang_ObjectI() {
    167         // Test for method byte
    168         // java.lang.reflect.Array.getByte(java.lang.Object, int)
    169         byte[] x = { 1 };
    170         byte ret = 0;
    171         boolean thrown = false;
    172         try {
    173             ret = Array.getByte(x, 0);
    174         } catch (Exception e) {
    175             fail("Exception during get test : " + e.getMessage());
    176         }
    177         assertEquals("Get returned incorrect value", 1, ret);
    178         try {
    179             ret = Array.getByte(new Object(), 0);
    180         } catch (IllegalArgumentException e) {
    181             // Correct behaviour
    182             thrown = true;
    183         }
    184         if (!thrown) {
    185             fail("Passing non-array failed to throw exception");
    186         }
    187         thrown = false;
    188         try {
    189             ret = Array.getByte(x, 4);
    190         } catch (ArrayIndexOutOfBoundsException e) {
    191             // Correct behaviour
    192             thrown = true;
    193         }
    194         if (!thrown) {
    195             fail("Invalid index failed to throw exception");
    196         }
    197         thrown = false;
    198         try {
    199             ret = Array.getByte(null, 0);
    200         } catch (NullPointerException e) {
    201             // Correct behaviour
    202             thrown = true;
    203         }
    204         if (!thrown) {
    205             fail("Null argument failed to throw NPE");
    206         }
    207     }
    208 
    209     /**
    210      * @tests java.lang.reflect.Array#getChar(java.lang.Object, int)
    211      */
    212     @TestTargetNew(
    213         level = TestLevel.COMPLETE,
    214         notes = "",
    215         method = "getChar",
    216         args = {java.lang.Object.class, int.class}
    217     )
    218     public void test_getCharLjava_lang_ObjectI() {
    219         // Test for method char
    220         // java.lang.reflect.Array.getChar(java.lang.Object, int)
    221         char[] x = { 1 };
    222         char ret = 0;
    223         boolean thrown = false;
    224         try {
    225             ret = Array.getChar(x, 0);
    226         } catch (Exception e) {
    227             fail("Exception during get test : " + e.getMessage());
    228         }
    229         assertEquals("Get returned incorrect value", 1, ret);
    230         try {
    231             ret = Array.getChar(new Object(), 0);
    232         } catch (IllegalArgumentException e) {
    233             // Correct behaviour
    234             thrown = true;
    235         }
    236         if (!thrown) {
    237             fail("Passing non-array failed to throw exception");
    238         }
    239         thrown = false;
    240         try {
    241             ret = Array.getChar(x, 4);
    242         } catch (ArrayIndexOutOfBoundsException e) {
    243             // Correct behaviour
    244             thrown = true;
    245         }
    246         if (!thrown) {
    247             fail("Invalid index failed to throw exception");
    248         }
    249         thrown = false;
    250         try {
    251             ret = Array.getChar(null, 0);
    252         } catch (NullPointerException e) {
    253             // Correct behaviour
    254             thrown = true;
    255         }
    256         if (!thrown) {
    257             fail("Null argument failed to throw NPE");
    258         }
    259     }
    260 
    261     /**
    262      * @tests java.lang.reflect.Array#getDouble(java.lang.Object, int)
    263      */
    264     @TestTargetNew(
    265         level = TestLevel.COMPLETE,
    266         notes = "",
    267         method = "getDouble",
    268         args = {java.lang.Object.class, int.class}
    269     )
    270     public void test_getDoubleLjava_lang_ObjectI() {
    271         // Test for method double
    272         // java.lang.reflect.Array.getDouble(java.lang.Object, int)
    273         double[] x = { 1 };
    274         double ret = 0;
    275         boolean thrown = false;
    276         try {
    277             ret = Array.getDouble(x, 0);
    278         } catch (Exception e) {
    279             fail("Exception during get test : " + e.getMessage());
    280         }
    281         assertEquals("Get returned incorrect value", 1, ret, 0.0);
    282         try {
    283             ret = Array.getDouble(new Object(), 0);
    284         } catch (IllegalArgumentException e) {
    285             // Correct behaviour
    286             thrown = true;
    287         }
    288 
    289         if (!thrown) {
    290             fail("Passing non-array failed to throw exception");
    291         }
    292         thrown = false;
    293         try {
    294             ret = Array.getDouble(x, 4);
    295         } catch (ArrayIndexOutOfBoundsException e) {
    296             // Correct behaviour
    297             thrown = true;
    298         }
    299         if (!thrown) {
    300             fail("Invalid index failed to throw exception");
    301         }
    302         thrown = false;
    303         try {
    304             ret = Array.getDouble(null, 0);
    305         } catch (NullPointerException e) {
    306             // Correct behaviour
    307             thrown = true;
    308         }
    309         if (!thrown) {
    310             fail("Null argument failed to throw NPE");
    311         }
    312     }
    313 
    314     /**
    315      * @tests java.lang.reflect.Array#getFloat(java.lang.Object, int)
    316      */
    317     @TestTargetNew(
    318         level = TestLevel.COMPLETE,
    319         notes = "",
    320         method = "getFloat",
    321         args = {java.lang.Object.class, int.class}
    322     )
    323     public void test_getFloatLjava_lang_ObjectI() {
    324         // Test for method float
    325         // java.lang.reflect.Array.getFloat(java.lang.Object, int)
    326         float[] x = { 1 };
    327         float ret = 0;
    328         boolean thrown = false;
    329         try {
    330             ret = Array.getFloat(x, 0);
    331         } catch (Exception e) {
    332             fail("Exception during get test : " + e.getMessage());
    333         }
    334         assertEquals("Get returned incorrect value", 1, ret, 0.0);
    335         try {
    336             ret = Array.getFloat(new Object(), 0);
    337         } catch (IllegalArgumentException e) {
    338             // Correct behaviour
    339             thrown = true;
    340         }
    341         if (!thrown) {
    342             fail("Passing non-array failed to throw exception");
    343         }
    344         thrown = false;
    345         try {
    346             ret = Array.getFloat(x, 4);
    347         } catch (ArrayIndexOutOfBoundsException e) {
    348             // Correct behaviour
    349             thrown = true;
    350         }
    351         if (!thrown) {
    352             fail("Invalid index failed to throw exception");
    353         }
    354         thrown = false;
    355         try {
    356             ret = Array.getFloat(null, 0);
    357         } catch (NullPointerException e) {
    358             // Correct behaviour
    359             thrown = true;
    360         }
    361         if (!thrown) {
    362             fail("Null argument failed to throw NPE");
    363         }
    364     }
    365 
    366     /**
    367      * @tests java.lang.reflect.Array#getInt(java.lang.Object, int)
    368      */
    369     @TestTargetNew(
    370         level = TestLevel.COMPLETE,
    371         notes = "",
    372         method = "getInt",
    373         args = {java.lang.Object.class, int.class}
    374     )
    375     public void test_getIntLjava_lang_ObjectI() {
    376         // Test for method int java.lang.reflect.Array.getInt(java.lang.Object,
    377         // int)
    378         int[] x = { 1 };
    379         int ret = 0;
    380         boolean thrown = false;
    381         try {
    382             ret = Array.getInt(x, 0);
    383         } catch (Exception e) {
    384             fail("Exception during get test : " + e.getMessage());
    385         }
    386         assertEquals("Get returned incorrect value", 1, ret);
    387         try {
    388             ret = Array.getInt(new Object(), 0);
    389         } catch (IllegalArgumentException e) {
    390             // Correct behaviour
    391             thrown = true;
    392         }
    393         if (!thrown) {
    394             fail("Passing non-array failed to throw exception");
    395         }
    396         thrown = false;
    397         try {
    398             ret = Array.getInt(x, 4);
    399         } catch (ArrayIndexOutOfBoundsException e) {
    400             // Correct behaviour
    401             thrown = true;
    402         }
    403         if (!thrown) {
    404             fail("Invalid index failed to throw exception");
    405         }
    406         thrown = false;
    407         try {
    408             ret = Array.getInt(null, 0);
    409         } catch (NullPointerException e) {
    410             // Correct behaviour
    411             thrown = true;
    412         }
    413         if (!thrown) {
    414             fail("Null argument failed to throw NPE");
    415         }
    416     }
    417 
    418     /**
    419      * @tests java.lang.reflect.Array#getLength(java.lang.Object)
    420      */
    421     @TestTargetNew(
    422         level = TestLevel.COMPLETE,
    423         notes = "",
    424         method = "getLength",
    425         args = {java.lang.Object.class}
    426     )
    427     public void test_getLengthLjava_lang_Object() {
    428         // Test for method int
    429         // java.lang.reflect.Array.getLength(java.lang.Object)
    430         long[] x = { 1 };
    431 
    432         assertEquals("Returned incorrect length", 1, Array.getLength(x));
    433         assertEquals("Returned incorrect length", 10000, Array
    434                 .getLength(new Object[10000]));
    435         try {
    436             Array.getLength(new Object());
    437         } catch (IllegalArgumentException e) {
    438             // Correct
    439             return;
    440         }
    441         fail("Failed to throw exception when passed non-array");
    442     }
    443 
    444     /**
    445      * @tests java.lang.reflect.Array#getLong(java.lang.Object, int)
    446      */
    447     @TestTargetNew(
    448         level = TestLevel.COMPLETE,
    449         notes = "",
    450         method = "getLong",
    451         args = {java.lang.Object.class, int.class}
    452     )
    453     public void test_getLongLjava_lang_ObjectI() {
    454         // Test for method long
    455         // java.lang.reflect.Array.getLong(java.lang.Object, int)
    456         long[] x = { 1 };
    457         long ret = 0;
    458         boolean thrown = false;
    459         try {
    460             ret = Array.getLong(x, 0);
    461         } catch (Exception e) {
    462             fail("Exception during get test : " + e.getMessage());
    463         }
    464         assertEquals("Get returned incorrect value", 1, ret);
    465         try {
    466             ret = Array.getLong(new Object(), 0);
    467         } catch (IllegalArgumentException e) {
    468             // Correct behaviour
    469             thrown = true;
    470         }
    471         if (!thrown) {
    472             fail("Passing non-array failed to throw exception");
    473         }
    474         thrown = false;
    475         try {
    476             ret = Array.getLong(x, 4);
    477         } catch (ArrayIndexOutOfBoundsException e) {
    478             // Correct behaviour
    479             thrown = true;
    480         }
    481         if (!thrown) {
    482             fail("Invalid index failed to throw exception");
    483         }
    484         thrown = false;
    485         try {
    486             ret = Array.getLong(null, 0);
    487         } catch (NullPointerException e) {
    488             // Correct behaviour
    489             thrown = true;
    490         }
    491         if (!thrown) {
    492             fail("Null argument failed to throw NPE");
    493         }
    494     }
    495 
    496     /**
    497      * @tests java.lang.reflect.Array#getShort(java.lang.Object, int)
    498      */
    499     @TestTargetNew(
    500         level = TestLevel.COMPLETE,
    501         notes = "",
    502         method = "getShort",
    503         args = {java.lang.Object.class, int.class}
    504     )
    505     public void test_getShortLjava_lang_ObjectI() {
    506         // Test for method short
    507         // java.lang.reflect.Array.getShort(java.lang.Object, int)
    508         short[] x = { 1 };
    509         short ret = 0;
    510         boolean thrown = false;
    511         try {
    512             ret = Array.getShort(x, 0);
    513         } catch (Exception e) {
    514             fail("Exception during get test : " + e.getMessage());
    515         }
    516         assertEquals("Get returned incorrect value", 1, ret);
    517         try {
    518             ret = Array.getShort(new Object(), 0);
    519         } catch (IllegalArgumentException e) {
    520             // Correct behaviour
    521             thrown = true;
    522         }
    523         if (!thrown) {
    524             fail("Passing non-array failed to throw exception");
    525         }
    526         thrown = false;
    527         try {
    528             ret = Array.getShort(x, 4);
    529         } catch (ArrayIndexOutOfBoundsException e) {
    530             // Correct behaviour
    531             thrown = true;
    532         }
    533         if (!thrown) {
    534             fail("Invalid index failed to throw exception");
    535         }
    536         thrown = false;
    537         try {
    538             ret = Array.getShort(null, 0);
    539         } catch (NullPointerException e) {
    540             // Correct behaviour
    541             thrown = true;
    542         }
    543         if (!thrown) {
    544             fail("Null argument failed to throw NPE");
    545         }
    546     }
    547 
    548     /**
    549      * @tests java.lang.reflect.Array#newInstance(java.lang.Class, int[])
    550      */
    551     @TestTargetNew(
    552         level = TestLevel.COMPLETE,
    553         notes = "",
    554         method = "newInstance",
    555         args = {java.lang.Class.class, int[].class}
    556     )
    557     public void test_newInstanceLjava_lang_Class$I() {
    558         // Test for method java.lang.Object
    559         // java.lang.reflect.Array.newInstance(java.lang.Class, int [])
    560         int[][] x;
    561         int[] y = { 2 };
    562 
    563         x = (int[][]) Array.newInstance(int[].class, y);
    564         assertEquals("Failed to instantiate array properly", 2, x.length);
    565 
    566         boolean thrown = false;
    567         try {
    568             x = (int[][]) Array.newInstance(null, y);
    569         } catch (NullPointerException e) {
    570             // Correct behaviour
    571             thrown = true;
    572         }
    573         if (!thrown) {
    574             fail("Null argument failed to throw NPE");
    575         }
    576 
    577         thrown = false;
    578         try {
    579             Array.newInstance(int[].class, new int[]{1,-1});
    580         } catch (NegativeArraySizeException e) {
    581             // Correct behaviour
    582             thrown = true;
    583         }
    584         if (!thrown) {
    585             fail("Negative array size failed to throw NegativeArraySizeException");
    586         }
    587 
    588         thrown = false;
    589         try {
    590             Array.newInstance(int[].class, new int[]{});
    591         } catch (IllegalArgumentException e) {
    592             // Correct behaviour
    593             thrown = true;
    594         }
    595         if (!thrown) {
    596             fail("Zero array size failed to throw IllegalArgumentException");
    597         }
    598     }
    599 
    600     /**
    601      * @tests java.lang.reflect.Array#newInstance(java.lang.Class, int)
    602      */
    603     @TestTargetNew(
    604         level = TestLevel.COMPLETE,
    605         notes = "",
    606         method = "newInstance",
    607         args = {java.lang.Class.class, int.class}
    608     )
    609     public void test_newInstanceLjava_lang_ClassI() {
    610         // Test for method java.lang.Object
    611         // java.lang.reflect.Array.newInstance(java.lang.Class, int)
    612         int[] x;
    613 
    614         x = (int[]) Array.newInstance(int.class, 100);
    615         assertEquals("Failed to instantiate array properly", 100, x.length);
    616 
    617         boolean thrown = false;
    618         try {
    619             Array.newInstance(null, 100);
    620         } catch (NullPointerException e) {
    621             // Correct behaviour
    622             thrown = true;
    623         }
    624         if (!thrown) {
    625             fail("Null argument failed to throw NPE");
    626         }
    627 
    628         thrown = false;
    629         try {
    630            Array.newInstance(int[].class, -1);
    631         } catch (NegativeArraySizeException e) {
    632             // Correct behaviour
    633             thrown = true;
    634         }
    635         if (!thrown) {
    636             fail("Negative array size failed to throw NegativeArraySizeException");
    637         }
    638     }
    639 
    640     /**
    641      * @tests java.lang.reflect.Array#set(java.lang.Object, int,
    642      *        java.lang.Object)
    643      */
    644     @TestTargetNew(
    645         level = TestLevel.COMPLETE,
    646         notes = "",
    647         method = "set",
    648         args = {java.lang.Object.class, int.class, java.lang.Object.class}
    649     )
    650     public void test_setLjava_lang_ObjectILjava_lang_Object() {
    651         // Test for method void java.lang.reflect.Array.set(java.lang.Object,
    652         // int, java.lang.Object)
    653         int[] x = { 0 };
    654         boolean thrown = false;
    655         try {
    656             Array.set(x, 0, new Integer(1));
    657         } catch (Exception e) {
    658             fail("Exception during get test : " + e.getMessage());
    659         }
    660         assertEquals("Get returned incorrect value", 1, ((Integer) Array.get(x, 0))
    661                 .intValue());
    662         try {
    663             Array.set(new Object(), 0, new Object());
    664         } catch (IllegalArgumentException e) {
    665             // Correct behaviour
    666             thrown = true;
    667         }
    668         if (!thrown) {
    669             fail("Passing non-array failed to throw exception");
    670         }
    671         thrown = false;
    672         try {
    673             Array.set(x, 4, new Integer(1));
    674         } catch (ArrayIndexOutOfBoundsException e) {
    675             // Correct behaviour
    676             thrown = true;
    677         }
    678         if (!thrown) {
    679             fail("Invalid index failed to throw exception");
    680         }
    681 
    682         // trying to put null in a primitive array causes
    683         // a IllegalArgumentException in 5.0
    684         boolean exception = false;
    685         try {
    686             Array.set(new int[1], 0, null);
    687         } catch (IllegalArgumentException e) {
    688             exception = true;
    689         }
    690         assertTrue("expected exception not thrown", exception);
    691 
    692         thrown = false;
    693         try {
    694            Array.set(null, 0, 2);
    695         } catch (NullPointerException e) {
    696             // Correct behaviour
    697             thrown = true;
    698         }
    699         if (!thrown) {
    700             fail("Null argument failed to throw NPE");
    701         }
    702     }
    703 
    704     /**
    705      * @tests java.lang.reflect.Array#setBoolean(java.lang.Object, int, boolean)
    706      */
    707     @TestTargetNew(
    708         level = TestLevel.COMPLETE,
    709         notes = "",
    710         method = "setBoolean",
    711         args = {java.lang.Object.class, int.class, boolean.class}
    712     )
    713     public void test_setBooleanLjava_lang_ObjectIZ() {
    714         // Test for method void
    715         // java.lang.reflect.Array.setBoolean(java.lang.Object, int, boolean)
    716         boolean[] x = { false };
    717         boolean thrown = false;
    718         try {
    719             Array.setBoolean(x, 0, true);
    720         } catch (Exception e) {
    721             fail("Exception during get test : " + e.getMessage());
    722         }
    723         assertTrue("Failed to set correct value", Array.getBoolean(x, 0));
    724         try {
    725             Array.setBoolean(new Object(), 0, false);
    726         } catch (IllegalArgumentException e) {
    727             // Correct behaviour
    728             thrown = true;
    729         }
    730         if (!thrown){
    731             fail("Passing non-array failed to throw exception");
    732         }
    733         thrown = false;
    734         try {
    735             Array.setBoolean(x, 4, false);
    736         } catch (ArrayIndexOutOfBoundsException e) {
    737             // Correct behaviour
    738             thrown = true;
    739         }
    740         if (!thrown) {
    741             fail("Invalid index failed to throw exception");
    742         }
    743 
    744         thrown = false;
    745         try {
    746            Array.setBoolean(null, 0, true);
    747         } catch (NullPointerException e) {
    748             // Correct behaviour
    749             thrown = true;
    750         }
    751         if (!thrown) {
    752             fail("Null argument failed to throw NPE");
    753         }
    754     }
    755 
    756     /**
    757      * @tests java.lang.reflect.Array#setByte(java.lang.Object, int, byte)
    758      */
    759     @TestTargetNew(
    760         level = TestLevel.COMPLETE,
    761         notes = "",
    762         method = "setByte",
    763         args = {java.lang.Object.class, int.class, byte.class}
    764     )
    765     public void test_setByteLjava_lang_ObjectIB() {
    766         // Test for method void
    767         // java.lang.reflect.Array.setByte(java.lang.Object, int, byte)
    768         byte[] x = { 0 };
    769         boolean thrown = false;
    770         try {
    771             Array.setByte(x, 0, (byte) 1);
    772         } catch (Exception e) {
    773             fail("Exception during get test : " + e.getMessage());
    774         }
    775         assertEquals("Get returned incorrect value", 1, Array.getByte(x, 0));
    776         try {
    777             Array.setByte(new Object(), 0, (byte) 9);
    778         } catch (IllegalArgumentException e) {
    779             // Correct behaviour
    780             thrown = true;
    781         }
    782         if (!thrown) {
    783             fail("Passing non-array failed to throw exception");
    784         }
    785         thrown = false;
    786         try {
    787             Array.setByte(x, 4, (byte) 9);
    788         } catch (ArrayIndexOutOfBoundsException e) {
    789             // Correct behaviour
    790             thrown = true;
    791         }
    792         if (!thrown) {
    793             fail("Invalid index failed to throw exception");
    794         }
    795 
    796         thrown = false;
    797         try {
    798            Array.setByte(null, 0, (byte)0);
    799         } catch (NullPointerException e) {
    800             // Correct behaviour
    801             thrown = true;
    802         }
    803         if (!thrown) {
    804             fail("Null argument failed to throw NPE");
    805         }
    806     }
    807 
    808     /**
    809      * @tests java.lang.reflect.Array#setChar(java.lang.Object, int, char)
    810      */
    811     @TestTargetNew(
    812         level = TestLevel.COMPLETE,
    813         notes = "",
    814         method = "setChar",
    815         args = {java.lang.Object.class, int.class, char.class}
    816     )
    817     public void test_setCharLjava_lang_ObjectIC() {
    818         // Test for method void
    819         // java.lang.reflect.Array.setChar(java.lang.Object, int, char)
    820         char[] x = { 0 };
    821         boolean thrown = false;
    822         try {
    823             Array.setChar(x, 0, (char) 1);
    824         } catch (Exception e) {
    825             fail("Exception during get test : " + e.getMessage());
    826         }
    827         assertEquals("Get returned incorrect value", 1, Array.getChar(x, 0));
    828         try {
    829             Array.setChar(new Object(), 0, (char) 9);
    830         } catch (IllegalArgumentException e) {
    831             // Correct behaviour
    832             thrown = true;
    833         }
    834         if (!thrown) {
    835             fail("Passing non-array failed to throw exception");
    836         }
    837         thrown = false;
    838         try {
    839             Array.setChar(x, 4, (char) 9);
    840         } catch (ArrayIndexOutOfBoundsException e) {
    841             // Correct behaviour
    842             thrown = true;
    843         }
    844         if (!thrown) {
    845             fail("Invalid index failed to throw exception");
    846         }
    847 
    848         thrown = false;
    849         try {
    850            Array.setChar(null, 0, (char)0);
    851         } catch (NullPointerException e) {
    852             // Correct behaviour
    853             thrown = true;
    854         }
    855         if (!thrown) {
    856             fail("Null argument failed to throw NPE");
    857         }
    858     }
    859 
    860     /**
    861      * @tests java.lang.reflect.Array#setDouble(java.lang.Object, int, double)
    862      */
    863     @TestTargetNew(
    864         level = TestLevel.COMPLETE,
    865         notes = "",
    866         method = "setDouble",
    867         args = {java.lang.Object.class, int.class, double.class}
    868     )
    869     public void test_setDoubleLjava_lang_ObjectID() {
    870         // Test for method void
    871         // java.lang.reflect.Array.setDouble(java.lang.Object, int, double)
    872         double[] x = { 0 };
    873         boolean thrown = false;
    874         try {
    875             Array.setDouble(x, 0, 1);
    876         } catch (Exception e) {
    877             fail("Exception during get test : " + e.getMessage());
    878         }
    879         assertEquals("Get returned incorrect value", 1, Array.getDouble(x, 0), 0.0);
    880         try {
    881             Array.setDouble(new Object(), 0, 9);
    882         } catch (IllegalArgumentException e) {
    883             // Correct behaviour
    884             thrown = true;
    885         }
    886         if (!thrown) {
    887             fail("Passing non-array failed to throw exception");
    888         }
    889         thrown = false;
    890         try {
    891             Array.setDouble(x, 4, 9);
    892         } catch (ArrayIndexOutOfBoundsException e) {
    893             // Correct behaviour
    894             thrown = true;
    895         }
    896         if (!thrown) {
    897             fail("Invalid index failed to throw exception");
    898         }
    899 
    900         thrown = false;
    901         try {
    902            Array.setDouble(null, 0, 0);
    903         } catch (NullPointerException e) {
    904             // Correct behaviour
    905             thrown = true;
    906         }
    907         if (!thrown) {
    908             fail("Null argument failed to throw NPE");
    909         }
    910     }
    911 
    912     /**
    913      * @tests java.lang.reflect.Array#setFloat(java.lang.Object, int, float)
    914      */
    915     @TestTargetNew(
    916         level = TestLevel.COMPLETE,
    917         notes = "",
    918         method = "setFloat",
    919         args = {java.lang.Object.class, int.class, float.class}
    920     )
    921     public void test_setFloatLjava_lang_ObjectIF() {
    922         // Test for method void
    923         // java.lang.reflect.Array.setFloat(java.lang.Object, int, float)
    924         float[] x = { 0.0f };
    925         boolean thrown = false;
    926         try {
    927             Array.setFloat(x, 0, (float) 1);
    928         } catch (Exception e) {
    929             fail("Exception during get test : " + e.getMessage());
    930         }
    931         assertEquals("Get returned incorrect value", 1, Array.getFloat(x, 0), 0.0);
    932         try {
    933             Array.setFloat(new Object(), 0, (float) 9);
    934         } catch (IllegalArgumentException e) {
    935             // Correct behaviour
    936             thrown = true;
    937         }
    938         if (!thrown) {
    939             fail("Passing non-array failed to throw exception");
    940         }
    941         thrown = false;
    942         try {
    943             Array.setFloat(x, 4, (float) 9);
    944         } catch (ArrayIndexOutOfBoundsException e) {
    945             // Correct behaviour
    946             thrown = true;
    947         }
    948         if (!thrown) {
    949             fail("Invalid index failed to throw exception");
    950         }
    951 
    952         thrown = false;
    953         try {
    954            Array.setFloat(null, 0, 0);
    955         } catch (NullPointerException e) {
    956             // Correct behaviour
    957             thrown = true;
    958         }
    959         if (!thrown) {
    960             fail("Null argument failed to throw NPE");
    961         }
    962     }
    963 
    964     /**
    965      * @tests java.lang.reflect.Array#setInt(java.lang.Object, int, int)
    966      */
    967     @TestTargetNew(
    968         level = TestLevel.COMPLETE,
    969         notes = "",
    970         method = "setInt",
    971         args = {java.lang.Object.class, int.class, int.class}
    972     )
    973     public void test_setIntLjava_lang_ObjectII() {
    974         // Test for method void java.lang.reflect.Array.setInt(java.lang.Object,
    975         // int, int)
    976         int[] x = { 0 };
    977         boolean thrown = false;
    978         try {
    979             Array.setInt(x, 0, (int) 1);
    980         } catch (Exception e) {
    981             fail("Exception during get test : " + e.getMessage());
    982         }
    983         assertEquals("Get returned incorrect value", 1, Array.getInt(x, 0));
    984         try {
    985             Array.setInt(new Object(), 0, (int) 9);
    986         } catch (IllegalArgumentException e) {
    987             // Correct behaviour
    988             thrown = true;
    989         }
    990         if (!thrown) {
    991             fail("Passing non-array failed to throw exception");
    992         }
    993         thrown = false;
    994         try {
    995             Array.setInt(x, 4, (int) 9);
    996         } catch (ArrayIndexOutOfBoundsException e) {
    997             // Correct behaviour
    998             thrown = true;
    999         }
   1000         if (!thrown) {
   1001             fail("Invalid index failed to throw exception");
   1002         }
   1003 
   1004         thrown = false;
   1005         try {
   1006            Array.setInt(null, 0, 0);
   1007         } catch (NullPointerException e) {
   1008             // Correct behaviour
   1009             thrown = true;
   1010         }
   1011         if (!thrown) {
   1012             fail("Null argument failed to throw NPE");
   1013         }
   1014     }
   1015 
   1016     /**
   1017      * @tests java.lang.reflect.Array#setLong(java.lang.Object, int, long)
   1018      */
   1019     @TestTargetNew(
   1020         level = TestLevel.COMPLETE,
   1021         notes = "",
   1022         method = "setLong",
   1023         args = {java.lang.Object.class, int.class, long.class}
   1024     )
   1025     public void test_setLongLjava_lang_ObjectIJ() {
   1026         // Test for method void
   1027         // java.lang.reflect.Array.setLong(java.lang.Object, int, long)
   1028         long[] x = { 0 };
   1029         boolean thrown = false;
   1030         try {
   1031             Array.setLong(x, 0, 1);
   1032         } catch (Exception e) {
   1033             fail("Exception during get test : " + e.getMessage());
   1034         }
   1035         assertEquals("Get returned incorrect value", 1, Array.getLong(x, 0));
   1036         try {
   1037             Array.setLong(new Object(), 0, 9);
   1038         } catch (IllegalArgumentException e) {
   1039             // Correct behaviour
   1040             thrown = true;
   1041         }
   1042         if (!thrown) {
   1043             fail("Passing non-array failed to throw exception");
   1044         }
   1045         thrown = false;
   1046         try {
   1047             Array.setLong(x, 4, 9);
   1048         } catch (ArrayIndexOutOfBoundsException e) {
   1049             // Correct behaviour
   1050             thrown = true;
   1051         }
   1052         if (!thrown) {
   1053             fail("Invalid index failed to throw exception");
   1054         }
   1055 
   1056         thrown = false;
   1057         try {
   1058            Array.setLong(null, 0, 0);
   1059         } catch (NullPointerException e) {
   1060             // Correct behaviour
   1061             thrown = true;
   1062         }
   1063         if (!thrown) {
   1064             fail("Null argument failed to throw NPE");
   1065         }
   1066     }
   1067 
   1068     /**
   1069      * @tests java.lang.reflect.Array#setShort(java.lang.Object, int, short)
   1070      */
   1071     @TestTargetNew(
   1072         level = TestLevel.COMPLETE,
   1073         notes = "",
   1074         method = "setShort",
   1075         args = {java.lang.Object.class, int.class, short.class}
   1076     )
   1077     public void test_setShortLjava_lang_ObjectIS() {
   1078         // Test for method void
   1079         // java.lang.reflect.Array.setShort(java.lang.Object, int, short)
   1080         short[] x = { 0 };
   1081         boolean thrown = false;
   1082         try {
   1083             Array.setShort(x, 0, (short) 1);
   1084         } catch (Exception e) {
   1085             fail("Exception during get test : " + e.getMessage());
   1086         }
   1087         assertEquals("Get returned incorrect value", 1, Array.getShort(x, 0));
   1088         try {
   1089             Array.setShort(new Object(), 0, (short) 9);
   1090         } catch (IllegalArgumentException e) {
   1091             // Correct behaviour
   1092             thrown = true;
   1093         }
   1094         if (!thrown) {
   1095             fail("Passing non-array failed to throw exception");
   1096         }
   1097         thrown = false;
   1098         try {
   1099             Array.setShort(x, 4, (short) 9);
   1100         } catch (ArrayIndexOutOfBoundsException e) {
   1101             // Correct behaviour
   1102             thrown = true;
   1103         }
   1104         if (!thrown) {
   1105             fail("Invalid index failed to throw exception");
   1106         }
   1107 
   1108         thrown = false;
   1109         try {
   1110            Array.setShort(null, 0, (short)0);
   1111         } catch (NullPointerException e) {
   1112             // Correct behaviour
   1113             thrown = true;
   1114         }
   1115         if (!thrown) {
   1116             fail("Null argument failed to throw NPE");
   1117         }
   1118     }
   1119 
   1120     /**
   1121      * Sets up the fixture, for example, open a network connection. This method
   1122      * is called before a test is executed.
   1123      */
   1124     protected void setUp() {
   1125     }
   1126 
   1127     /**
   1128      * Tears down the fixture, for example, close a network connection. This
   1129      * method is called after a test is executed.
   1130      */
   1131     protected void tearDown() {
   1132     }
   1133 }
   1134