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 library testing.mocks; | 5 library testing.mocks; |
6 | 6 |
7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:typed_mock/typed_mock.dart'; | 10 import 'package:typed_mock/typed_mock.dart'; |
11 | 11 |
12 | 12 |
13 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { | 13 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { |
14 MockAnalysisContext(String name) : super(name); | 14 MockAnalysisContext(String name) : super(name); |
15 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 15 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
16 } | 16 } |
17 | 17 |
18 | 18 |
| 19 class MockClassElement extends TypedMock implements ClassElement { |
| 20 final ElementKind kind = ElementKind.CLASS; |
| 21 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 22 } |
| 23 |
| 24 |
19 class MockCompilationUnitElement extends TypedMock implements | 25 class MockCompilationUnitElement extends TypedMock implements |
20 CompilationUnitElement { | 26 CompilationUnitElement { |
| 27 final ElementKind kind = ElementKind.COMPILATION_UNIT; |
| 28 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 29 } |
| 30 |
| 31 |
| 32 class MockConstructorElement extends TypedMock implements ConstructorElement { |
| 33 final kind = ElementKind.CONSTRUCTOR; |
21 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 34 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
22 } | 35 } |
23 | 36 |
24 | 37 |
25 class MockElement extends StringTypedMock implements Element { | 38 class MockElement extends StringTypedMock implements Element { |
26 MockElement([String name = '<element>']) : super(name); | 39 MockElement([String name = '<element>']) : super(name); |
| 40 |
| 41 @override |
| 42 String get displayName => _toString; |
| 43 |
| 44 @override |
| 45 String get name => _toString; |
| 46 |
| 47 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 48 } |
| 49 |
| 50 |
| 51 class MockFieldElement extends TypedMock implements FieldElement { |
| 52 final ElementKind kind = ElementKind.FIELD; |
| 53 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 54 } |
| 55 |
| 56 |
| 57 class MockFunctionElement extends TypedMock implements FunctionElement { |
| 58 final ElementKind kind = ElementKind.FUNCTION; |
| 59 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 60 } |
| 61 |
| 62 |
| 63 class MockFunctionTypeAliasElement extends TypedMock implements |
| 64 FunctionTypeAliasElement { |
| 65 final ElementKind kind = ElementKind.FUNCTION_TYPE_ALIAS; |
27 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 66 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
28 } | 67 } |
29 | 68 |
30 | 69 |
31 class MockHtmlElement extends TypedMock implements HtmlElement { | 70 class MockHtmlElement extends TypedMock implements HtmlElement { |
| 71 final ElementKind kind = ElementKind.HTML; |
| 72 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 73 } |
| 74 |
| 75 |
| 76 class MockImportElement extends TypedMock implements ImportElement { |
| 77 final ElementKind kind = ElementKind.IMPORT; |
32 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 78 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
33 } | 79 } |
34 | 80 |
35 | 81 |
36 class MockLibraryElement extends TypedMock implements LibraryElement { | 82 class MockLibraryElement extends TypedMock implements LibraryElement { |
| 83 final ElementKind kind = ElementKind.LIBRARY; |
37 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 84 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
38 } | 85 } |
39 | 86 |
| 87 |
| 88 class MockLocalVariableElement extends TypedMock implements LocalVariableElement |
| 89 { |
| 90 final ElementKind kind = ElementKind.LOCAL_VARIABLE; |
| 91 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 92 } |
| 93 |
40 | 94 |
41 class MockLogger extends TypedMock implements Logger { | 95 class MockLogger extends TypedMock implements Logger { |
42 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 96 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
43 } | 97 } |
44 | 98 |
45 | 99 |
| 100 class MockMethodElement extends StringTypedMock implements MethodElement { |
| 101 final kind = ElementKind.METHOD; |
| 102 MockMethodElement([String name = 'method']) : super(name); |
| 103 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 104 } |
| 105 |
| 106 |
| 107 class MockParameterElement extends TypedMock implements ParameterElement { |
| 108 final ElementKind kind = ElementKind.PARAMETER; |
| 109 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 110 } |
| 111 |
| 112 |
| 113 class MockPropertyAccessorElement extends TypedMock implements |
| 114 PropertyAccessorElement { |
| 115 final ElementKind kind; |
| 116 MockPropertyAccessorElement(this.kind); |
| 117 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 118 } |
| 119 |
| 120 |
46 class MockSource extends StringTypedMock implements Source { | 121 class MockSource extends StringTypedMock implements Source { |
47 MockSource([String name = 'mocked.dart']) : super(name); | 122 MockSource([String name = 'mocked.dart']) : super(name); |
48 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 123 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
49 } | 124 } |
50 | 125 |
51 | 126 |
| 127 class MockTopLevelVariableElement extends TypedMock implements |
| 128 TopLevelVariableElement { |
| 129 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; |
| 130 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 131 } |
| 132 |
| 133 |
| 134 class MockTypeParameterElement extends TypedMock implements TypeParameterElement |
| 135 { |
| 136 final ElementKind kind = ElementKind.TYPE_PARAMETER; |
| 137 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 138 } |
| 139 |
| 140 |
52 class StringTypedMock extends TypedMock { | 141 class StringTypedMock extends TypedMock { |
53 String _toString; | 142 String _toString; |
54 | 143 |
55 StringTypedMock(this._toString); | 144 StringTypedMock(this._toString); |
56 | 145 |
57 @override | 146 @override |
58 String toString() { | 147 String toString() { |
59 if (_toString != null) { | 148 if (_toString != null) { |
60 return _toString; | 149 return _toString; |
61 } | 150 } |
62 return super.toString(); | 151 return super.toString(); |
63 } | 152 } |
64 } | 153 } |
OLD | NEW |