16
16
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .options ;
17
17
import static org .assertj .core .api .Assertions .assertThat ;
18
18
import static org .assertj .core .api .Assertions .failBecauseExceptionWasNotThrown ;
19
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
19
20
20
21
import com .github .tomakehurst .wiremock .junit5 .WireMockExtension ;
21
22
import io .kubernetes .client .openapi .ApiClient ;
@@ -49,31 +50,21 @@ void getPodMetricsThrowsAPIExceptionWhenServerReturnsError() {
49
50
.withStatus (503 )
50
51
.withHeader ("Content-Type" , "text/plain" )
51
52
.withBody ("Service Unavailable" )));
52
- try {
53
- metrics .getPodMetrics (namespace );
54
- failBecauseExceptionWasNotThrown (ApiException .class );
55
- } catch (ApiException ex ) {
56
- assertThat (ex .getCode ()).isEqualTo (503 );
57
- }
53
+ assertThrows (ApiException .class , () -> metrics .getPodMetrics (namespace ));
58
54
}
59
55
60
56
@ Test
61
57
void getPodMetricsWithLabelSelectorThrowsAPIExceptionWhenServerReturnsError () {
62
58
String namespace = "default" ;
63
59
Metrics metrics = new Metrics (client );
64
60
apiServer .stubFor (
65
- get (urlPathMatching ("^/apis/metrics.k8s.io/v1beta1/namespaces/" + namespace + "/pods.*" ))
66
- .willReturn (
67
- aResponse ()
68
- .withStatus (503 )
69
- .withHeader ("Content-Type" , "text/plain" )
70
- .withBody ("Service Unavailable" )));
71
- try {
72
- metrics .getPodMetrics (namespace , "foo=bar" );
73
- failBecauseExceptionWasNotThrown (ApiException .class );
74
- } catch (ApiException ex ) {
75
- assertThat (ex .getCode ()).isEqualTo (503 );
76
- }
61
+ get (urlPathMatching ("^/apis/metrics.k8s.io/v1beta1/namespaces/" + namespace + "/pods.*" ))
62
+ .willReturn (
63
+ aResponse ()
64
+ .withStatus (503 )
65
+ .withHeader ("Content-Type" , "text/plain" )
66
+ .withBody ("Service Unavailable" )));
67
+ assertThrows (ApiException .class , () -> metrics .getPodMetrics (namespace , "foo=bar" ));
77
68
}
78
69
79
70
@ Test
@@ -86,11 +77,6 @@ void getNodeMetricsThrowsAPIExceptionWhenServerReturnsError() {
86
77
.withStatus (503 )
87
78
.withHeader ("Content-Type" , "text/plain" )
88
79
.withBody ("Service Unavailable" )));
89
- try {
90
- metrics .getNodeMetrics ();
91
- failBecauseExceptionWasNotThrown (ApiException .class );
92
- } catch (ApiException ex ) {
93
- assertThat (ex .getCode ()).isEqualTo (503 );
94
- }
80
+ assertThrows (ApiException .class , metrics ::getNodeMetrics );
95
81
}
96
82
}
0 commit comments