feat(interface): make api injectable for test

This commit is contained in:
Hugo Pointcheval 2023-02-22 20:13:51 +01:00
parent d8cf8dddc4
commit 8044ccfa43
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
2 changed files with 10 additions and 3 deletions

View File

@ -13,3 +13,5 @@ export 'src/core/exceptions/exception.dart';
export 'src/implementations/basic_message_channel_native_crypto.dart';
export 'src/implementations/method_channel_native_crypto.dart';
export 'src/interface/native_crypto_platform.dart';
export 'src/pigeon/messages.pigeon.dart';
export 'src/pigeon/test_api.dart';

View File

@ -6,13 +6,18 @@
import 'package:flutter/foundation.dart';
import 'package:native_crypto_platform_interface/native_crypto_platform_interface.dart';
import 'package:native_crypto_platform_interface/src/pigeon/messages.pigeon.dart';
/// An implementation of [NativeCryptoPlatform] that uses Pigeon generated code.
class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
/// Creates a new instance of [BasicMessageChannelNativeCrypto].
///
/// The [api] parameter permits to override the default Pigeon API used to
/// interact with the native platform. This is useful for testing.
BasicMessageChannelNativeCrypto({NativeCryptoAPI? api})
: api = api ?? NativeCryptoAPI();
/// The Pigeon API used to interact with the native platform.
@visibleForTesting
NativeCryptoAPI api = NativeCryptoAPI();
final NativeCryptoAPI api;
@override
Future<Uint8List?> hash(Uint8List data, {required String algorithm}) async {