| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:analysis_server/protocol/protocol.dart'; | 8 import 'package:analysis_server/protocol/protocol.dart'; |
| 9 import 'package:analysis_server/protocol/protocol_generated.dart'; | 9 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/channel/channel.dart'; | 11 import 'package:analysis_server/src/channel/channel.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart' as resource; | 13 import 'package:analyzer/file_system/file_system.dart' as resource; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 14 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
| 15 import 'package:analyzer/source/package_map_provider.dart'; | 15 import 'package:analyzer/source/package_map_provider.dart'; |
| 16 import 'package:analyzer/source/pub_package_map_provider.dart'; | 16 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:mockito/mockito.dart'; |
| 19 import 'package:test/test.dart'; | 20 import 'package:test/test.dart'; |
| 20 import 'package:typed_mock/typed_mock.dart'; | |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Answer the absolute path the SDK relative to the currently running | 23 * Answer the absolute path the SDK relative to the currently running |
| 24 * script or throw an exception if it cannot be found. | 24 * script or throw an exception if it cannot be found. |
| 25 */ | 25 */ |
| 26 String get sdkPath { | 26 String get sdkPath { |
| 27 Uri sdkUri = Platform.script.resolve('../../../sdk/'); | 27 Uri sdkUri = Platform.script.resolve('../../../sdk/'); |
| 28 | 28 |
| 29 // Verify the directory exists | 29 // Verify the directory exists |
| 30 Directory sdkDir = new Directory.fromUri(sdkUri); | 30 Directory sdkDir = new Directory.fromUri(sdkUri); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 61 // invoking this method. | 61 // invoking this method. |
| 62 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 62 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 typedef void MockServerOperationPerformFunction(AnalysisServer server); | 65 typedef void MockServerOperationPerformFunction(AnalysisServer server); |
| 66 | 66 |
| 67 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { | 67 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { |
| 68 MockAnalysisContext(String name) : super(name); | 68 MockAnalysisContext(String name) : super(name); |
| 69 } | 69 } |
| 70 | 70 |
| 71 class MockClassElement extends TypedMock implements ClassElement { | 71 class MockClassElement extends Mock implements ClassElement { |
| 72 final ElementKind kind = ElementKind.CLASS; | 72 final ElementKind kind = ElementKind.CLASS; |
| 73 } | 73 } |
| 74 | 74 |
| 75 class MockCompilationUnitElement extends TypedMock | 75 class MockCompilationUnitElement extends Mock |
| 76 implements CompilationUnitElement { | 76 implements CompilationUnitElement { |
| 77 final ElementKind kind = ElementKind.COMPILATION_UNIT; | 77 final ElementKind kind = ElementKind.COMPILATION_UNIT; |
| 78 } | 78 } |
| 79 | 79 |
| 80 class MockConstructorElement extends TypedMock implements ConstructorElement { | 80 class MockConstructorElement extends Mock implements ConstructorElement { |
| 81 final kind = ElementKind.CONSTRUCTOR; | 81 final kind = ElementKind.CONSTRUCTOR; |
| 82 } | 82 } |
| 83 | 83 |
| 84 class MockElement extends StringTypedMock implements Element { | 84 class MockElement extends StringTypedMock implements Element { |
| 85 MockElement([String name = '<element>']) : super(name); | 85 MockElement([String name = '<element>']) : super(name); |
| 86 | 86 |
| 87 @override | 87 @override |
| 88 String get displayName => _toString; | 88 String get displayName => _toString; |
| 89 | 89 |
| 90 @override | 90 @override |
| 91 String get name => _toString; | 91 String get name => _toString; |
| 92 } | 92 } |
| 93 | 93 |
| 94 class MockFieldElement extends TypedMock implements FieldElement { | 94 class MockFieldElement extends Mock implements FieldElement { |
| 95 final ElementKind kind = ElementKind.FIELD; | 95 final ElementKind kind = ElementKind.FIELD; |
| 96 } | 96 } |
| 97 | 97 |
| 98 class MockFunctionElement extends TypedMock implements FunctionElement { | 98 class MockFunctionElement extends Mock implements FunctionElement { |
| 99 final ElementKind kind = ElementKind.FUNCTION; | 99 final ElementKind kind = ElementKind.FUNCTION; |
| 100 } | 100 } |
| 101 | 101 |
| 102 class MockFunctionTypeAliasElement extends TypedMock | 102 class MockFunctionTypeAliasElement extends Mock |
| 103 implements FunctionTypeAliasElement { | 103 implements FunctionTypeAliasElement { |
| 104 final ElementKind kind = ElementKind.FUNCTION_TYPE_ALIAS; | 104 final ElementKind kind = ElementKind.FUNCTION_TYPE_ALIAS; |
| 105 } | 105 } |
| 106 | 106 |
| 107 class MockImportElement extends TypedMock implements ImportElement { | 107 class MockImportElement extends Mock implements ImportElement { |
| 108 final ElementKind kind = ElementKind.IMPORT; | 108 final ElementKind kind = ElementKind.IMPORT; |
| 109 } | 109 } |
| 110 | 110 |
| 111 class MockLibraryElement extends TypedMock implements LibraryElement { | 111 class MockLibraryElement extends Mock implements LibraryElement { |
| 112 final ElementKind kind = ElementKind.LIBRARY; | 112 final ElementKind kind = ElementKind.LIBRARY; |
| 113 } | 113 } |
| 114 | 114 |
| 115 class MockLocalVariableElement extends TypedMock | 115 class MockLocalVariableElement extends Mock implements LocalVariableElement { |
| 116 implements LocalVariableElement { | |
| 117 final ElementKind kind = ElementKind.LOCAL_VARIABLE; | 116 final ElementKind kind = ElementKind.LOCAL_VARIABLE; |
| 118 } | 117 } |
| 119 | 118 |
| 120 class MockLogger extends TypedMock implements Logger {} | 119 class MockLogger extends Mock implements Logger {} |
| 121 | 120 |
| 122 class MockMethodElement extends StringTypedMock implements MethodElement { | 121 class MockMethodElement extends StringTypedMock implements MethodElement { |
| 123 final kind = ElementKind.METHOD; | 122 final kind = ElementKind.METHOD; |
| 124 MockMethodElement([String name = 'method']) : super(name); | 123 MockMethodElement([String name = 'method']) : super(name); |
| 125 } | 124 } |
| 126 | 125 |
| 127 /** | 126 /** |
| 128 * A mock [PackageMapProvider]. | 127 * A mock [PackageMapProvider]. |
| 129 */ | 128 */ |
| 130 class MockPackageMapProvider implements PubPackageMapProvider { | 129 class MockPackageMapProvider implements PubPackageMapProvider { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 } | 156 } |
| 158 return new PackageMapInfo(packageMap, dependencies); | 157 return new PackageMapInfo(packageMap, dependencies); |
| 159 } | 158 } |
| 160 | 159 |
| 161 noSuchMethod(Invocation invocation) { | 160 noSuchMethod(Invocation invocation) { |
| 162 // No other methods should be called. | 161 // No other methods should be called. |
| 163 return super.noSuchMethod(invocation); | 162 return super.noSuchMethod(invocation); |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 | 165 |
| 167 class MockParameterElement extends TypedMock implements ParameterElement { | 166 class MockParameterElement extends Mock implements ParameterElement { |
| 168 final ElementKind kind = ElementKind.PARAMETER; | 167 final ElementKind kind = ElementKind.PARAMETER; |
| 169 } | 168 } |
| 170 | 169 |
| 171 class MockPropertyAccessorElement extends TypedMock | 170 class MockPropertyAccessorElement extends Mock |
| 172 implements PropertyAccessorElement { | 171 implements PropertyAccessorElement { |
| 173 final ElementKind kind; | 172 final ElementKind kind; |
| 174 MockPropertyAccessorElement(this.kind); | 173 MockPropertyAccessorElement(this.kind); |
| 175 } | 174 } |
| 176 | 175 |
| 177 /** | 176 /** |
| 178 * A mock [ServerCommunicationChannel] for testing [AnalysisServer]. | 177 * A mock [ServerCommunicationChannel] for testing [AnalysisServer]. |
| 179 */ | 178 */ |
| 180 class MockServerChannel implements ServerCommunicationChannel { | 179 class MockServerChannel implements ServerCommunicationChannel { |
| 181 StreamController<Request> requestController = new StreamController<Request>(); | 180 StreamController<Request> requestController = new StreamController<Request>(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 285 |
| 287 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 286 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 288 | 287 |
| 289 Stream<T> where(bool test(dynamic t)) => stream.where((T data) => test(data)); | 288 Stream<T> where(bool test(dynamic t)) => stream.where((T data) => test(data)); |
| 290 } | 289 } |
| 291 | 290 |
| 292 class MockSource extends StringTypedMock implements Source { | 291 class MockSource extends StringTypedMock implements Source { |
| 293 MockSource([String name = 'mocked.dart']) : super(name); | 292 MockSource([String name = 'mocked.dart']) : super(name); |
| 294 } | 293 } |
| 295 | 294 |
| 296 class MockTopLevelVariableElement extends TypedMock | 295 class MockTopLevelVariableElement extends Mock |
| 297 implements TopLevelVariableElement { | 296 implements TopLevelVariableElement { |
| 298 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; | 297 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; |
| 299 } | 298 } |
| 300 | 299 |
| 301 class MockTypeParameterElement extends TypedMock | 300 class MockTypeParameterElement extends Mock implements TypeParameterElement { |
| 302 implements TypeParameterElement { | |
| 303 final ElementKind kind = ElementKind.TYPE_PARAMETER; | 301 final ElementKind kind = ElementKind.TYPE_PARAMETER; |
| 304 } | 302 } |
| 305 | 303 |
| 306 class NoResponseException implements Exception { | 304 class NoResponseException implements Exception { |
| 307 /** | 305 /** |
| 308 * The request that was not responded to. | 306 * The request that was not responded to. |
| 309 */ | 307 */ |
| 310 final Request request; | 308 final Request request; |
| 311 | 309 |
| 312 NoResponseException(this.request); | 310 NoResponseException(this.request); |
| 313 | 311 |
| 314 String toString() { | 312 String toString() { |
| 315 return "NoResponseException after request ${request.toJson()}"; | 313 return "NoResponseException after request ${request.toJson()}"; |
| 316 } | 314 } |
| 317 } | 315 } |
| 318 | 316 |
| 319 class StringTypedMock extends TypedMock { | 317 class StringTypedMock extends Mock { |
| 320 String _toString; | 318 String _toString; |
| 321 | 319 |
| 322 StringTypedMock(this._toString); | 320 StringTypedMock(this._toString); |
| 323 | 321 |
| 324 @override | 322 @override |
| 325 String toString() { | 323 String toString() { |
| 326 if (_toString != null) { | 324 if (_toString != null) { |
| 327 return _toString; | 325 return _toString; |
| 328 } | 326 } |
| 329 return super.toString(); | 327 return super.toString(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 406 } |
| 409 return mismatchDescription; | 407 return mismatchDescription; |
| 410 } | 408 } |
| 411 | 409 |
| 412 @override | 410 @override |
| 413 bool matches(item, Map matchState) { | 411 bool matches(item, Map matchState) { |
| 414 Response response = item; | 412 Response response = item; |
| 415 return response != null && response.id == _id && response.error == null; | 413 return response != null && response.id == _id && response.error == null; |
| 416 } | 414 } |
| 417 } | 415 } |
| OLD | NEW |