Skip to content

Commit a283716

Browse files
authored
Add eq, toString and hash methods to HttpProfileRedirectData (#1165)
1 parent 70cf298 commit a283716

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

pkgs/http_profile/lib/src/http_profile_response_data.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ class HttpProfileRedirectData {
3636
'method': _method,
3737
'location': _location,
3838
};
39+
40+
@override
41+
bool operator ==(Object other) =>
42+
(other is HttpProfileRedirectData) &&
43+
(statusCode == other.statusCode &&
44+
method == other.method &&
45+
location == other.location);
46+
47+
@override
48+
int get hashCode => Object.hashAll([statusCode, method, location]);
49+
50+
@override
51+
String toString() =>
52+
'HttpProfileRedirectData(statusCode: $statusCode, method: $method, '
53+
'location: $location)';
3954
}
4055

4156
/// Describes details about a response to an HTTP request.

pkgs/http_profile/test/http_profile_response_data_test.dart

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,48 @@ void main() {
2626
backingMap = profileBackingMaps.lastOrNull!;
2727
});
2828

29+
group('HttpProfileRedirectData', () {
30+
test('equal', () {
31+
expect(
32+
HttpProfileRedirectData(
33+
statusCode: 302, method: 'GET', location: 'http://somewhere'),
34+
HttpProfileRedirectData(
35+
statusCode: 302, method: 'GET', location: 'http://somewhere'));
36+
});
37+
38+
test('not equal', () {
39+
expect(
40+
HttpProfileRedirectData(
41+
statusCode: 302, method: 'GET', location: 'http://somewhere'),
42+
isNot(Object()));
43+
expect(
44+
HttpProfileRedirectData(
45+
statusCode: 302, method: 'GET', location: 'http://somewhere'),
46+
isNot(HttpProfileRedirectData(
47+
statusCode: 303, method: 'GET', location: 'http://somewhere')));
48+
expect(
49+
HttpProfileRedirectData(
50+
statusCode: 302, method: 'GET', location: 'http://somewhere'),
51+
isNot(HttpProfileRedirectData(
52+
statusCode: 302, method: 'POST', location: 'http://somewhere')));
53+
expect(
54+
HttpProfileRedirectData(
55+
statusCode: 302, method: 'GET', location: 'http://somewhere'),
56+
isNot(HttpProfileRedirectData(
57+
statusCode: 302, method: 'GET', location: 'http://notthere')));
58+
});
59+
60+
test('hash', () {
61+
expect(
62+
HttpProfileRedirectData(
63+
statusCode: 302, method: 'GET', location: 'http://somewhere')
64+
.hashCode,
65+
HttpProfileRedirectData(
66+
statusCode: 302, method: 'GET', location: 'http://somewhere')
67+
.hashCode);
68+
});
69+
});
70+
2971
test('calling HttpClientRequestProfile.responseData.addRedirect', () async {
3072
final responseData = backingMap['responseData'] as Map<String, dynamic>;
3173
final redirectsFromBackingMap =
@@ -45,11 +87,13 @@ void main() {
4587
expect(redirectFromBackingMap['method'], 'GET');
4688
expect(redirectFromBackingMap['location'], 'https://images.example.com/1');
4789

48-
expect(profile.responseData.redirects.length, 1);
49-
final redirectFromGetter = profile.responseData.redirects.first;
50-
expect(redirectFromGetter.statusCode, 301);
51-
expect(redirectFromGetter.method, 'GET');
52-
expect(redirectFromGetter.location, 'https://images.example.com/1');
90+
expect(profile.responseData.redirects, [
91+
HttpProfileRedirectData(
92+
statusCode: 301,
93+
method: 'GET',
94+
location: 'https://images.example.com/1',
95+
)
96+
]);
5397
});
5498

5599
test('populating HttpClientRequestProfile.responseData.headersListValues',

0 commit comments

Comments
 (0)