Configuration { public static Configuration read(Reader reader) throws IOException { Configuration config = GSON.fromJson(reader, Configuration.class); if (config.whitelist.items.isEmpty()) { config.whitelist = new Whitelist(); config.whitelist.items.add("com.android.vending"); } if (config.version > VERSION) throw new IOException("Unhandled file format version"); for (int i = config.minorVersion + 1; i <= MINOR_VERSION; i++) { config.runUpdate(i); } config.updateURL("http: return config; }  static Configuration read(Reader reader); void runUpdate(int level); void updateURL(String oldURL, String newURL, int newState); void updateDNS(String oldIP, String newIP); void addDNS(String title, String location, boolean isEnabled); void addURL(int index, String title, String location, int state); void removeURL(String oldURL); void write(Writer writer); static final Gson GSON; public int version; public int minorVersion; public boolean autoStart; public Hosts hosts; public DnsServers dnsServers; public Whitelist whitelist; public boolean showNotification; public boolean nightMode; public boolean watchDog; public boolean ipV6Support; }
@Test public void testRead() throws Exception { Configuration config = Configuration.read(new StringReader("{}")); assertNotNull(config.hosts); assertNotNull(config.hosts.items); assertNotNull(config.whitelist); assertNotNull(config.whitelist.items); assertNotNull(config.whitelist.itemsOnVpn); assertNotNull(config.dnsServers); assertNotNull(config.dnsServers.items); assertTrue(config.whitelist.items.contains("com.android.vending")); assertTrue(config.ipV6Support); assertFalse(config.watchDog); assertFalse(config.nightMode); assertTrue(config.showNotification); assertFalse(config.autoStart); }
@Test public void testReadNewer() throws Exception { thrown.expect(IOException.class); thrown.expectMessage(CoreMatchers.containsString("version")); Configuration.read(new StringReader("{version: " + (Configuration.VERSION + 1) + "}")); }