Code example for Constructor

Methods: newInstance, setAccessible

0
    private Configuration createConfiguration() throws Exception {
        // Using reflection instead since we want to pass null to 
        // a constructor marked with @NonNull, so the test won't compile. 
        Constructor<Configuration> constructor =
                Configuration.class.getDeclaredConstructor(ConfigurationChooser.class);
        constructor.setAccessible(true);
        ConfigurationChooser chooser = null;
        return constructor.newInstance(chooser);
    } 
 
    public void test() throws Exception { 
        Configuration configuration = createConfiguration();
        assertNotNull(configuration);
        configuration.setTheme("@style/Theme");
        assertEquals("@style/Theme", configuration.getTheme());
 
        DeviceManager deviceManager = new DeviceManager(new StdLogger(StdLogger.Level.VERBOSE));
        List<Device> devices = deviceManager.getDefaultDevices();
        assertNotNull(devices);
        assertTrue(devices.size() > 0);
        configuration.setDevice(devices.get(0), false);