OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.src.task.general_test; |
| 6 |
| 7 import 'package:analyzer/src/generated/engine.dart' |
| 8 hide AnalysisTask, GetContentTask; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/task/general.dart'; |
| 11 import 'package:analyzer/task/general.dart'; |
| 12 import 'package:analyzer/task/model.dart'; |
| 13 import 'package:typed_mock/typed_mock.dart'; |
| 14 import 'package:unittest/unittest.dart'; |
| 15 |
| 16 import '../../generated/test_support.dart'; |
| 17 import '../../reflective_tests.dart'; |
| 18 import '../../utils.dart'; |
| 19 |
| 20 main() { |
| 21 initializeTestEnvironment(); |
| 22 runReflectiveTests(GetContentTaskTest); |
| 23 } |
| 24 |
| 25 @reflectiveTest |
| 26 class GetContentTaskTest extends EngineTestCase { |
| 27 test_buildInputs() { |
| 28 AnalysisTarget target = new TestSource(); |
| 29 Map<String, TaskInput> inputs = GetContentTask.buildInputs(target); |
| 30 expect(inputs, isEmpty); |
| 31 } |
| 32 |
| 33 test_constructor() { |
| 34 AnalysisContext context = new _MockContext(); |
| 35 AnalysisTarget target = new TestSource(); |
| 36 GetContentTask task = new GetContentTask(context, target); |
| 37 expect(task, isNotNull); |
| 38 expect(task.context, context); |
| 39 expect(task.target, target); |
| 40 } |
| 41 |
| 42 test_createTask() { |
| 43 AnalysisContext context = new _MockContext(); |
| 44 AnalysisTarget target = new TestSource(); |
| 45 GetContentTask task = GetContentTask.createTask(context, target); |
| 46 expect(task, isNotNull); |
| 47 expect(task.context, context); |
| 48 expect(task.target, target); |
| 49 } |
| 50 |
| 51 test_descriptor() { |
| 52 AnalysisContext context = new _MockContext(); |
| 53 AnalysisTarget target = new TestSource(); |
| 54 GetContentTask task = new GetContentTask(context, target); |
| 55 expect(task.descriptor, GetContentTask.DESCRIPTOR); |
| 56 } |
| 57 |
| 58 test_perform() { |
| 59 AnalysisContext context = new _MockContext(); |
| 60 Source target = new TestSource(); |
| 61 GetContentTask task = new GetContentTask(context, target); |
| 62 when(context.getContents(target)) |
| 63 .thenReturn(new TimestampedData<String>(42, 'foo')); |
| 64 task.perform(); |
| 65 expect(task.caughtException, isNull); |
| 66 expect(task.outputs, hasLength(2)); |
| 67 expect(task.outputs[CONTENT], 'foo'); |
| 68 expect(task.outputs[MODIFICATION_TIME], 42); |
| 69 } |
| 70 |
| 71 void test_perform_exception() { |
| 72 AnalysisContext context = new _MockContext(); |
| 73 Source target = new TestSource(); |
| 74 GetContentTask task = new GetContentTask(context, target); |
| 75 when(context.getContents(target)).thenThrow('My exception!'); |
| 76 task.perform(); |
| 77 expect(task.caughtException, isNull); |
| 78 expect(task.outputs, hasLength(2)); |
| 79 expect(task.outputs[CONTENT], ''); |
| 80 expect(task.outputs[MODIFICATION_TIME], -1); |
| 81 } |
| 82 } |
| 83 |
| 84 class _MockContext extends TypedMock implements AnalysisContext { |
| 85 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 86 } |
OLD | NEW |