1212import com .fasterxml .jackson .databind .ObjectMapper ;
1313
1414import java .lang .reflect .Field ;
15+ import java .util .concurrent .atomic .AtomicLong ;
1516
1617import static org .assertj .core .api .Assertions .assertThat ;
1718
@@ -113,7 +114,7 @@ void metricsEndpoint_shouldReturnCorrectVersion() throws Exception {
113114 JsonNode json = objectMapper .readTree (body );
114115
115116 // Then: Version should match App.VERSION
116- assertThat (json .get ("version" ).asText ()).isEqualTo (App .VERSION . toString () );
117+ assertThat (json .get ("version" ).floatValue ()).isEqualTo (App .VERSION );
117118 return null ;
118119 });
119120 }
@@ -137,7 +138,7 @@ void metricsEndpoint_shouldReturnUptime() throws Exception {
137138 JsonNode json = objectMapper .readTree (body );
138139
139140 // Then: Uptime should be greater than 5000ms
140- long uptime = Long . parseLong ( json .get ("uptime" ).asText () );
141+ long uptime = json .get ("uptime" ).asLong ( );
141142 assertThat (uptime ).isGreaterThanOrEqualTo (5000 );
142143 return null ;
143144 });
@@ -164,7 +165,7 @@ void metricsEndpoint_shouldReturnNumberOfRequests() throws Exception {
164165 JsonNode json = objectMapper .readTree (body );
165166
166167 // Then: Should return correct request count
167- assertThat (json .get ("numberOfRequests" ).asText ()).isEqualTo ("3" );
168+ assertThat (json .get ("numberOfRequests" ).asLong ()).isEqualTo (3 );
168169 return null ;
169170 });
170171 }
@@ -220,14 +221,14 @@ void metricsEndpoint_shouldHandleMultipleRequests() throws Exception {
220221 private void resetStatistics () throws Exception {
221222 Field requestsField = Statistics .class .getDeclaredField ("numberOfRequests" );
222223 requestsField .setAccessible (true );
223- requestsField .setLong (null , 0 );
224+ (( AtomicLong ) requestsField .get (null )). set ( 0 );
224225
225226 Field bytesField = Statistics .class .getDeclaredField ("bytesTransferred" );
226227 bytesField .setAccessible (true );
227- bytesField .setLong (null , 0 );
228+ (( AtomicLong ) bytesField .get (null )). set ( 0 );
228229
229230 Field startTimeField = Statistics .class .getDeclaredField ("startTime" );
230231 startTimeField .setAccessible (true );
231- startTimeField .setLong (null , 0 );
232+ (( AtomicLong ) startTimeField .get (null )). set ( 0 );
232233 }
233234}
0 commit comments