Skip to content

Commit

Permalink
Add mock mixins of Chopper components. (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotori authored Oct 26, 2023
1 parent f061355 commit e5417d1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
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> {}

0 comments on commit e5417d1

Please sign in to comment.