|
| 1 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:io'; |
| 6 | + |
| 7 | +import 'package:flutter/services.dart'; |
| 8 | +import 'package:path_provider/path_provider.dart'; |
| 9 | +import 'package:test/test.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + const channel = const MethodChannel('plugins.flutter.io/path_provider'); |
| 13 | + final List<MethodCall> log = <MethodCall>[]; |
| 14 | + String response; |
| 15 | + |
| 16 | + channel.setMockMethodCallHandler((MethodCall methodCall) async { |
| 17 | + log.add(methodCall); |
| 18 | + return response; |
| 19 | + }); |
| 20 | + |
| 21 | + tearDown(() { |
| 22 | + log.clear(); |
| 23 | + }); |
| 24 | + |
| 25 | + test('getTemporaryDirectory test', () async { |
| 26 | + response = null; |
| 27 | + Directory directory = await getTemporaryDirectory(); |
| 28 | + expect(log, equals(<MethodCall>[new MethodCall('getTemporaryDirectory')])); |
| 29 | + expect(directory, isNull); |
| 30 | + }); |
| 31 | + |
| 32 | + test('getApplicationDocumentsDirectory test', () async { |
| 33 | + response = null; |
| 34 | + Directory directory = await getApplicationDocumentsDirectory(); |
| 35 | + expect( |
| 36 | + log, |
| 37 | + equals(<MethodCall>[new MethodCall('getApplicationDocumentsDirectory')]), |
| 38 | + ); |
| 39 | + expect(directory, isNull); |
| 40 | + }); |
| 41 | + |
| 42 | + test('TemporaryDirectory path test', () async { |
| 43 | + final String fakePath = "/foo/bar/baz"; |
| 44 | + response = fakePath; |
| 45 | + Directory directory = await getTemporaryDirectory(); |
| 46 | + expect(directory.path, equals(fakePath)); |
| 47 | + }); |
| 48 | + |
| 49 | + test('ApplicationDocumentsDirectory path test', () async { |
| 50 | + final String fakePath = "/foo/bar/baz"; |
| 51 | + response = fakePath; |
| 52 | + Directory directory = await getApplicationDocumentsDirectory(); |
| 53 | + expect(directory.path, equals(fakePath)); |
| 54 | + }); |
| 55 | +} |
0 commit comments