Skip to content

Commit edf5941

Browse files
committed
fix: Change lastRequest from static to instance variable
- Remove static modifier from lastRequest field in RequestCapturingMock - Update all references to use instance variable (mock.lastRequest) instead of static - Fix compilation error: static can only be used on fields of a top level type - Maintain request capture functionality for test assertions
1 parent 040c4e9 commit edf5941

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

force-app/main/default/classes/NebulaAdapter_Test.cls

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
private class NebulaAdapter_Test {
33
// Mock that implements HttpCalloutMock and uses HttpCalloutMockFactory for response generation
44
public class RequestCapturingMock implements HttpCalloutMock {
5-
public static HttpRequest lastRequest;
5+
public HttpRequest lastRequest;
66
private HttpResponse mockResponse;
77

88
@SuppressWarnings('PMD.ExcessiveParameterList')
@@ -59,16 +59,16 @@ private class NebulaAdapter_Test {
5959
System.assert(res.getBody().contains('"ok":true'), 'Response body should contain ok:true');
6060

6161
// Assert — request captured by mock
62-
System.assertEquals('POST', RequestCapturingMock.lastRequest.getMethod(), 'Should use POST method');
63-
System.assert(RequestCapturingMock.lastRequest.getEndpoint().startsWith('callout:'),
62+
System.assertEquals('POST', mock.lastRequest.getMethod(), 'Should use POST method');
63+
System.assert(mock.lastRequest.getEndpoint().startsWith('callout:'),
6464
'Endpoint should use callout:NamedCredential...');
65-
System.assertEquals('{"hello":"world"}', RequestCapturingMock.lastRequest.getBody(), 'Should have correct body');
66-
System.assertEquals('application/json', RequestCapturingMock.lastRequest.getHeader('Content-Type'), 'Should have correct Content-Type');
67-
System.assertEquals('abc123', RequestCapturingMock.lastRequest.getHeader('X-Custom'), 'Should have correct X-Custom header');
65+
System.assertEquals('{"hello":"world"}', mock.lastRequest.getBody(), 'Should have correct body');
66+
System.assertEquals('application/json', mock.lastRequest.getHeader('Content-Type'), 'Should have correct Content-Type');
67+
System.assertEquals('abc123', mock.lastRequest.getHeader('X-Custom'), 'Should have correct X-Custom header');
6868

6969
// Nebula adapter should safely no-op (no exception thrown)
7070
NebulaAdapter.info('Just a test log', a);
71-
NebulaAdapter.logHttpRequest('Req', RequestCapturingMock.lastRequest, new List<String>{'X-Custom'}, a);
71+
NebulaAdapter.logHttpRequest('Req', mock.lastRequest, new List<String>{'X-Custom'}, a);
7272
NebulaAdapter.logHttpResponse('Res', res, a);
7373
// If Nebula isn't installed, the above calls should silently do nothing.
7474
}
@@ -105,9 +105,9 @@ private class NebulaAdapter_Test {
105105
System.assertEquals(200, res.getStatusCode(), 'Should get 200 OK');
106106

107107
// Assert — request
108-
System.assertEquals('DELETE', RequestCapturingMock.lastRequest.getMethod(), 'DEL should map to DELETE');
109-
System.assertEquals('application/json', RequestCapturingMock.lastRequest.getHeader('Accept'), 'Should have correct Accept header');
110-
System.assertEquals(null, RequestCapturingMock.lastRequest.getBody(), 'DELETE should not have a body by default');
108+
System.assertEquals('DELETE', mock.lastRequest.getMethod(), 'DEL should map to DELETE');
109+
System.assertEquals('application/json', mock.lastRequest.getHeader('Accept'), 'Should have correct Accept header');
110+
System.assertEquals(null, mock.lastRequest.getBody(), 'DELETE should not have a body by default');
111111

112112
// Nebula adapter no-ops again
113113
NebulaAdapter.debug('Another test log', a);

0 commit comments

Comments
 (0)