Skip to content
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
4 changes: 2 additions & 2 deletions lib/mockito.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'src/mock.dart' hide setDefaultResponse;
export 'src/spy.dart';
export 'mockito_no_mirrors.dart';
export 'src/spy.dart' show spy;
30 changes: 29 additions & 1 deletion lib/mockito_no_mirrors.dart
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
export 'src/mock.dart' hide setDefaultResponse;
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;
74 changes: 37 additions & 37 deletions lib/src/mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ class InvocationMatcher {
bool isMatchingArg(roleArg, actArg) {
if (roleArg is _ArgMatcher) {
return roleArg._matcher.matches(actArg, {});
// } else if(roleArg is Mock){
// return identical(roleArg, actArg);
} else {
return equals(roleArg).matches(actArg, {});
}
Expand All @@ -385,47 +383,49 @@ class _TimeStampProvider {
}

class RealCall {
// This used to use MirrorSystem, which cleans up the Symbol() wrapper.
// Since this toString method is just used in Mockito's own tests, it's not
// a big deal to massage the toString a bit.
//
// Input: Symbol("someMethodName")
static String _symbolToString(Symbol symbol) {
return symbol.toString().split('"')[1];
}

DateTime _timeStamp;
final Mock mock;
final Invocation invocation;
final DateTime timeStamp;

bool verified = false;
RealCall(this.mock, this.invocation) {
_timeStamp = _timer.now();
}

DateTime get timeStamp => _timeStamp;
RealCall(this.mock, this.invocation) : timeStamp = _timer.now();

String toString() {
var verifiedText = verified ? "[VERIFIED] " : "";
List<String> posArgs = invocation.positionalArguments
var args = invocation.positionalArguments
.map((v) => v == null ? "null" : v.toString())
.toList();
List<String> mapArgList = invocation.namedArguments.keys.map((key) {
return "${_symbolToString(key)}: ${invocation.namedArguments[key]}";
}).toList(growable: false);
if (mapArgList.isNotEmpty) {
posArgs.add("{${mapArgList.join(", ")}}");
.join(", ");
if (invocation.namedArguments.isNotEmpty) {
var namedArgs = invocation.namedArguments.keys
.map((key) =>
"${_symbolToString(key)}: ${invocation.namedArguments[key]}")
.join(", ");
args += ", {$namedArgs}";
}
String args = posArgs.join(", ");
String method = _symbolToString(invocation.memberName);

var method = _symbolToString(invocation.memberName);
if (invocation.isMethod) {
method = ".$method($args)";
method = "$method($args)";
} else if (invocation.isGetter) {
method = ".$method";
method = "$method";
} else if (invocation.isSetter) {
method = "$method=$args";
} else {
method = ".$method=$args";
throw new StateError(
'Invocation should be getter, setter or a method call.');
}
return "$verifiedText$mock$method";

var verifiedText = verified ? "[VERIFIED] " : "";
return "$verifiedText$mock.$method";
}

// This used to use MirrorSystem, which cleans up the Symbol() wrapper.
// Since this toString method is just used in Mockito's own tests, it's not
// a big deal to massage the toString a bit.
//
// Input: Symbol("someMethodName")
static String _symbolToString(Symbol symbol) =>
symbol.toString().split('"')[1];
}

class _WhenCall {
Expand Down Expand Up @@ -528,7 +528,7 @@ typedef dynamic Answering(Invocation realInvocation);

typedef VerificationResult Verification(matchingInvocations);

typedef void InOrderVerification(recordedInvocations);
typedef void _InOrderVerification(List<dynamic> recordedInvocations);

Verification get verifyNever => _makeVerify(true);

Expand All @@ -553,12 +553,12 @@ Verification _makeVerify(bool never) {
};
}

InOrderVerification get verifyInOrder {
_InOrderVerification get verifyInOrder {
if (_verifyCalls.isNotEmpty) {
throw new StateError(_verifyCalls.join());
}
_verificationInProgress = true;
return (verifyCalls) {
return (List<dynamic> _) {
_verificationInProgress = false;
DateTime dt = new DateTime.fromMillisecondsSinceEpoch(0);
var tmpVerifyCalls = new List.from(_verifyCalls);
Expand All @@ -584,9 +584,9 @@ InOrderVerification get verifyInOrder {
"Matching call #${tmpVerifyCalls.indexOf(verifyCall)} not found.$otherCalls");
}
}
matchedCalls.forEach((rc) {
rc.verified = true;
});
for (var call in matchedCalls) {
call.verified = true;
}
};
}

Expand Down Expand Up @@ -623,7 +623,7 @@ void logInvocations(List<Mock> mocks) {
});
}

/// Should only be used during Mockito testing.
/// Only for mockito testing.
void resetMockitoState() {
_whenInProgress = false;
_verificationInProgress = false;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mockito
version: 1.0.1+2
version: 2.0.0-dev
authors:
- Dmitriy Fibulwinter <fibulwinter@gmail.com>
- Ted Sander <tsander@google.com>
Expand Down
4 changes: 3 additions & 1 deletion test/mockito_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';

import 'package:mockito/src/mock.dart';
import 'package:mockito/src/spy.dart';

class RealClass {
String methodWithoutArgs() => "Real";
Expand Down