2727import java .net .NetworkInterface ;
2828import java .util .ArrayList ;
2929import java .util .List ;
30- import java .util .Optional ;
3130
3231import jdk .test .lib .NetworkConfiguration ;
33- import org .testng .SkipException ;
34- import org .testng .annotations .BeforeTest ;
35- import org .testng .annotations .DataProvider ;
36- import org .testng .annotations .Test ;
32+ import static jdk .test .lib .net .IPSupport .diagnoseConfigurationIssue ;
3733import static java .lang .String .format ;
3834import static java .lang .System .out ;
3935import static java .net .StandardSocketOptions .IP_MULTICAST_IF ;
4036import static java .util .stream .Collectors .toList ;
41- import static jdk .test .lib .net .IPSupport .diagnoseConfigurationIssue ;
42- import static org .testng .Assert .assertEquals ;
43- import static org .testng .Assert .assertTrue ;
37+
38+ import org .junit .jupiter .api .Assumptions ;
39+ import org .junit .jupiter .api .BeforeAll ;
40+ import org .junit .jupiter .api .Test ;
41+ import org .junit .jupiter .params .ParameterizedTest ;
42+ import org .junit .jupiter .params .provider .MethodSource ;
43+ import static org .junit .jupiter .api .Assertions .assertEquals ;
44+ import static org .junit .jupiter .api .Assertions .assertTrue ;
4445
4546/**
4647 * @test
4748 * @bug 8236441
4849 * @summary Bound MulticastSocket fails when setting outbound interface on Windows
4950 * @library /test/lib
50- * @run testng IPMulticastIF
51- * @run testng /othervm -Djava.net.preferIPv4Stack=true IPMulticastIF
52- * @run testng /othervm -Djava.net.preferIPv6Addresses=true IPMulticastIF
53- * @run testng /othervm -Djava.net.preferIPv6Addresses=true -Djava.net.preferIPv4Stack=true IPMulticastIF
51+ * @run junit ${test.main.class}
52+ * @run junit /othervm -Djava.net.preferIPv4Stack=true ${test.main.class}
53+ * @run junit /othervm -Djava.net.preferIPv6Addresses=true ${test.main.class}
54+ * @run junit /othervm -Djava.net.preferIPv6Addresses=true -Djava.net.preferIPv4Stack=true ${test.main.class}
5455 */
5556public class IPMulticastIF {
5657
57- @ BeforeTest
58- public void sanity () {
59- Optional <String > configurationIssue = diagnoseConfigurationIssue ();
60- configurationIssue .map (SkipException ::new ).ifPresent (x -> {
61- throw x ;
62- });
58+ @ BeforeAll
59+ public static void sanity () {
60+ diagnoseConfigurationIssue ().ifPresent (Assumptions ::abort );
6361 NetworkConfiguration .printSystemConfiguration (out );
6462 }
6563
66- @ DataProvider (name = "scenarios" )
67- public Object [][] positive () throws Exception {
64+ public static Object [][] positive () throws Exception {
6865 List <InetAddress > addrs = List .of (InetAddress .getLocalHost (),
6966 InetAddress .getLoopbackAddress ());
7067 List <Object []> list = new ArrayList <>();
@@ -81,8 +78,7 @@ public Object[][] positive() throws Exception {
8178 return list .stream ().toArray (Object [][]::new );
8279 }
8380
84- @ DataProvider (name = "interfaces" )
85- public Object [][] interfaces () throws Exception {
81+ public static Object [][] interfaces () throws Exception {
8682 List <Object []> list = new ArrayList <>();
8783 NetworkConfiguration nc = NetworkConfiguration .probe ();
8884 nc .multicastInterfaces (true )
@@ -92,65 +88,69 @@ public Object[][] interfaces() throws Exception {
9288 return list .stream ().toArray (Object [][]::new );
9389 }
9490
95- @ Test (dataProvider = "scenarios" )
91+ @ ParameterizedTest
92+ @ MethodSource ("positive" )
9693 public void testSetGetInterfaceBound (InetSocketAddress bindAddr , NetworkInterface nif )
9794 throws Exception
9895 {
9996 out .println (format ("\n \n --- testSetGetInterfaceBound bindAddr=[%s], nif=[%s]" , bindAddr , nif ));
10097 try (MulticastSocket ms = new MulticastSocket (bindAddr )) {
10198 ms .setNetworkInterface (nif );
10299 NetworkInterface msNetIf = ms .getNetworkInterface ();
103- assertEquals (msNetIf , nif );
100+ assertEquals (nif , msNetIf );
104101 }
105102 }
106103
107- @ Test (dataProvider = "interfaces" )
104+ @ ParameterizedTest
105+ @ MethodSource ("interfaces" )
108106 public void testSetGetInterfaceUnbound (NetworkInterface nif )
109107 throws Exception
110108 {
111109 out .println (format ("\n \n --- testSetGetInterfaceUnbound nif=[%s]" , nif ));
112110 try (MulticastSocket ms = new MulticastSocket ()) {
113111 ms .setNetworkInterface (nif );
114112 NetworkInterface msNetIf = ms .getNetworkInterface ();
115- assertEquals (msNetIf , nif );
113+ assertEquals (nif , msNetIf );
116114 }
117115 }
118116
119- @ Test (dataProvider = "scenarios" )
117+ @ ParameterizedTest
118+ @ MethodSource ("positive" )
120119 public void testSetGetOptionBound (InetSocketAddress bindAddr , NetworkInterface nif )
121120 throws Exception
122121 {
123122 out .println (format ("\n \n --- testSetGetOptionBound bindAddr=[%s], nif=[%s]" , bindAddr , nif ));
124123 try (MulticastSocket ms = new MulticastSocket (bindAddr )) {
125124 ms .setOption (IP_MULTICAST_IF , nif );
126125 NetworkInterface msNetIf = ms .getOption (IP_MULTICAST_IF );
127- assertEquals (msNetIf , nif );
126+ assertEquals (nif , msNetIf );
128127 }
129128 }
130129
131- @ Test (dataProvider = "interfaces" )
130+ @ ParameterizedTest
131+ @ MethodSource ("interfaces" )
132132 public void testSetGetOptionUnbound (NetworkInterface nif )
133133 throws Exception
134134 {
135135 out .println (format ("\n \n --- testSetGetOptionUnbound nif=[%s]" , nif ));
136136 try (MulticastSocket ms = new MulticastSocket ()) {
137137 ms .setOption (IP_MULTICAST_IF , nif );
138138 NetworkInterface msNetIf = ms .getOption (IP_MULTICAST_IF );
139- assertEquals (msNetIf , nif );
139+ assertEquals (nif , msNetIf );
140140 }
141141 }
142142
143143 // -- get without set
144144
145- @ DataProvider (name = "bindAddresses" )
146- public Object [][] bindAddresses () throws Exception {
145+ public static Object [][] bindAddresses () throws Exception {
147146 return new Object [][] {
148147 { new InetSocketAddress (InetAddress .getLocalHost (), 0 ) },
149148 { new InetSocketAddress (InetAddress .getLoopbackAddress (), 0 ) },
150149 };
151150 }
152151
153- @ Test (dataProvider = "bindAddresses" )
152+ @ ParameterizedTest
153+ @ MethodSource ("bindAddresses" )
154154 public void testGetInterfaceBound (InetSocketAddress bindAddr )
155155 throws Exception
156156 {
@@ -168,29 +168,30 @@ public void testGetInterfaceUnbound() throws Exception {
168168 }
169169 }
170170
171- @ Test (dataProvider = "bindAddresses" )
171+ @ ParameterizedTest
172+ @ MethodSource ("bindAddresses" )
172173 public void testGetOptionBound (InetSocketAddress bindAddr )
173174 throws Exception
174175 {
175176 out .println (format ("\n \n --- testGetOptionBound bindAddr=[%s]" , bindAddr ));
176177 try (MulticastSocket ms = new MulticastSocket (bindAddr )) {
177- assertEquals (ms .getOption (IP_MULTICAST_IF ), null );
178+ assertEquals (null , ms .getOption (IP_MULTICAST_IF ));
178179 }
179180 }
180181
181182 @ Test
182183 public void testGetOptionUnbound () throws Exception {
183184 out .println ("\n \n --- testGetOptionUnbound " );
184185 try (MulticastSocket ms = new MulticastSocket ()) {
185- assertEquals (ms .getOption (IP_MULTICAST_IF ), null );
186+ assertEquals (null , ms .getOption (IP_MULTICAST_IF ));
186187 }
187188 }
188189
189190 // Asserts that the placeholder NetworkInterface has a single InetAddress
190191 // that represent any local address.
191192 static void assertPlaceHolder (NetworkInterface nif ) {
192193 List <InetAddress > addrs = nif .inetAddresses ().collect (toList ());
193- assertEquals (addrs .size (), 1 );
194+ assertEquals (1 , addrs .size ());
194195 assertTrue (addrs .get (0 ).isAnyLocalAddress ());
195196 }
196197}
0 commit comments