Merge pull request #42 from matanlurey/flip_api_defaults

Move all mirrors-based API to mirrors.dart
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d20582b..89117a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 2.0.0-dev
+
+* Remove export of `spy` and any `dart:mirrors` based API from
+  `mockito.dart`. Users may import as `package:mockito/mirrors.dart`
+  going forward.
+* Deprecated `mockito_no_mirrors.dart`; replace with `mockito.dart`.
+
 ## 1.0.1
 
 * Add a new `thenThrow` method to the API.
diff --git a/lib/mirrors.dart b/lib/mirrors.dart
new file mode 100644
index 0000000..18a7952
--- /dev/null
+++ b/lib/mirrors.dart
@@ -0,0 +1,2 @@
+export 'mockito.dart';
+export 'src/spy.dart' show spy;
diff --git a/lib/mockito.dart b/lib/mockito.dart
index 44a2e01..f204c69 100644
--- a/lib/mockito.dart
+++ b/lib/mockito.dart
@@ -1,2 +1,29 @@
-export 'mockito_no_mirrors.dart';
-export 'src/spy.dart' show spy;
+export 'src/mock.dart'
+    show
+    Mock,
+    named,
+
+    // -- setting behaviour
+    when,
+    any,
+    argThat,
+    captureAny,
+    captureThat,
+    typed,
+    Answering,
+    Expectation,
+    PostExpectation,
+
+    // -- verification
+    verify,
+    verifyInOrder,
+    verifyNever,
+    verifyNoMoreInteractions,
+    verifyZeroInteractions,
+    VerificationResult,
+    Verification,
+
+    // -- misc
+    clearInteractions,
+    reset,
+    logInvocations;
diff --git a/lib/mockito_no_mirrors.dart b/lib/mockito_no_mirrors.dart
index eaecec0..c6f7da4 100644
--- a/lib/mockito_no_mirrors.dart
+++ b/lib/mockito_no_mirrors.dart
@@ -1,29 +1,4 @@
-export 'src/mock.dart'
-    show
-        Mock,
-        named,
+@Deprecated('Import "package:mockito/mockito.dart" instead.')
+library mockito.mockito_no_mirrors;
 
-        // -- setting behaviour
-        when,
-        any,
-        argThat,
-        captureAny,
-        captureThat,
-        typed,
-        Answering,
-        Expectation,
-        PostExpectation,
-
-        // -- verification
-        verify,
-        verifyInOrder,
-        verifyNever,
-        verifyNoMoreInteractions,
-        verifyZeroInteractions,
-        VerificationResult,
-        Verification,
-
-        // -- misc
-        clearInteractions,
-        reset,
-        logInvocations;
+export 'mockito.dart';
diff --git a/lib/src/mock.dart b/lib/src/mock.dart
index c19aca9..6091ba4 100644
--- a/lib/src/mock.dart
+++ b/lib/src/mock.dart
@@ -1,6 +1,5 @@
 // Warning: Do not import dart:mirrors in this library, as it's exported via
-// lib/mockito_no_mirrors.dart, which is used for Dart AOT projects such as
-// Flutter.
+// lib/mockito.dart, which is used for Dart AOT projects such as Flutter.
 
 import 'package:meta/meta.dart';
 import 'package:test/test.dart';
diff --git a/lib/src/spy.dart b/lib/src/spy.dart
index d7fbccd..08966ae 100644
--- a/lib/src/spy.dart
+++ b/lib/src/spy.dart
@@ -1,11 +1,17 @@
 // This file is intentionally separated from 'mock.dart' in order to avoid
-// bringing in the mirrors dependency into mockito_no_mirrors.dart.
+// bringing in the mirrors dependency into mockito.dart.
 import 'dart:mirrors';
 
-import 'mock.dart' show CannedResponse, setDefaultResponse;
+import 'mock.dart' show CannedResponse, Mock, setDefaultResponse;
 
