Skip to content

Commit

Permalink
Replace mockito with mocktail
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcegraph committed Apr 26, 2024
1 parent 957245e commit b644005
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion w_common/test/unit/browser/browser_stubs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import 'dart:html';

import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:w_common/disposable_browser.dart';

import '../stubs.dart';
Expand Down
22 changes: 11 additions & 11 deletions w_common/test/unit/browser/cache/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@TestOn('browser')

import 'dart:async';
import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import 'package:w_common/src/common/cache/cache.dart';
import 'package:w_common/src/common/cache/least_recently_used_strategy.dart';
Expand Down Expand Up @@ -108,7 +108,7 @@ void main() {
var mockCachingStrategy = MockCachingStrategy();
var childCache = Cache(mockCachingStrategy);
await childCache.get(cachedId, () => cachedValue);
verify(mockCachingStrategy.onDidGet(cachedId, cachedValue));
verify(() => mockCachingStrategy.onDidGet(cachedId, cachedValue));
});

test('should call onDidGet when value is cached', () async {
Expand All @@ -117,7 +117,7 @@ void main() {
await childCache.get(cachedId, () => cachedValue);
await childCache.get(cachedId, () => cachedValue);

verify(mockCachingStrategy.onDidGet(cachedId, cachedValue)).called(2);
verify(() => mockCachingStrategy.onDidGet(cachedId, cachedValue)).called(2);
});

test('should throw when disposed', () async {
Expand Down Expand Up @@ -200,15 +200,15 @@ void main() {
await childCache.get(cachedId, () => cachedValue);
await childCache.remove(cachedId);

verify(stubCachingStrategy.onDidRemove(cachedId, cachedValue));
verify(() => stubCachingStrategy.onDidRemove(cachedId, cachedValue));
});

test('should call onWillRemove when value was cached', () async {
var stubCachingStrategy = MockCachingStrategy();
var childCache = Cache(stubCachingStrategy);
await childCache.get(cachedId, () => cachedValue);
await childCache.remove(cachedId);
verify(stubCachingStrategy.onWillRemove(cachedId));
verify(() => stubCachingStrategy.onWillRemove(cachedId));
});

test('should not call onDidRemove when identifier is not cached',
Expand All @@ -217,7 +217,7 @@ void main() {
var childCache = Cache(stubCachingStrategy);
await childCache.remove(cachedId);

verifyNever(stubCachingStrategy.onDidRemove(cachedId, cachedValue));
verifyNever(() => stubCachingStrategy.onDidRemove(cachedId, cachedValue));
});

test('should not call onWillRemove when identifier is not cached',
Expand All @@ -226,7 +226,7 @@ void main() {
var childCache = Cache(stubCachingStrategy);
await childCache.remove(cachedId);

verifyNever(stubCachingStrategy.onWillRemove(cachedId));
verifyNever(() => stubCachingStrategy.onWillRemove(cachedId));
});

test('should remove after pending get if called synchronously', () {
Expand Down Expand Up @@ -292,7 +292,7 @@ void main() {
await childCache.get(cachedId, () => cachedValue);
await childCache.release(cachedId);

verify(stubCachingStrategy.onDidRelease(
verify(() => stubCachingStrategy.onDidRelease(
cachedId, cachedValue, childCache.remove));
});

Expand All @@ -302,15 +302,15 @@ void main() {
await childCache.get(cachedId, () => cachedValue);
await childCache.release(cachedId);

verify(stubCachingStrategy.onWillRelease(cachedId));
verify(() => stubCachingStrategy.onWillRelease(cachedId));
});

test('should not call onDidRelease when identifier is not cached',
() async {
var stubCachingStrategy = MockCachingStrategy();
var childCache = Cache(stubCachingStrategy);
await childCache.release(cachedId);
verifyNever(stubCachingStrategy.onDidRelease(
verifyNever(() => stubCachingStrategy.onDidRelease(
cachedId, cachedValue, childCache.remove));
});

Expand All @@ -319,7 +319,7 @@ void main() {
var stubCachingStrategy = MockCachingStrategy();
var childCache = Cache(stubCachingStrategy);
await childCache.release(cachedId);
verifyNever(stubCachingStrategy.onWillRelease(cachedId));
verifyNever(() => stubCachingStrategy.onWillRelease(cachedId));
});

test('should complete if pending get factory completes with an error',
Expand Down
2 changes: 1 addition & 1 deletion w_common/test/unit/browser/cache/cache_test.mg.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;

import 'package:mockito/mockito.dart' as _i1;
import 'package:mocktail/mocktail.dart' as _i1;
import 'package:w_common/src/common/cache/cache.dart' as _i2;

// ignore_for_file: type=lint
Expand Down
10 changes: 5 additions & 5 deletions w_common/test/unit/browser/disposable_browser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import 'dart:html';
import 'dart:js' as js;

import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import 'package:w_common/src/browser/disposable_browser.dart';
import 'package:w_common/src/common/disposable.dart' show LeakFlag;
Expand Down Expand Up @@ -48,9 +48,9 @@ void main() {

disposable.subscribeToDocumentEvent(eventName, callback,
documentObject: document, useCapture: useCapture);
verify(document.addEventListener(eventName, callback, useCapture));
verify(() => document.addEventListener(eventName, callback, useCapture));
await disposable.dispose();
verify(document.removeEventListener(eventName, callback, useCapture));
verify(() => document.removeEventListener(eventName, callback, useCapture));
});

test(
Expand All @@ -60,9 +60,9 @@ void main() {

disposable.subscribeToWindowEvent(eventName, callback,
windowObject: window, useCapture: useCapture);
verify(window.addEventListener(eventName, callback, useCapture));
verify(() => window.addEventListener(eventName, callback, useCapture));
await disposable.dispose();
verify(window.removeEventListener(eventName, callback, useCapture));
verify(() => window.removeEventListener(eventName, callback, useCapture));
});
});

Expand Down
5 changes: 0 additions & 5 deletions w_common_tools/build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
targets:
$default:
builders:
# mockito's builder is expensive and is not needed until this package is
# migrated to null-safety. At that point, it should be scoped only to
# relevant files.
mockito:mockBuilder:
enabled: false

0 comments on commit b644005

Please sign in to comment.