Code example for Field

Methods: toString

0
        thrown = false;
        try { 
            f = x.getClass().getDeclaredField("floatPFField");
            assertFalse(f.isAccessible());
            f.setFloat(x, Float.MIN_VALUE);
            fail("Accessed inaccessible field");
        } catch (IllegalAccessException ex) {
            thrown = true;
        } 
        assertTrue("IllegalAccessException expected but not thrown", thrown);
         
      //Test NPE 
        thrown = false;
        try { 
            f = x.getClass().getDeclaredField("floatField");
            f.setFloat(null, Float.MIN_VALUE);
            fail("NullPointerException expected but not thrown");
        } catch (NullPointerException ex) {
            thrown = true;
        } catch (Exception ex) {
            fail("NullPointerException expected but not thrown");