Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Add unit tests for WifiConfigStore.xml parser
Browse files Browse the repository at this point in the history
Added Robolectric dependency because we use Android dependency for XML parsing.

Issue: #34
  • Loading branch information
bparmentier committed Oct 28, 2018
1 parent 24b4fbd commit 81f5368
Show file tree
Hide file tree
Showing 4 changed files with 530 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ android {
lintOptions {
abortOnError false
}
testOptions.unitTests.includeAndroidResources = true
}

dependencies {
Expand All @@ -41,6 +42,7 @@ dependencies {
implementation 'commons-codec:commons-codec:1.11'

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.0'
}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* WiFiKeyShare. Share Wi-Fi passwords with QR codes or NFC tags.
* Copyright (C) 2018 Bruno Parmentier <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package be.brunoparmentier.wifikeyshare.utils;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import be.brunoparmentier.wifikeyshare.model.WifiAuthType;
import be.brunoparmentier.wifikeyshare.model.WifiNetwork;

import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
public class WifiConfigStoreParserTest {

private final List<WifiNetwork> expectedWifiNetworks = new ArrayList<>();

@Before
public void setUp() {
expectedWifiNetworks.add(new WifiNetwork(
"test1", WifiAuthType.OPEN, "", false));
expectedWifiNetworks.add(new WifiNetwork(
"test2", WifiAuthType.WEP, "test", false));
expectedWifiNetworks.add(new WifiNetwork(
"test3", WifiAuthType.WPA2_PSK, "test1234", false));
expectedWifiNetworks.add(new WifiNetwork(
"test4", WifiAuthType.WPA2_PSK, "ABCDEFGHI0123456789JKLMNOP", false));
expectedWifiNetworks.add(new WifiNetwork(
"test5", WifiAuthType.WPA2_PSK, "\";/\\=#}`,\\\"$4<d)=%", false));
expectedWifiNetworks.add(new WifiNetwork(
"test6", WifiAuthType.WPA2_EAP, "", false));
expectedWifiNetworks.add(new WifiNetwork(
"test7", WifiAuthType.WPA2_EAP, "", false));
expectedWifiNetworks.add(new WifiNetwork(
"a\"=$\\o(#=>™•,k8", WifiAuthType.OPEN, "", false));


}

@Test
public void parse() throws XmlPullParserException, IOException {
InputStream wifiConfigStoreFileStream =
getClass().getClassLoader().getResourceAsStream("test_WifiConfigStore.xml");

List<WifiNetwork> parsedWifiNetworks = WifiConfigStoreParser.parse(wifiConfigStoreFileStream);
assertEquals(expectedWifiNetworks.size(), parsedWifiNetworks.size());
for (int i = 0; i < expectedWifiNetworks.size(); i++) {
assertEquals(expectedWifiNetworks.get(i), parsedWifiNetworks.get(i));
}
}
}
Loading

0 comments on commit 81f5368

Please sign in to comment.