88
99import java .io .FileNotFoundException ;
1010import java .io .IOException ;
11+ import java .net .SocketTimeoutException ;
1112import java .util .List ;
1213
1314import static org .junit .jupiter .api .Assertions .assertEquals ;
1415import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
1516import static org .junit .jupiter .api .Assertions .assertThrows ;
1617import static org .junit .jupiter .api .Assertions .assertTrue ;
1718import static org .junit .jupiter .api .Assumptions .assumeFalse ;
19+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
1820
1921/**
2022 * Created by colezlaw on 10/13/14.
@@ -52,6 +54,9 @@ void testValidSha1() throws Exception {
5254 assertEquals ("org.apache.maven.plugins" , ma .get (0 ).getGroupId (), "Incorrect group" );
5355 assertEquals ("maven-compiler-plugin" , ma .get (0 ).getArtifactId (), "Incorrect artifact" );
5456 assertEquals ("3.1" , ma .get (0 ).getVersion (), "Incorrect version" );
57+ } catch (SocketTimeoutException ex ) {
58+ // skip test if Maven Central times out
59+ assumeTrue (false , "Skipping test due to SocketTimeoutException: " + ex .getMessage ());
5560 } catch (IOException ex ) {
5661 // abort if we hit a failure state on the CI
5762 assumeFalse (StringUtils .contains (ex .getMessage (), "Could not connect to MavenCentral" ));
@@ -66,16 +71,21 @@ void testValidSha1() throws Exception {
6671 // you may not be able to reach. Remove the @Ignore annotation if you want to
6772 // test it anyway
6873 @ Test
69- void testMissingSha1 () {
70- IOException ex = assertThrows (IOException .class , () -> searcher .searchSha1 ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ));
71-
72- // abort if we hit a failure state on the CI
73- assumeFalse (StringUtils .contains (ex .getMessage (), "Could not connect to MavenCentral" ));
74- assumeFalse (ex .getMessage ().matches ("^https://.+ - Server status: \\ d{3} - Server reason: .+$" ));
74+ void testMissingSha1 () throws Exception {
75+ try {
76+ searcher .searchSha1 ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" );
77+ } catch (SocketTimeoutException ex ) {
78+ // skip test if Maven Central times out
79+ assumeTrue (false , "Skipping test due to SocketTimeoutException: " + ex .getMessage ());
80+ } catch (IOException ex ) {
81+ // abort if we hit a failure state on the CI
82+ assumeFalse (StringUtils .contains (ex .getMessage (), "Could not connect to MavenCentral" ));
83+ assumeFalse (ex .getMessage ().matches ("^https://.+ - Server status: \\ d{3} - Server reason: .+$" ));
7584
76- // otherwise assert that the exception is a FileNotFoundException
77- assertInstanceOf (FileNotFoundException .class , ex );
78- assertEquals ("Artifact not found in Central" , ex .getMessage ());
85+ // otherwise assert that the exception is a FileNotFoundException
86+ assertInstanceOf (FileNotFoundException .class , ex );
87+ assertEquals ("Artifact not found in Central" , ex .getMessage ());
88+ }
7989 }
8090
8191 // This test should give us multiple results back from Central
@@ -84,6 +94,9 @@ void testMultipleReturns() throws Exception {
8494 try {
8595 List <MavenArtifact > ma = searcher .searchSha1 ("94A9CE681A42D0352B3AD22659F67835E560D107" );
8696 assertTrue (ma .size () > 1 );
97+ } catch (SocketTimeoutException ex ) {
98+ // skip test if Maven Central times out
99+ assumeTrue (false , "Skipping test due to SocketTimeoutException: " + ex .getMessage ());
87100 } catch (IOException ex ) {
88101 // abort if we hit a failure state on the CI
89102 assumeFalse (StringUtils .contains (ex .getMessage (), "Could not connect to MavenCentral" ));
0 commit comments