22
33import com .fasterxml .uuid .EgressInterfaceFinder .EgressResolutionException ;
44import com .fasterxml .uuid .EgressInterfaceFinder .Finder ;
5- import junit .framework . TestCase ;
5+ import org . junit .jupiter . api . Test ;
66
77import java .net .InetAddress ;
88import java .net .InetSocketAddress ;
99import java .net .NetworkInterface ;
1010import java .net .UnknownHostException ;
1111
1212import static com .fasterxml .uuid .EgressInterfaceFinder .DEFAULT_TIMEOUT_MILLIS ;
13+ import static org .junit .jupiter .api .Assertions .*;
1314
14- public class EgressInterfaceFinderTest extends TestCase {
15+ public class EgressInterfaceFinderTest {
1516
1617 private final EgressInterfaceFinder finder = new EgressInterfaceFinder ();
1718
19+ @ Test
1820 public void testUnspecifiedIPv4LocalAddress () throws UnknownHostException {
1921 EgressResolutionException ex = null ;
2022 try {
2123 finder .fromLocalAddress (InetAddress .getByName ("0.0.0.0" ));
2224 } catch (EgressResolutionException e ) {
2325 ex = e ;
2426 }
25- assertNotNull ("EgressResolutionException was not thrown" , ex );
27+ assertNotNull (ex , "EgressResolutionException was not thrown" );
2628 String message = ex .getMessage ();
27- assertTrue (String .format (
29+ assertTrue (message . startsWith ( "local address" ), String .format (
2830 "message [%s] does not begin with \" local address\" " ,
29- message ),
30- message .startsWith ("local address" ));
31+ message ));
3132 assertEquals (1 , ex .getMessages ().size ());
3233 }
3334
35+ @ Test
3436 public void testUnspecifiedIPv6LocalAddress () throws Exception {
3537 EgressResolutionException ex = null ;
3638 try {
3739 finder .fromLocalAddress (InetAddress .getByName ("::" ));
3840 } catch (EgressResolutionException e ) {
3941 ex = e ;
4042 }
41- assertNotNull ("EgressResolutionException was not thrown" , ex );
43+ assertNotNull (ex , "EgressResolutionException was not thrown" );
4244 String message = ex .getMessage ();
43- assertTrue (String .format (
45+ assertTrue (message . startsWith ( "local address" ), String .format (
4446 "message [%s] does not begin with \" local address\" " ,
45- message ),
46- message .startsWith ("local address" ));
47+ message ));
4748 assertEquals (1 , ex .getMessages ().size ());
4849 }
4950
51+ @ Test
5052 public void testFromLocalAddress () throws Exception {
5153 NetworkInterface anInterface =
5254 NetworkInterface .getNetworkInterfaces ().nextElement ();
5355 InetAddress anAddress = anInterface .getInetAddresses ().nextElement ();
5456 assertEquals (anInterface , finder .fromLocalAddress (anAddress ));
5557 }
5658
59+ @ Test
5760 public void testFromIncorrectLocalAddress () throws Exception {
5861 EgressResolutionException ex = null ;
5962 try {
@@ -62,15 +65,15 @@ public void testFromIncorrectLocalAddress() throws Exception {
6265 } catch (EgressResolutionException e ) {
6366 ex = e ;
6467 }
65- assertNotNull ("EgressResolutionException was not thrown" , ex );
68+ assertNotNull (ex , "EgressResolutionException was not thrown" );
6669 String message = ex .getMessage ();
67- assertTrue (String .format (
70+ assertTrue (message . startsWith ( "no interface found" ), String .format (
6871 "message [%s] does not begin with \" no interface found\" " ,
69- message ),
70- message .startsWith ("no interface found" ));
72+ message ));
7173 assertEquals (1 , ex .getMessages ().size ());
7274 }
7375
76+ @ Test
7477 public void testFromRemoteDatagramSocketConnection () throws Exception {
7578 if (!System .getProperty ("os.name" ).startsWith ("Mac" )) {
7679 String name = EgressInterfaceFinder .randomRootServerName ();
@@ -79,22 +82,26 @@ public void testFromRemoteDatagramSocketConnection() throws Exception {
7982 }
8083 }
8184
85+ @ Test
8286 public void testFromRemoteSocketConnection () throws Exception {
8387 String name = EgressInterfaceFinder .randomRootServerName ();
8488 InetSocketAddress address = new InetSocketAddress (name , 53 );
8589 finder .fromRemoteSocketConnection (DEFAULT_TIMEOUT_MILLIS , address );
8690 }
8791
92+ @ Test
8893 public void testFromRemoteConnection () throws Exception {
8994 String name = EgressInterfaceFinder .randomRootServerName ();
9095 InetSocketAddress address = new InetSocketAddress (name , 53 );
9196 finder .fromRemoteConnection (DEFAULT_TIMEOUT_MILLIS , address );
9297 }
9398
99+ @ Test
94100 public void testFromRootNameServerConnection () throws Exception {
95101 finder .fromRootNameserverConnection (DEFAULT_TIMEOUT_MILLIS );
96102 }
97103
104+ @ Test
98105 public void testAggregateExceptions () {
99106 EgressResolutionException ex = null ;
100107 final int [] counter = {0 };
@@ -112,10 +119,11 @@ public NetworkInterface egressInterface()
112119 } catch (EgressResolutionException e ) {
113120 ex = e ;
114121 }
115- assertNotNull ("EgressResolutionException was not thrown" , ex );
122+ assertNotNull (ex , "EgressResolutionException was not thrown" );
116123 assertEquals (9 , ex .getMessages ().size ());
117124 }
118125
126+ @ Test
119127 public void testDefaultMechanisms () throws Exception {
120128 try {
121129 finder .egressInterface ();
0 commit comments