Skip to content

Instantly share code, notes, and snippets.

@easylive1989
Created September 24, 2023 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easylive1989/4fc59087a431e71107b28d2f1a6b1b32 to your computer and use it in GitHub Desktop.
Save easylive1989/4fc59087a431e71107b28d2f1a6b1b32 to your computer and use it in GitHub Desktop.
2023鐵人賽_D10_1
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'scheduler_4_test.mocks.dart';
@GenerateNiceMocks([MockSpec<WalletRepository>()])
main() {
test("should update wallet", () {
var mockWalletRepository = MockWalletRepository();
UpdateWalletScheduler(mockWalletRepository).execute();
verify(mockWalletRepository.update()).called(1);
});
}
class UpdateWalletScheduler {
final WalletRepository walletRepository;
UpdateWalletScheduler(this.walletRepository);
void start() {
Timer.periodic(
const Duration(seconds: 5),
(timer) => execute(),
);
}
void execute() {
walletRepository.update();
}
}
class WalletRepository {
Future<void> update() async {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment