diff --git a/CHANGELOG.md b/CHANGELOG.md index 1177080..64e9527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0 +* Feature equivalent of v0.0.9 +* Enabled null-safety + ## 0.0.9 * Fix sendSms Future never completes. diff --git a/lib/constants.dart b/lib/constants.dart index 3d4894f..4425895 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -171,10 +171,10 @@ enum SmsStatus { STATUS_COMPLETE, STATUS_FAILED, STATUS_NONE, STATUS_PENDING } enum DataState { DISCONNECTED, CONNECTING, CONNECTED, SUSPENDED, UNKNOWN } /// Represents state of cellular calls. -enum CallState { IDLE, RINGING, OFFHOOK } +enum CallState { IDLE, RINGING, OFFHOOK, UNKNOWN } /// Represents state of cellular network data activity. -enum DataActivity { NONE, IN, OUT, INOUT, DORMANT } +enum DataActivity { NONE, IN, OUT, INOUT, DORMANT, UNKNOWN } /// Represents types of networks for a device. enum NetworkType { @@ -202,7 +202,7 @@ enum NetworkType { } /// Represents types of cellular technology supported by a device. -enum PhoneType { NONE, GSM, CDMA, SIP } +enum PhoneType { NONE, GSM, CDMA, SIP, UNKNOWN } /// Represents state of SIM. enum SimState { @@ -221,7 +221,7 @@ enum SimState { } /// Represents state of cellular service. -enum ServiceState { IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF } +enum ServiceState { IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF, UNKNOWN } /// Represents the quality of cellular signal. enum SignalStrength { NONE_OR_UNKNOWN, POOR, MODERATE, GOOD, GREAT } @@ -234,11 +234,9 @@ extension Value on Sort { switch (this) { case Sort.ASC: return "ASC"; - break; case Sort.DESC: default: return "DESC"; - break; } } } diff --git a/lib/filter.dart b/lib/filter.dart index 47445a6..5a1a96f 100644 --- a/lib/filter.dart +++ b/lib/filter.dart @@ -90,8 +90,8 @@ class ConversationFilter abstract class FilterStatement { String _column; - String _previousFilter; - List _previousFilterArgs; + String _previousFilter = ""; + List _previousFilterArgs = []; FilterStatement._(this._column); @@ -167,12 +167,8 @@ class SmsFilterStatement @override SmsFilter _createFilter(String value, String operator) { - if (_previousFilter != null) { - return SmsFilter._("$_previousFilter $_column $operator ?", - _previousFilterArgs..add(value)); - } else { - return SmsFilter._("$_column $operator ?", [value]); - } + return SmsFilter._("$_previousFilter $_column $operator ?", + _previousFilterArgs..add(value)); } } @@ -186,12 +182,8 @@ class ConversationFilterStatement @override ConversationFilter _createFilter(String value, String operator) { - if (_previousFilter != null) { - return ConversationFilter._("$_previousFilter $_column $operator ?", - _previousFilterArgs..add(value)); - } else { - return ConversationFilter._("$_column $operator ?", [value]); - } + return ConversationFilter._("$_previousFilter $_column $operator ?", + _previousFilterArgs..add(value)); } } @@ -200,10 +192,8 @@ class OrderBy { Sort _sort = Sort.DESC; /// Orders the query results by the provided column and [sort] value. - OrderBy(this._column, {Sort sort}) { - if (sort != null) { - _sort = sort; - } + OrderBy(this._column, {Sort sort = Sort.DESC}) { + _sort = sort; } String get _value => "${_column._name} ${_sort.value}"; diff --git a/lib/telephony.dart b/lib/telephony.dart index fd65b66..fe88396 100644 --- a/lib/telephony.dart +++ b/lib/telephony.dart @@ -22,7 +22,7 @@ void _flutterSmsSetupBackgroundChannel( final CallbackHandle handle = CallbackHandle.fromRawHandle(call.arguments['handle']); final Function handlerFunction = - PluginUtilities.getCallbackFromHandle(handle); + PluginUtilities.getCallbackFromHandle(handle)!; try { await handlerFunction(SmsMessage.fromMap( call.arguments['message'], INCOMING_SMS_COLUMNS)); @@ -52,9 +52,9 @@ class Telephony { final MethodChannel _foregroundChannel; final Platform _platform; - MessageHandler _onNewMessage; - MessageHandler _onBackgroundMessages; - SmsSendStatusListener _statusListener; + late MessageHandler _onNewMessage; + late MessageHandler _onBackgroundMessages; + late SmsSendStatusListener _statusListener; /// /// Gets a singleton instance of the [Telephony] class. @@ -90,8 +90,8 @@ class Telephony { /// /// void listenIncomingSms( - {@required MessageHandler onNewMessage, - MessageHandler onBackgroundMessage, + {required MessageHandler onNewMessage, + MessageHandler? onBackgroundMessage, bool listenInBackground = true}) { assert(_platform.isAndroid == true, "Can only be called on Android."); assert( @@ -107,8 +107,8 @@ class Telephony { if (listenInBackground && onBackgroundMessage != null) { _onBackgroundMessages = onBackgroundMessage; final CallbackHandle backgroundSetupHandle = - PluginUtilities.getCallbackHandle(_flutterSmsSetupBackgroundChannel); - final CallbackHandle backgroundMessageHandle = + PluginUtilities.getCallbackHandle(_flutterSmsSetupBackgroundChannel)!; + final CallbackHandle? backgroundMessageHandle = PluginUtilities.getCallbackHandle(_onBackgroundMessages); if (backgroundMessageHandle == null) { @@ -138,13 +138,10 @@ class Telephony { case ON_MESSAGE: final message = call.arguments["message"]; return _onNewMessage(SmsMessage.fromMap(message, INCOMING_SMS_COLUMNS)); - break; case SMS_SENT: return _statusListener(SendStatus.SENT); - break; case SMS_DELIVERED: return _statusListener(SendStatus.DELIVERED); - break; } } @@ -164,13 +161,13 @@ class Telephony { /// [Future>] Future> getInboxSms( {List columns = DEFAULT_SMS_COLUMNS, - SmsFilter filter, - List sortOrder}) async { + SmsFilter? filter, + List? sortOrder}) async { assert(_platform.isAndroid == true, "Can only be called on Android."); final args = _getArguments(columns, filter, sortOrder); final List messages = - await _foregroundChannel.invokeMethod(GET_ALL_INBOX_SMS, args); + await (_foregroundChannel.invokeMethod(GET_ALL_INBOX_SMS, args) as FutureOr>); return messages .map((message) => SmsMessage.fromMap(message, columns)) @@ -193,13 +190,13 @@ class Telephony { /// [Future>] Future> getSentSms( {List columns = DEFAULT_SMS_COLUMNS, - SmsFilter filter, - List sortOrder}) async { + SmsFilter? filter, + List? sortOrder}) async { assert(_platform.isAndroid == true, "Can only be called on Android."); final args = _getArguments(columns, filter, sortOrder); final List messages = - await _foregroundChannel.invokeMethod(GET_ALL_SENT_SMS, args); + await (_foregroundChannel.invokeMethod(GET_ALL_SENT_SMS, args) as FutureOr>); return messages .map((message) => SmsMessage.fromMap(message, columns)) @@ -222,13 +219,13 @@ class Telephony { /// [Future>] Future> getDraftSms( {List columns = DEFAULT_SMS_COLUMNS, - SmsFilter filter, - List sortOrder}) async { + SmsFilter? filter, + List? sortOrder}) async { assert(_platform.isAndroid == true, "Can only be called on Android."); final args = _getArguments(columns, filter, sortOrder); final List messages = - await _foregroundChannel.invokeMethod(GET_ALL_DRAFT_SMS, args); + await (_foregroundChannel.invokeMethod(GET_ALL_DRAFT_SMS, args) as FutureOr>); return messages .map((message) => SmsMessage.fromMap(message, columns)) @@ -249,12 +246,12 @@ class Telephony { /// /// [Future>] Future> getConversations( - {ConversationFilter filter, List sortOrder}) async { + {ConversationFilter? filter, List? sortOrder}) async { assert(_platform.isAndroid == true, "Can only be called on Android."); final args = _getArguments(DEFAULT_CONVERSATION_COLUMNS, filter, sortOrder); final List conversations = - await _foregroundChannel.invokeMethod(GET_ALL_CONVERSATIONS, args); + await (_foregroundChannel.invokeMethod(GET_ALL_CONVERSATIONS, args) as FutureOr>); return conversations .map((conversation) => SmsConversation.fromMap(conversation)) @@ -262,12 +259,10 @@ class Telephony { } Map _getArguments( - List<_TelephonyColumn> columns, Filter filter, List sortOrder) { + List<_TelephonyColumn> columns, Filter? filter, List? sortOrder) { final Map args = {}; - if (columns != null) { - args["projection"] = columns.map((c) => c._name).toList(); - } + args["projection"] = columns.map((c) => c._name).toList(); if (filter != null) { args["selection"] = filter.selection; @@ -295,9 +290,9 @@ class Telephony { /// - [isMultipart] (optional) : If message body is longer than standard SMS limit of 160 characters, set this flag to /// send the SMS in multiple parts. Future sendSms({ - @required String to, - @required String message, - SmsSendStatusListener statusListener, + required String to, + required String message, + SmsSendStatusListener? statusListener, bool isMultipart = false, }) async { assert(_platform.isAndroid == true, "Can only be called on Android."); @@ -326,8 +321,8 @@ class Telephony { /// - [message] : Message to be sent. /// Future sendSmsByDefaultApp({ - @required String to, - @required String message, + required String to, + required String message, }) async { final Map args = { "address": to, @@ -341,7 +336,7 @@ class Telephony { /// /// Uses TelephonyManager class on Android. /// - Future get isSmsCapable => + Future get isSmsCapable => _foregroundChannel.invokeMethod(IS_SMS_CAPABLE); /// @@ -351,9 +346,9 @@ class Telephony { /// /// [Future] Future get cellularDataState async { - final int dataState = + final int? dataState = await _foregroundChannel.invokeMethod(GET_CELLULAR_DATA_STATE); - if (dataState == -1) { + if ( dataState == null || dataState == -1) { return DataState.UNKNOWN; } else { return DataState.values[dataState]; @@ -367,9 +362,13 @@ class Telephony { /// /// [Future] Future get callState async { - final int state = + final int? state = await _foregroundChannel.invokeMethod(GET_CALL_STATE); - return CallState.values[state]; + if (state != null) { + return CallState.values[state]; + } else { + return CallState.UNKNOWN; + } } /// @@ -379,9 +378,13 @@ class Telephony { /// /// [Future] Future get dataActivity async { - final int activity = + final int? activity = await _foregroundChannel.invokeMethod(GET_DATA_ACTIVITY); - return DataActivity.values[activity]; + if (activity != null) { + return DataActivity.values[activity]; + } else { + return DataActivity.UNKNOWN; + } } /// @@ -391,7 +394,7 @@ class Telephony { /// /// Result may be unreliable on CDMA networks (use phoneType to determine if on a CDMA network). /// - Future get networkOperator => + Future get networkOperator => _foregroundChannel.invokeMethod(GET_NETWORK_OPERATOR); /// @@ -401,7 +404,7 @@ class Telephony { /// /// Result may be unreliable on CDMA networks (use phoneType to determine if on a CDMA network). /// - Future get networkOperatorName => + Future get networkOperatorName => _foregroundChannel.invokeMethod(GET_NETWORK_OPERATOR_NAME); /// @@ -410,31 +413,39 @@ class Telephony { /// ### Requires READ_PHONE_STATE permission. /// Future get dataNetworkType async { - final int type = + final int? type = await _foregroundChannel.invokeMethod(GET_DATA_NETWORK_TYPE); - return NetworkType.values[type]; + if (type != null) { + return NetworkType.values[type]; + } else { + return NetworkType.UNKNOWN; + } } /// /// Returns a constant indicating the device phone type. This indicates the type of radio used to transmit voice calls. /// Future get phoneType async { - final int type = await _foregroundChannel.invokeMethod(GET_PHONE_TYPE); - return PhoneType.values[type]; + final int? type = await _foregroundChannel.invokeMethod(GET_PHONE_TYPE); + if (type != null) { + return PhoneType.values[type]; + } else { + return PhoneType.UNKNOWN; + } } /// /// Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. 5 or 6 decimal digits. /// /// Availability: SimState must be SIM\_STATE\_READY - Future get simOperator => + Future get simOperator => _foregroundChannel.invokeMethod(GET_SIM_OPERATOR); /// /// Returns the Service Provider Name (SPN). /// /// Availability: SimState must be SIM_STATE_READY - Future get simOperatorName => + Future get simOperatorName => _foregroundChannel.invokeMethod(GET_SIM_OPERATOR_NAME); /// @@ -444,15 +455,18 @@ class Telephony { /// /// [Future] Future get simState async { - final int state = await _foregroundChannel.invokeMethod(GET_SIM_STATE); - return SimState.values[state]; + final int? state = await _foregroundChannel.invokeMethod(GET_SIM_STATE); + if (state != null) { + return SimState.values[state]; + } else { + return SimState.UNKNOWN; + } } - /// /// Returns true if the device is considered roaming on the current network, for GSM purposes. /// /// Availability: Only when user registered to a network. - Future get isNetworkRoaming => + Future get isNetworkRoaming => _foregroundChannel.invokeMethod(IS_NETWORK_ROAMING); /// @@ -464,9 +478,9 @@ class Telephony { /// /// [Future>] Future> get signalStrengths async { - final List strengths = + final List? strengths = await _foregroundChannel.invokeMethod(GET_SIGNAL_STRENGTH); - return strengths + return (strengths ?? []) .map((s) => SignalStrength.values[s]) .toList(growable: false); } @@ -481,35 +495,39 @@ class Telephony { /// /// [Future] Future get serviceState async { - final int state = + final int? state = await _foregroundChannel.invokeMethod(GET_SERVICE_STATE); - return ServiceState.values[state]; + if (state != null) { + return ServiceState.values[state]; + } else { + return ServiceState.UNKNOWN; + } } /// /// Request the user for all the sms permissions listed in the app's AndroidManifest.xml /// - Future get requestSmsPermissions => + Future get requestSmsPermissions => _foregroundChannel.invokeMethod(REQUEST_SMS_PERMISSION); /// /// Request the user for all the phone permissions listed in the app's AndroidManifest.xml /// - Future get requestPhonePermissions => + Future get requestPhonePermissions => _foregroundChannel.invokeMethod(REQUEST_PHONE_PERMISSION); /// /// Request the user for all the phone and sms permissions listed in the app's AndroidManifest.xml /// - Future get requestPhoneAndSmsPermissions => + Future get requestPhoneAndSmsPermissions => _foregroundChannel.invokeMethod(REQUEST_PHONE_AND_SMS_PERMISSION); /// /// Opens the default dialer with the given phone number. /// Future openDialer(String phoneNumber) async { - assert(phoneNumber != null && phoneNumber.isNotEmpty, - "phoneNumber cannot be null or empty"); + assert(phoneNumber.isNotEmpty, + "phoneNumber cannot be empty"); final Map args = {"phoneNumber": phoneNumber}; await _foregroundChannel.invokeMethod(OPEN_DIALER, args); } @@ -520,7 +538,7 @@ class Telephony { /// ### Requires permission CALL_PHONE /// Future dialPhoneNumber(String phoneNumber) async { - assert(phoneNumber != null && phoneNumber.isNotEmpty, + assert(phoneNumber.isNotEmpty, "phoneNumber cannot be null or empty"); final Map args = {"phoneNumber": phoneNumber}; await _foregroundChannel.invokeMethod(DIAL_PHONE_NUMBER, args); @@ -531,18 +549,18 @@ class Telephony { /// Represents a message returned by one of the query functions such as /// [getInboxSms], [getSentSms], [getDraftSms] class SmsMessage { - int id; - String address; - String body; - int date; - int dateSent; - bool read; - bool seen; - String subject; - int subscriptionId; - int threadId; - SmsType type; - SmsStatus status; + int? id; + String? address; + String? body; + int? date; + int? dateSent; + bool? read; + bool? seen; + String? subject; + int? subscriptionId; + int? threadId; + SmsType? type; + SmsStatus? status; /// ## Do not call this method. This method is visible only for testing. @visibleForTesting @@ -630,9 +648,9 @@ class SmsMessage { /// Represents a conversation returned by the query conversation functions /// [getConversations] class SmsConversation { - String snippet; - int threadId; - int messageCount; + String? snippet; + int? threadId; + int? messageCount; /// ## Do not call this method. This method is visible only for testing. @visibleForTesting @@ -640,16 +658,16 @@ class SmsConversation { final conversation = Map.castFrom(rawConversation); for (var column in DEFAULT_CONVERSATION_COLUMNS) { - final String value = conversation[column._columnName]; + final String? value = conversation[column._columnName]; switch (column._columnName) { case _ConversationProjections.SNIPPET: this.snippet = value; break; case _ConversationProjections.THREAD_ID: - this.threadId = int.tryParse(value); + this.threadId = int.tryParse(value!); break; case _ConversationProjections.MSG_COUNT: - this.messageCount = int.tryParse(value); + this.messageCount = int.tryParse(value!); break; } } diff --git a/pubspec.yaml b/pubspec.yaml index 8a4cac6..9c02486 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,26 +1,27 @@ name: telephony -description: A Flutter plugin to use telephony features such as fetch network info, start phone calls, send and receive SMS, and listen for incoming SMS. -version: 0.0.9 +description: A Flutter plugin to use telephony features such as fetch network + info, start phone calls, send and receive SMS, and listen for incoming SMS. +version: 0.1.0 homepage: https://github.com/shounakmulay/Telephony repository: https://github.com/shounakmulay/Telephony environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.10.0" dependencies: - platform: ^2.2.1 flutter: sdk: flutter + platform: ^3.0.0 dev_dependencies: flutter_test: sdk: flutter - mockito: ^4.1.3 - collection: ^1.14.13 + build_runner: ^1.11.5 + collection: ^1.15.0 + mockito: ^5.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec - # The following section is specific to Flutter. flutter: # This section identifies this Flutter project as a plugin project. @@ -34,7 +35,6 @@ flutter: pluginClass: TelephonyPlugin ios: pluginClass: TelephonyPlugin - # To add assets to your plugin package, add an assets section, like this: # assets: # - images/a_dot_burr.jpeg @@ -45,7 +45,6 @@ flutter: # # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware. - # To add custom fonts to your plugin package, add a fonts section here, # in this "flutter" section. Each entry in this list should have a # "family" key with the font family name, and a "fonts" key with a diff --git a/test/listener_test.dart b/test/listener_test.dart index e3d1ba8..0298d60 100644 --- a/test/listener_test.dart +++ b/test/listener_test.dart @@ -7,8 +7,8 @@ import 'mocks/messages.dart'; main() { TestWidgetsFlutterBinding.ensureInitialized(); - MethodChannel methodChannel; - Telephony telephony; + late MethodChannel methodChannel; + late Telephony telephony; final List log = []; SmsSendStatusListener listener; diff --git a/test/telephony_test.dart b/test/telephony_test.dart index 931c74d..58766e7 100644 --- a/test/telephony_test.dart +++ b/test/telephony_test.dart @@ -1,17 +1,20 @@ import "package:flutter/services.dart"; import "package:flutter_test/flutter_test.dart"; +import 'package:mockito/annotations.dart'; import "package:mockito/mockito.dart"; import "package:platform/platform.dart"; import "package:telephony/telephony.dart"; import 'package:collection/collection.dart'; import 'mocks/messages.dart'; +import 'telephony_test.mocks.dart'; +@GenerateMocks([MethodChannel]) main() { TestWidgetsFlutterBinding.ensureInitialized(); - MockMethodChannel methodChannel; - Telephony telephony; + MockMethodChannel methodChannel = MockMethodChannel(); + late Telephony telephony; setUp(() { methodChannel = MockMethodChannel(); @@ -171,23 +174,31 @@ main() { group("should send", () { test("sms", () async { - telephony.sendSms(to: "0000000000", message: "Test message"); + final String address = "0000000000"; + final String body = "Test message"; + when(methodChannel.invokeMethod(SEND_SMS, { + "address": address, + "message_body": body, + "listen_status": false + })).thenAnswer((realInvocation) => Future.value()); + telephony.sendSms(to: address, message: body); verify(methodChannel.invokeMethod(SEND_SMS, { - "address": "0000000000", - "message_body": "Test message", + "address": address, + "message_body": body, "listen_status": false })).called(1); }); test("multipart message", () async { - telephony.sendSms( - to: "123456", message: "some long message", isMultipart: true); - final args = { "address": "123456", "message_body": "some long message", "listen_status": false }; + when(methodChannel.invokeMethod(SEND_MULTIPART_SMS, args)) + .thenAnswer((realInvocation) => Future.value()); + telephony.sendSms( + to: "123456", message: "some long message", isMultipart: true); verifyNever(methodChannel.invokeMethod(SEND_SMS, args)); @@ -195,10 +206,16 @@ main() { }); test("sms by default app", () async { - telephony.sendSmsByDefaultApp(to: "123456", message: "message"); + final String address = "123456"; + final String body = "message"; + when(methodChannel.invokeMethod(SEND_SMS_INTENT, { + "address": address, + "message_body": body + })).thenAnswer((realInvocation) => Future.value()); + telephony.sendSmsByDefaultApp(to: address, message: body); verify(methodChannel.invokeMethod(SEND_SMS_INTENT, - {"address": "123456", "message_body": "message"})).called(1); + {"address": address, "message_body": body})).called(1); }); }); @@ -227,7 +244,7 @@ main() { test("inbox with filters", () async { final columns = [SmsColumn.ID, SmsColumn.ADDRESS]; - final filter = SmsFilter.where(SmsColumn.ID) + final SmsFilter filter = SmsFilter.where(SmsColumn.ID) .equals("3") .and(SmsColumn.ADDRESS) .like("mess"); @@ -235,7 +252,7 @@ main() { final args = { "projection": ["_id", "address"], - "selection": "_id = ? AND address LIKE ?", + "selection": " _id = ? AND address LIKE ?", "selection_args": ["3", "mess"], "sort_order": "_id ASC" }; @@ -277,7 +294,7 @@ main() { test("sent with filters", () async { final columns = [SmsColumn.ID, SmsColumn.ADDRESS]; - final filter = SmsFilter.where(SmsColumn.ID) + final SmsFilter filter = SmsFilter.where(SmsColumn.ID) .equals("4") .and(SmsColumn.DATE) .greaterThan("12"); @@ -285,7 +302,7 @@ main() { final args = { "projection": ["_id", "address"], - "selection": "_id = ? AND date > ?", + "selection": " _id = ? AND date > ?", "selection_args": ["4", "12"], "sort_order": "_id ASC" }; @@ -327,7 +344,7 @@ main() { test("draft with filters", () async { final columns = [SmsColumn.ID, SmsColumn.ADDRESS]; - final filter = SmsFilter.where(SmsColumn.ID) + final SmsFilter filter = SmsFilter.where(SmsColumn.ID) .equals("4") .and(SmsColumn.DATE) .greaterThan("12"); @@ -335,7 +352,7 @@ main() { final args = { "projection": ["_id", "address"], - "selection": "_id = ? AND date > ?", + "selection": " _id = ? AND date > ?", "selection_args": ["4", "12"], "sort_order": "_id ASC" }; @@ -377,17 +394,18 @@ main() { }); test("conversations with filter", () async { - final filter = ConversationFilter.where(ConversationColumn.MSG_COUNT) - .equals("4") - .and(ConversationColumn.THREAD_ID) - .greaterThan("12"); + final ConversationFilter filter = + ConversationFilter.where(ConversationColumn.MSG_COUNT) + .equals("4") + .and(ConversationColumn.THREAD_ID) + .greaterThan("12"); final sortOrder = [ OrderBy(ConversationColumn.THREAD_ID, sort: Sort.ASC) ]; final args = { "projection": ["snippet", "thread_id", "msg_count"], - "selection": "msg_count = ? AND thread_id > ?", + "selection": " msg_count = ? AND thread_id > ?", "selection_args": ["4", "12"], "sort_order": "thread_id ASC" }; @@ -414,7 +432,7 @@ main() { group("should generate", () { test("sms filter statement", () async { - final statement = SmsFilter.where(SmsColumn.ADDRESS) + final SmsFilter statement = SmsFilter.where(SmsColumn.ADDRESS) .greaterThan("1") .and(SmsColumn.ID) .greaterThanOrEqualTo("2") @@ -427,7 +445,7 @@ main() { expect( statement.selection, equals( - "address > ? AND _id >= ? OR date BETWEEN ? OR NOT type LIKE ?")); + " address > ? AND _id >= ? OR date BETWEEN ? OR NOT type LIKE ?")); expect( ListEquality() .equals(statement.selectionArgs, ["1", "2", "3 AND 4", "5"]), @@ -435,16 +453,17 @@ main() { }); test("conversation filter statement", () async { - final statement = ConversationFilter.where(ConversationColumn.THREAD_ID) - .lessThanOrEqualTo("1") - .or(ConversationColumn.MSG_COUNT) - .notEqualTo("6") - .and(ConversationColumn.SNIPPET) - .not - .notEqualTo("7"); + final ConversationFilter statement = + ConversationFilter.where(ConversationColumn.THREAD_ID) + .lessThanOrEqualTo("1") + .or(ConversationColumn.MSG_COUNT) + .notEqualTo("6") + .and(ConversationColumn.SNIPPET) + .not + .notEqualTo("7"); expect(statement.selection, - "thread_id <= ? OR msg_count != ? AND NOT snippet != ?"); + " thread_id <= ? OR msg_count != ? AND NOT snippet != ?"); expect(ListEquality().equals(statement.selectionArgs, ["1", "6", "7"]), isTrue); }); @@ -473,5 +492,3 @@ main() { }); }); } - -class MockMethodChannel extends Mock implements MethodChannel {} diff --git a/test/telephony_test.mocks.dart b/test/telephony_test.mocks.dart new file mode 100644 index 0000000..523efa3 --- /dev/null +++ b/test/telephony_test.mocks.dart @@ -0,0 +1,64 @@ +// Mocks generated by Mockito 5.0.0 from annotations +// in telephony/test/telephony_test.dart. +// Do not manually edit this file. + +import 'dart:async' as _i5; + +import 'package:flutter/src/services/binary_messenger.dart' as _i3; +import 'package:flutter/src/services/message_codec.dart' as _i2; +import 'package:flutter/src/services/platform_channel.dart' as _i4; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: comment_references +// ignore_for_file: unnecessary_parenthesis + +class _FakeMethodCodec extends _i1.Fake implements _i2.MethodCodec {} + +class _FakeBinaryMessenger extends _i1.Fake implements _i3.BinaryMessenger {} + +/// A class which mocks [MethodChannel]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockMethodChannel extends _i1.Mock implements _i4.MethodChannel { + MockMethodChannel() { + _i1.throwOnMissingStub(this); + } + + @override + String get name => + (super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String); + @override + _i2.MethodCodec get codec => (super.noSuchMethod(Invocation.getter(#codec), + returnValue: _FakeMethodCodec()) as _i2.MethodCodec); + @override + _i3.BinaryMessenger get binaryMessenger => + (super.noSuchMethod(Invocation.getter(#binaryMessenger), + returnValue: _FakeBinaryMessenger()) as _i3.BinaryMessenger); + @override + _i5.Future invokeMethod(String? method, [dynamic arguments]) => + (super.noSuchMethod(Invocation.method(#invokeMethod, [method, arguments]), + returnValue: Future.value(null)) as _i5.Future); + @override + _i5.Future?> invokeListMethod(String? method, + [dynamic arguments]) => + (super.noSuchMethod( + Invocation.method(#invokeListMethod, [method, arguments]), + returnValue: Future.value([])) as _i5.Future?>); + @override + _i5.Future?> invokeMapMethod(String? method, + [dynamic arguments]) => + (super.noSuchMethod( + Invocation.method(#invokeMapMethod, [method, arguments]), + returnValue: Future.value({})) as _i5.Future?>); + @override + bool checkMethodCallHandler( + _i5.Future Function(_i2.MethodCall)? handler) => + (super.noSuchMethod(Invocation.method(#checkMethodCallHandler, [handler]), + returnValue: false) as bool); + @override + bool checkMockMethodCallHandler( + _i5.Future Function(_i2.MethodCall)? handler) => + (super.noSuchMethod( + Invocation.method(#checkMockMethodCallHandler, [handler]), + returnValue: false) as bool); +}