Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mock mixins of Chopper components. #529

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions chopper/lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,17 @@ base class ChopperClient {
Stream<Response> get onResponse => _responseController.stream;
}

///
/// [ChopperClient] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockChopperClient extends Mock with MockChopperClientMixin {}
/// ```
///
@visibleForTesting
base mixin MockChopperClientMixin implements ChopperClient {}

/// A marker and helper class used by `chopper_generator` to generate network
/// call implementations.
///
Expand Down
12 changes: 12 additions & 0 deletions chopper/lib/src/chopper_log_record.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:meta/meta.dart';

final class ChopperLogRecord {
const ChopperLogRecord(this.message, {this.request, this.response});
Expand All @@ -11,3 +12,14 @@ final class ChopperLogRecord {
@override
String toString() => message;
}

///
/// [ChopperLogRecord] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockChopperLogRecord extends Mock with MockChopperLogRecordMixin {}
/// ```
///
@visibleForTesting
base mixin MockChopperLogRecordMixin implements ChopperLogRecord {}
33 changes: 33 additions & 0 deletions chopper/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ base class Request extends http.BaseRequest with EquatableMixin {
];
}

///
/// [Request] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockRequest extends Mock with MockRequestMixin {}
/// ```
///
@visibleForTesting
base mixin MockRequestMixin implements Request {}

/// Represents a part in a multipart request.
@immutable
final class PartValue<T> with EquatableMixin {
Expand All @@ -263,8 +274,30 @@ final class PartValue<T> with EquatableMixin {
];
}

///
/// [PartValue] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockPartValue<T> extends Mock with MockPartValueMixin<T> {}
/// ```
///
@visibleForTesting
base mixin MockPartValueMixin<T> implements PartValue<T> {}

/// Represents a file [PartValue] in a multipart request.
@immutable
final class PartValueFile<T> extends PartValue<T> {
const PartValueFile(super.name, super.value);
}

///
/// [PartValueFile] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockPartValueFile<T> extends Mock with MockPartValueFileMixin<T> {}
/// ```
///
@visibleForTesting
base mixin MockPartValueFileMixin<T> implements PartValueFile<T> {}
11 changes: 11 additions & 0 deletions chopper/lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ base class Response<BodyType> with EquatableMixin {
error,
];
}

///
/// [Response] mixin for the purposes of creating mocks
/// using a mocking framework such as Mockito or Mocktail.
///
/// ```dart
/// base class MockResponse<BodyType> extends Mock with MockResponseMixin<BodyType> {}
/// ```
///
@visibleForTesting
base mixin MockResponseMixin<BodyType> implements Response<BodyType> {}