-dynamic spy(dynamic mock, dynamic spiedObject) {
-  var mirror = reflect(spiedObject);
+/// Sets the default response of [mock] to be delegated to [spyOn].
+///
+/// __Example use__:
+///     var mockAnimal = new MockAnimal();
+///     var realAnimal = new RealAnimal();
+///     spy(mockAnimal, realAnimal);
+/*=E*/ spy/*<E>*/(Mock mock, Object /*=E*/ spyOn) {
+  var mirror = reflect(spyOn);
   setDefaultResponse(
       mock,
       () => new CannedResponse(null,
diff --git a/test/invocation_matcher_test.dart b/test/invocation_matcher_test.dart
index d148196..31ed88d 100644
--- a/test/invocation_matcher_test.dart
+++ b/test/invocation_matcher_test.dart
@@ -54,7 +54,7 @@
       var call2 = stub.value;
       stub.value = true;
       var call3 = Stub.lastInvocation;
-      shouldPass(call1, isInvocation(call2));
+      shouldPass(call1, isInvocation(call2 as Invocation));
       shouldFail(
         call1,
         isInvocation(call3),
diff --git a/test/mockito_test.dart b/test/mockito_test.dart
index 2dd4b9b..b203bca 100644
--- a/test/mockito_test.dart
+++ b/test/mockito_test.dart
@@ -1,8 +1,7 @@
+import 'package:mockito/mockito.dart';
+import 'package:mockito/src/mock.dart' show resetMockitoState;
 import 'package:test/test.dart';
 
-import 'package:mockito/src/mock.dart';
-import 'package:mockito/src/spy.dart';
-
 class RealClass {
   String methodWithoutArgs() => "Real";
   String methodWithNormalArgs(int x) => "Real";
@@ -69,24 +68,6 @@
     resetMockitoState();
   });
 
-  group("spy", () {
-    setUp(() {
-      mock = spy(new MockedClass(), new RealClass());
-    });
-
-    test("should delegate to real object by default", () {
-      expect(mock.methodWithoutArgs(), 'Real');
-    });
-    test("should record interactions delegated to real object", () {
-      mock.methodWithoutArgs();
-      verify(mock.methodWithoutArgs());
-    });
-    test("should behave as mock when expectation are set", () {
-      when(mock.methodWithoutArgs()).thenReturn('Spied');
-      expect(mock.methodWithoutArgs(), 'Spied');
-    });
-  });
-
   group("mixin support", () {
     test("should work", () {
       var foo = new MockFoo();
diff --git a/test/spy_test.dart b/test/spy_test.dart
new file mode 100644
index 0000000..4ebfa60
--- /dev/null
+++ b/test/spy_test.dart
@@ -0,0 +1,37 @@
+import 'package:mockito/src/mock.dart' show resetMockitoState;
+import 'package:mockito/mirrors.dart';
+import 'package:test/test.dart';
+
+import 'mockito_test.dart' show MockedClass, RealClass;
+
+void main() {
+  RealClass mock;
+
+  setUp(() {
+    mock = new MockedClass();
+  });
+
+  tearDown(() {
+    // In some of the tests that expect an Error to be thrown, Mockito's
+    // global state can become invalid. Reset it.
+    resetMockitoState();
+  });
+
+  group("spy", () {
+    setUp(() {
+      mock = spy/*<RealClass>*/(new MockedClass(), new RealClass());
+    });
+
+    test("should delegate to real object by default", () {
+      expect(mock.methodWithoutArgs(), 'Real');
+    });
+    test("should record interactions delegated to real object", () {
+      mock.methodWithoutArgs();
+      verify(mock.methodWithoutArgs());
+    });
+    test("should behave as mock when expectation are set", () {
+      when(mock.methodWithoutArgs()).thenReturn('Spied');
+      expect(mock.methodWithoutArgs(), 'Spied');
+    });
+  });
+}