changeset 1009:654309b16935

StaticMACAddressResolver
author Devel 2
date Tue, 24 Mar 2020 10:03:14 +0100
parents 469c65b34298
children 82c2ce110b91
files stress-tester/src/main/java/com/passus/st/emitter/SimpleMACAddressResolver.java stress-tester/src/main/java/com/passus/st/emitter/StaticMACAddressResolver.java stress-tester/src/test/java/com/passus/st/emitter/StaticMACAddressResolverTest.java
diffstat 3 files changed, 66 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/emitter/SimpleMACAddressResolver.java	Tue Mar 24 10:03:14 2020 +0100
@@ -0,0 +1,19 @@
+package com.passus.st.emitter;
+
+import com.passus.net.IpAddress;
+import com.passus.net.MACAddress;
+
+public class SimpleMACAddressResolver implements MACAddressResolver {
+
+    private final MACAddress mac;
+
+    public SimpleMACAddressResolver(MACAddress mac) {
+        this.mac = mac;
+    }
+
+    @Override
+    public MACAddress resolve(IpAddress ip) {
+        return mac;
+    }
+
+}
--- a/stress-tester/src/main/java/com/passus/st/emitter/StaticMACAddressResolver.java	Fri Mar 20 14:49:19 2020 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-package com.passus.st.emitter;
-
-import com.passus.net.IpAddress;
-import com.passus.net.MACAddress;
-
-public class StaticMACAddressResolver implements MACAddressResolver {
-
-    private final MACAddress mac;
-
-    public StaticMACAddressResolver(MACAddress mac) {
-        this.mac = mac;
-    }
-
-    @Override
-    public MACAddress resolve(IpAddress ip) {
-        return mac;
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/test/java/com/passus/st/emitter/StaticMACAddressResolverTest.java	Tue Mar 24 10:03:14 2020 +0100
@@ -0,0 +1,47 @@
+package com.passus.st.emitter;
+
+import com.passus.net.IpAddress;
+import com.passus.net.MACAddress;
+import com.passus.st.Pair;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.text.ParseException;
+
+import static com.passus.st.emitter.StaticMACAddressResolver.parse;
+import static org.testng.Assert.assertEquals;
+
+public class StaticMACAddressResolverTest {
+
+    @DataProvider(name = "validPairs")
+    public Object[][] validPairs() {
+        return new Object[][]{
+                {"1.1.1.1 -> 74:86:7a:ee:31:96", "1.1.1.1", "74:86:7A:EE:31:96"},
+                {"1.1.1.1 -> 74:86:7A:EE:31:96", "1.1.1.1", "74:86:7A:EE:31:96"},
+                {"1.1.1.1->74:86:7A:EE:31:96", "1.1.1.1", "74:86:7A:EE:31:96"},
+                {"   1.1.1.1   ->    74:86:7A:EE:31:96  ", "1.1.1.1", "74:86:7A:EE:31:96"}
+        };
+    }
+
+    @Test(dataProvider = "validPairs")
+    public void testParseValidPair(String pairStr, String ip, String mac) throws Exception {
+        Pair<IpAddress, MACAddress> pair = parse(pairStr);
+
+        assertEquals(ip, pair.getValue1().toString());
+        assertEquals(mac, pair.getValue2().toString());
+    }
+
+    @DataProvider(name = "invalidPairs")
+    public Object[][] invalidPairs() {
+        return new Object[][]{
+                {"1.1.1.1 74:86:7a:ee:31:96"},
+                {"1.1.1.1 <-> 74:86:7a:ee:31:96"},
+                {"1.1.1.1 -> 74:86:7a:ee:31:96 ->"}
+        };
+    }
+
+    @Test(dataProvider = "invalidPairs", expectedExceptions = ParseException.class)
+    public void testParseInvalidPair(String pairStr) throws Exception {
+        parse(pairStr);
+    }
+}
\ No newline at end of file