Deprecate two APIs (#202)
Deprecate two APIs; 4.1.1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d1e31a..5f99597 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 4.1.1
+
+* Mark the unexported and accidentally public `setDefaultResponse` as
+ deprecated.
+* Mark the not useful, and not generally used, `named` function as deprecated.
+
## 4.1.0
* Add a `Fake` class for implementing a subset of a class API as overrides
diff --git a/lib/mockito.dart b/lib/mockito.dart
index 87da9da..10fb4c5 100644
--- a/lib/mockito.dart
+++ b/lib/mockito.dart
@@ -16,7 +16,7 @@
show
Fake,
Mock,
- named,
+ named, // ignore: deprecated_member_use_from_same_package
// -- setting behaviour
when,
diff --git a/lib/src/mock.dart b/lib/src/mock.dart
index 2d43a95..b18f187 100644
--- a/lib/src/mock.dart
+++ b/lib/src/mock.dart
@@ -34,7 +34,9 @@
final List<ArgMatcher> _storedArgs = <ArgMatcher>[];
final Map<String, ArgMatcher> _storedNamedArgs = <String, ArgMatcher>{};
-// Hidden from the public API, used by spy.dart.
+@Deprecated(
+ 'This function is not a supported function, and may be deleted as early as '
+ 'Mockito 5.0.0')
void setDefaultResponse(Mock mock, CallPair<dynamic> defaultResponse()) {
mock._defaultResponse = defaultResponse;
}
@@ -364,6 +366,10 @@
this.namedArguments, this.isGetter, this.isMethod, this.isSetter);
}
+@Deprecated(
+ 'This function does not provide value; hashCode and toString() can be '
+ 'stubbed individually. This function may be deleted as early as Mockito '
+ '5.0.0')
T named<T extends Mock>(T mock, {String name, int hashCode}) => mock
.._givenName = name
.._givenHashCode = hashCode;
diff --git a/pubspec.yaml b/pubspec.yaml
index e777a8c..b291b6d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: mockito
-version: 4.1.0
+version: 4.1.1
authors:
- Dmitriy Fibulwinter <fibulwinter@gmail.com>
diff --git a/test/deprecated_apis/mockito_test.dart b/test/deprecated_apis/mockito_test.dart
index f7bf7bc..95dbcb4 100644
--- a/test/deprecated_apis/mockito_test.dart
+++ b/test/deprecated_apis/mockito_test.dart
@@ -134,5 +134,21 @@
.thenReturn("42");
expect(mock.methodWithNormalArgs(43), equals("43"));
});
+
+ test("should mock hashCode", () {
+ named(mock, hashCode: 42);
+ expect(mock.hashCode, equals(42));
+ });
+
+ test("should have toString as name when it is not mocked", () {
+ named(mock, name: "Cat");
+ expect(mock.toString(), equals("Cat"));
+ });
+
+ test("should mock equals between mocks when givenHashCode is equals", () {
+ var anotherMock = named(_MockedClass(), hashCode: 42);
+ named(mock, hashCode: 42);
+ expect(mock == anotherMock, isTrue);
+ });
});
}
diff --git a/test/deprecated_apis/verify_test.dart b/test/deprecated_apis/verify_test.dart
index 21a5fb4..a8c870c 100644
--- a/test/deprecated_apis/verify_test.dart
+++ b/test/deprecated_apis/verify_test.dart
@@ -121,5 +121,16 @@
verify(mock.methodWithPositionalArgs(
typed(argThat(greaterThanOrEqualTo(100))), 17));
});
+
+ test('should mock method with mock args', () {
+ var m1 = named(_MockedClass(), name: 'm1');
+ mock.methodWithObjArgs(m1);
+ expectFail(
+ 'No matching calls. All calls: _MockedClass.methodWithObjArgs(m1)\n'
+ '$noMatchingCallsFooter', () {
+ verify(mock.methodWithObjArgs(_MockedClass()));
+ });
+ verify(mock.methodWithObjArgs(m1));
+ });
});
}
diff --git a/test/mockito_test.dart b/test/mockito_test.dart
index 754b76d..ff872f4 100644
--- a/test/mockito_test.dart
+++ b/test/mockito_test.dart
@@ -181,11 +181,6 @@
expect(mock.getter, equals("A"));
});
- test("should mock hashCode", () {
- named(mock, hashCode: 42);
- expect(mock.hashCode, equals(42));
- });
-
test("should have hashCode when it is not mocked", () {
expect(mock.hashCode, isNotNull);
});
@@ -194,17 +189,6 @@
expect(mock.toString(), equals("_MockedClass"));
});
- test("should have toString as name when it is not mocked", () {
- named(mock, name: "Cat");
- expect(mock.toString(), equals("Cat"));
- });
-
- test("should mock equals between mocks when givenHashCode is equals", () {
- var anotherMock = named(_MockedClass(), hashCode: 42);
- named(mock, hashCode: 42);
- expect(mock == anotherMock, isTrue);
- });
-
test("should use identical equality between it is not mocked", () {
var anotherMock = _MockedClass();
expect(mock == anotherMock, isFalse);
diff --git a/test/verify_test.dart b/test/verify_test.dart
index 2b0b176..0c41c29 100644
--- a/test/verify_test.dart
+++ b/test/verify_test.dart
@@ -128,17 +128,6 @@
verify(mock.methodWithNamedArgs(42, y: 17));
});
- test('should mock method with mock args', () {
- var m1 = named(_MockedClass(), name: 'm1');
- mock.methodWithObjArgs(m1);
- expectFail(
- 'No matching calls. All calls: _MockedClass.methodWithObjArgs(m1)\n'
- '$noMatchingCallsFooter', () {
- verify(mock.methodWithObjArgs(_MockedClass()));
- });
- verify(mock.methodWithObjArgs(m1));
- });
-
test('should mock method with list args', () {
mock.methodWithListArgs([42]);
expectFail(