WpaSupplicantParser { public static List<WifiNetwork> parse(String networkString) { List<WifiNetwork> wifiNetworks = new ArrayList<>(); String[] networkSections = networkString.split("network="); for (int i = 1; i < networkSections.length; i++) { String networkSection = networkSections[i]; String name = networkName(networkSection); WifiAuthType authType = networkType(networkSection); String password = networkPassword(networkSection); wifiNetworks.add(new WifiNetwork(name, authType, password, false)); } return wifiNetworks; }  static List<WifiNetwork> parse(String networkString);  }
@Test public void parse() { InputStream wpaSupplicantFileStream = getClass().getClassLoader().getResourceAsStream("test_wpa_supplicant.conf"); Scanner s = new Scanner(wpaSupplicantFileStream).useDelimiter("\\A"); String wpaSupplicantString = s.hasNext() ? s.next() : ""; List<WifiNetwork> parsedWifiNetworks = WpaSupplicantParser.parse(wpaSupplicantString); assertEquals(expectedWifiNetworks.size(), parsedWifiNetworks.size()); for (int i = 0; i < expectedWifiNetworks.size(); i++) { assertEquals(expectedWifiNetworks.get(i), parsedWifiNetworks.get(i)); } }