summaryrefslogtreecommitdiff
path: root/app/src/test/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-14 18:23:45 +0100
committercyBerta <cyberta@riseup.net>2021-11-14 18:23:45 +0100
commit187c2091b0735f531e505462ea92a284de59846b (patch)
tree663cac82e9e77b0b18aacb4603af8c9bc7b02812 /app/src/test/java/se
parent59931af646b19fd8e206ea10a40e0971b968d620 (diff)
implement IPv4 address check based on regex
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/base/utils/ConfigHelperTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/base/utils/ConfigHelperTest.java b/app/src/test/java/se/leap/bitmaskclient/base/utils/ConfigHelperTest.java
new file mode 100644
index 00000000..75552226
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/base/utils/ConfigHelperTest.java
@@ -0,0 +1,48 @@
+package se.leap.bitmaskclient.base.utils;
+
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(DataProviderRunner.class)
+public class ConfigHelperTest {
+
+ @DataProvider
+ public static Object[][] dataProviderIPs() {
+ // @formatter:off
+ return new Object[][] {
+ { "0.0.0.0", true },
+ { "1.1.1.1", true },
+ { "8.8.8.8", true },
+ { "127.0.0.1", true },
+ { "255.255.255.255", true },
+ { "200.50.20.10", true },
+ { "97.72.15.12", true },
+ {"02.0.0.0", false},
+ {"10.000.1.1", false},
+ {"256.256.256.256", false},
+ {"127..0.1", false},
+ {"127.0..1", false},
+ {"127.0.0.", false},
+ {"127.0.0", false},
+ {"255.255.255.255.255", false},
+ {"", false},
+ {null, false},
+ };
+ }
+
+
+ @Test
+ @UseDataProvider("dataProviderIPs")
+ public void testisIPv4_validIPs_returnsTrue(String ip, boolean isValidExpected) {
+ assertEquals(isValidExpected, ConfigHelper.isIPv4(ip));
+ }
+} \ No newline at end of file