| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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.operation.analysis; |
| 6 |
| 7 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:typed_mock/typed_mock.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 import '../reflective_tests.dart'; |
| 14 |
| 15 main() { |
| 16 groupSep = ' | '; |
| 17 |
| 18 group('errorToJson', () { |
| 19 runReflectiveTests(Test_errorToJson); |
| 20 }); |
| 21 } |
| 22 |
| 23 |
| 24 @ReflectiveTestCase() |
| 25 class Test_errorToJson { |
| 26 Source source = new SourceMock(); |
| 27 AnalysisError analysisError = new AnalysisErrorMock(); |
| 28 |
| 29 setUp() { |
| 30 // prepare Source |
| 31 when(source.fullName).thenReturn('foo.dart'); |
| 32 // prepare AnalysisError |
| 33 when(analysisError.source).thenReturn(source); |
| 34 when(analysisError.errorCode).thenReturn(CompileTimeErrorCode.AMBIGUOUS_EXPO
RT); |
| 35 when(analysisError.message).thenReturn('my message'); |
| 36 when(analysisError.offset).thenReturn(10); |
| 37 when(analysisError.length).thenReturn(20); |
| 38 } |
| 39 |
| 40 tearDown() { |
| 41 source = null; |
| 42 analysisError = null; |
| 43 } |
| 44 |
| 45 test_noCorrection() { |
| 46 when(analysisError.correction).thenReturn('my correction'); |
| 47 Map<String, Object> json = errorToJson(analysisError); |
| 48 expect(json, { |
| 49 'file': 'foo.dart', |
| 50 'errorCode': 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', |
| 51 'offset': 10, |
| 52 'length': 20, |
| 53 'message': 'my message', |
| 54 'correction': 'my correction'}); |
| 55 } |
| 56 |
| 57 test_withCorrection() { |
| 58 Map<String, Object> json = errorToJson(analysisError); |
| 59 expect(json, { |
| 60 'file': 'foo.dart', |
| 61 'errorCode': 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', |
| 62 'offset': 10, |
| 63 'length': 20, |
| 64 'message': 'my message'}); |
| 65 } |
| 66 } |
| 67 |
| 68 |
| 69 class SourceMock extends TypedMock implements Source { |
| 70 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 71 } |
| 72 |
| 73 |
| 74 class AnalysisErrorMock extends TypedMock implements AnalysisError { |
| 75 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 76 } |
| OLD | NEW |