Skip to content

Commit 4b6c67b

Browse files
committed
Merge branch 'master' into all-is-typed
* master: Remove upper case constants (#113) Bump to 3.0.0-alpha+3 (#112) Switch back to Chrome for Travis (#104) Try using a staged, fancy travis config. (#100) Update travis script to actually run dartanalyzer (#102) verify*Interactions methods throw helpfully that they expect Mock (#92) First draft of upgrade guide for Mockito 3.0 (#96) Generic support for `thenReturn` and `thenAnswer` (#101) Remove references to `@proxy`. (#99) Remove Spy docs (#97) Remove mirrors implementation (#91)
2 parents b027593 + e7b5151 commit 4b6c67b

16 files changed

+388
-233
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See https://www.dartlang.org/guides/libraries/private-files
22

33
# Files and directories created by pub
4+
.dart_tool
45
.packages
56
.pub
67
pubspec.lock

.travis.yml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
language: dart
2-
sudo: false
3-
dart:
4-
- dev
5-
script: ./tool/travis.sh
2+
3+
# Gives more resources on Travis (8GB Ram, 2 CPUs).
4+
# Do not remove without verifying w/ Travis.
5+
sudo: required
6+
addons:
7+
chrome: stable
8+
9+
# Build stages: https://docs.travis-ci.com/user/build-stages/.
10+
stages:
11+
- presubmit
12+
- build
13+
- testing
14+
15+
# 1. Run dartfmt, dartanalyzer, pub run test (VM).
16+
# 2. Then run a build.
17+
# 3. Then run tests compiled via dartdevc and dart2js.
18+
jobs:
19+
include:
20+
- stage: presubmit
21+
script: ./tool/travis.sh dartfmt
22+
dart: dev
23+
- stage: presubmit
24+
script: ./tool/travis.sh dartanalyzer
25+
dart: dev
26+
- stage: presubmit
27+
script: ./tool/travis.sh vm_test
28+
dart: dev
29+
- stage: build
30+
script: ./tool/travis.sh dartdevc_build
31+
dart: dev
32+
- stage: testing
33+
script: ./tool/travis.sh dartdevc_test
34+
dart: dev
35+
- stage: testing
36+
script: ./tool/travis.sh dart2js_test
37+
dart: dev
38+
39+
# Only building master means that we don't run two builds for each pull request.
40+
branches:
41+
only: [master]
42+
43+
# Incremental pub cache and builds.
44+
cache:
45+
directories:
46+
- $HOME/.pub-cache
47+
- .dart_tool
48+
49+
# Necessary for Chrome and Firefox to run
50+
before_install:
51+
- export DISPLAY=:99.0
52+
- sh -e /etc/init.d/xvfb start
53+
- "t=0; until (xdpyinfo -display :99 &> /dev/null || test $t -gt 10); do sleep 1; let t=$t+1; done"

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
## 3.0.0
1+
## 3.0.0-alpha+3
2+
3+
* `thenReturn` and `thenAnswer` now support generics and infer the correct
4+
types from the `when` call.
5+
* Completely remove the mirrors implementation of Mockito (`mirrors.dart`).
6+
7+
## 3.0.0-alpha+2
8+
9+
* Support stubbing of void methods in Dart 2.
10+
11+
## 3.0.0-alpha
212

313
* `thenReturn` now throws an `ArgumentError` if either a `Future` or `Stream`
414
is provided. `thenReturn` calls with futures and streams should be changed to

README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,6 @@ when(cat.eatFood(any)).thenReturn(false);
295295
expect(cat.eatFood("Fish"), false);
296296
```
297297

298-
## Spy
299-
300-
```dart
301-
// Spy creation:
302-
var cat = spy(new MockCat(), new Cat());
303-
304-
// Stubbing - before execution:
305-
when(cat.sound()).thenReturn("Purr");
306-
307-
// Using mocked interaction:
308-
expect(cat.sound(), "Purr");
309-
310-
// Using a real object:
311-
expect(cat.lives, 9);
312-
```
313-
314298
## Debugging
315299

316300
```dart

dart_test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TODO(https://github.com/dart-lang/test/issues/772): Headless chrome timeout.
2+
override_platforms:
3+
chrome:
4+
settings:
5+
headless: false

lib/mirrors.dart

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/src/mock.dart

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Warning: Do not import dart:mirrors in this library, as it's exported via
16-
// lib/mockito.dart, which is used for Dart AOT projects such as Flutter.
17-
1815
import 'dart:async';
1916

2017
import 'package:meta/meta.dart';
@@ -316,8 +313,8 @@ void clearInteractions(var mock) {
316313
mock._realCalls.clear();
317314
}
318315

319-
class PostExpectation {
320-
thenReturn(expected) {
316+
class PostExpectation<T> {
317+
void thenReturn(T expected) {
321318
if (expected is Future) {
322319
throw new ArgumentError(
323320
'`thenReturn` should not be used to return a Future. '
@@ -331,22 +328,20 @@ class PostExpectation {
331328
return _completeWhen((_) => expected);
332329
}
333330

334-
thenThrow(throwable) {
331+
void thenThrow(throwable) {
335332
return _completeWhen((_) {
336333
throw throwable;
337334
});
338335
}
339336

340-
thenAnswer(Answering answer) {
337+
void thenAnswer(Answering<T> answer) {
341338
return _completeWhen(answer);
342339
}
343340

344-
_completeWhen(Answering answer) {
341+
void _completeWhen(Answering answer) {
345342
_whenCall._setExpected(answer);
346-
var mock = _whenCall.mock;
347343
_whenCall = null;
348344
_whenInProgress = false;
349-
return mock;
350345
}
351346
}
352347

@@ -631,7 +626,7 @@ class VerificationResult {
631626
}
632627
}
633628

634-
typedef dynamic Answering(Invocation realInvocation);
629+
typedef T Answering<T>(Invocation realInvocation);
635630

636631
typedef Verification = VerificationResult Function<T>(T matchingInvocations);
637632

@@ -732,21 +727,32 @@ _InOrderVerification get verifyInOrder {
732727
};
733728
}
734729

730+
void _throwMockArgumentError(method) =>
731+
throw new ArgumentError('$method must only be given a Mock object');
732+
735733
void verifyNoMoreInteractions(var mock) {
736-
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
737-
if (unverified.isNotEmpty) {
738-
fail("No more calls expected, but following found: " + unverified.join());
734+
if (mock is Mock) {
735+
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
736+
if (unverified.isNotEmpty) {
737+
fail("No more calls expected, but following found: " + unverified.join());
738+
}
739+
} else {
740+
_throwMockArgumentError('verifyNoMoreInteractions');
739741
}
740742
}
741743

742744
void verifyZeroInteractions(var mock) {
743-
if (mock._realCalls.isNotEmpty) {
744-
fail("No interaction expected, but following found: " +
745-
mock._realCalls.join());
745+
if (mock is Mock) {
746+
if (mock._realCalls.isNotEmpty) {
747+
fail("No interaction expected, but following found: " +
748+
mock._realCalls.join());
749+
}
750+
} else {
751+
_throwMockArgumentError('verifyZeroInteractions');
746752
}
747753
}
748754

749-
typedef Expectation = PostExpectation Function<T>(T x);
755+
typedef Expectation = PostExpectation<T> Function<T>(T x);
750756

751757
/// Create a stub method response.
752758
///
@@ -772,7 +778,7 @@ Expectation get when {
772778
_whenInProgress = true;
773779
return <T>(T _) {
774780
_whenInProgress = false;
775-
return new PostExpectation();
781+
return new PostExpectation<T>();
776782
};
777783
}
778784

lib/src/spy.dart

Lines changed: 0 additions & 36 deletions
This file was deleted.

pubspec.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: mockito
2-
version: 3.0.0-alpha
2+
version: 3.0.0-alpha+3
33
authors:
44
- Dmitriy Fibulwinter <fibulwinter@gmail.com>
55
- Dart Team <misc@dartlang.org>
66
description: A mock framework inspired by Mockito.
77
homepage: https://github.com/dart-lang/mockito
88
environment:
99
sdk: '>=2.0.0-dev.16.0 <2.0.0'
10+
1011
dependencies:
1112
collection: '^1.1.0'
1213
matcher: '^0.12.0'
1314
meta: '^1.0.4'
1415
test: '>=0.12.25 <0.13.0'
16+
17+
dev_dependencies:
18+
build_runner: ^0.7.11
19+
build_test: ^0.10.0
20+
build_web_compilers: ^0.3.1

test/example/iss/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ The unit test, `iss_dart.test`, mocks the IssLocator class:
2525

2626
```
2727
// The Mock class uses noSuchMethod to catch all method invocations.
28-
// The @proxy annotation indicates that noSuchMethod calls should be
29-
// handled gracefully. For more info, see the readme for package:mockito.
30-
@proxy
3128
class MockIssLocator extends Mock implements IssLocator {}
3229
```
3330
The tests check for two scenarios:

test/example/iss/iss.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IssLocator {
4242
// Returns the point on the earth directly under the space station
4343
// at this moment.
4444
Response rs = await client.get('http://api.open-notify.org/iss-now.json');
45-
Map data = JSON.decode(rs.body);
45+
Map data = jsonDecode(rs.body);
4646
double latitude = double.parse(data['iss_position']['latitude']);
4747
double longitude = double.parse(data['iss_position']['longitude']);
4848
_position = new Point<double>(latitude, longitude);

0 commit comments

Comments
 (0)