2
2
3
3
4
4
import static org .assertj .core .api .Assertions .assertThat ;
5
- import static org .mockito .ArgumentMatchers .any ;
6
- import static org .mockito .Mockito .when ;
7
5
8
6
import de .sldk .mc .MetricsServer ;
9
7
import de .sldk .mc .PrometheusExporter ;
10
8
import io .prometheus .client .CollectorRegistry ;
11
9
import io .prometheus .client .Counter ;
12
10
import io .prometheus .client .exporter .common .TextFormat ;
13
11
import io .restassured .RestAssured ;
14
- import org .bukkit .Server ;
15
- import org .bukkit .scheduler .BukkitScheduler ;
16
12
import org .eclipse .jetty .http .HttpStatus ;
17
13
import org .eclipse .jetty .util .URIUtil ;
18
14
import org .junit .jupiter .api .AfterEach ;
24
20
25
21
import java .io .IOException ;
26
22
import java .net .ServerSocket ;
27
- import java .util .concurrent .CompletableFuture ;
28
23
29
24
@ ExtendWith (MockitoExtension .class )
30
25
public class PrometheusExporterTest {
31
26
32
27
@ Mock
33
28
private PrometheusExporter exporterMock ;
34
- @ Mock
35
- private Server mockServer ;
36
- @ Mock
37
- private BukkitScheduler mockScheduler ;
38
29
39
30
private int metricsServerPort ;
40
31
private MetricsServer metricsServer ;
@@ -60,7 +51,6 @@ void cleanup() throws Exception {
60
51
61
52
@ Test
62
53
void metrics_server_should_return_valid_prometheus_response () {
63
- mockBukkitApis ();
64
54
mockPrometheusCounter ("mc_mock_metric" , "This is a mock metric" , 419 );
65
55
66
56
String requestPath = URIUtil .newURI ("http" , "localhost" , metricsServerPort , "/metrics" , null );
@@ -78,12 +68,6 @@ void metrics_server_should_return_valid_prometheus_response() {
78
68
assertThat (lines [2 ]).isEqualTo ("mc_mock_metric_total 419.0" );
79
69
}
80
70
81
- private void mockBukkitApis () {
82
- when (exporterMock .getServer ()).thenReturn (mockServer );
83
- when (mockServer .getScheduler ()).thenReturn (mockScheduler );
84
- when (mockScheduler .callSyncMethod (any (), any ())).thenReturn (CompletableFuture .completedFuture (null ));
85
- }
86
-
87
71
private void mockPrometheusCounter (String name , String help , int value ) {
88
72
Counter mockPrometheusCounter = Counter .build ().name (name ).help (help ).register ();
89
73
mockPrometheusCounter .inc (value );
0 commit comments