Code example for Field

Methods: getBoolean, setBoolean

0
        try { 
            f = x.getClass().getDeclaredField("shortField");
            val = f.getShort(x);
        } catch (Exception e) {
            fail("Exception during getShort test : " + e.getMessage());
        } 
        assertTrue("Returned incorrect short field value",
                val == Short.MAX_VALUE);
       
        boolean thrown = false;
        try { 
            f = x.getClass().getDeclaredField("booleanField");
            f.getShort(x);
            fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException ex) {
            thrown = true;
        } catch (Exception ex) {
            fail("IllegalArgumentException expected but not thrown "
                    + ex.getMessage());
        } 
        assertTrue("IllegalArgumentException expected but not thrown", thrown);