Skip to content

Commit

Permalink
Null-safety migration
Browse files Browse the repository at this point in the history
Used pull request to migrate because original package author no responding.
  • Loading branch information
elianortega committed Apr 6, 2021
1 parent 2033106 commit e7dce05
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/src/data/network_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import 'package:data_connection_checker/data_connection_checker.dart';

import '../domain/inetwork_manager.dart';

///Implementation of NetworkManager
class NetworkManager implements INetworkManager {
///NetworkManager recive a connection Checker
NetworkManager(this.connectionChecker);

/// Access to connectionChecker properties
final DataConnectionChecker connectionChecker;

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/src/domain/inetwork_manager.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// Interface for Network Manager
abstract class INetworkManager {
/// Future that returns true if there is internet connection
Future<bool> get isConnected;
}
17 changes: 9 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: network_manager
description: Dart package which manages data connection.
version: 1.0.0
version: 2.0.0
# homepage: https://www.example.com

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
data_connection_checker: ^0.3.4
data_connection_checker:
git:
url: git://github.com/uSlashVlad/data_connection_checker.git
equatable: ^2.0.0
meta: ^1.1.8
path: ^1.7.0
meta: ^1.3.0
path: ^1.8.0

dev_dependencies:
mockito: ^5.0.3
test: ^1.14.4
mocktail: ^0.1.1
test: ^1.16.8
very_good_analysis: ^2.0.0
10 changes: 5 additions & 5 deletions test/network_manager_test.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import 'package:network_manager/network_manager.dart';

class MockDataConnectionChecker extends Mock implements DataConnectionChecker {}

void main() {
NetworkManager networkInfo;
MockDataConnectionChecker dataConnectionChecker;
late NetworkManager networkInfo;
late MockDataConnectionChecker dataConnectionChecker;

setUp(() {
dataConnectionChecker = MockDataConnectionChecker();
Expand All @@ -22,14 +22,14 @@ void main() {
final tIsConnected = Future.value(true);

when(
dataConnectionChecker.hasConnection,
() => dataConnectionChecker.hasConnection,
).thenAnswer((_) => tIsConnected);

// side effects -> collect the result to test
final result = networkInfo.isConnected;

// expectations -> compare result to expected value
verify(dataConnectionChecker.hasConnection);
verify(() => dataConnectionChecker.hasConnection);
expect(result, tIsConnected);
},
);
Expand Down

0 comments on commit e7dce05

Please sign in to comment.