Code example for Constructor

Methods: setAccessiblenewInstance

0
public class DefaultsTest { 
 
    @Test(expected = InvocationTargetException.class) 
    public void cannotInstantiate() throws Exception { 
        Constructor<Defaults> init = Defaults.class.getDeclaredConstructor();
        init.setAccessible(true);
        init.newInstance();
    } 
 
    @Test 
    public void testInteger() { 
        Integer n = 23;
        assertEquals(23, Defaults.to(n, 42));
    } 
 
    @Test 
    public void testNull() { 
        String answer = null;
        assertEquals("A", Defaults.to(answer, "A"));
    } 
Contextual code suggestions in your IDE  Get Codota for Java