Chromium Code Reviews| 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.queue; | |
| 6 | |
| 7 import 'package:analysis_server/src/operation/operation.dart'; | |
| 8 import 'package:analysis_server/src/operation/operation_queue.dart'; | |
| 9 import 'package:typed_mock/typed_mock.dart'; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 | |
| 12 main() { | |
| 13 groupSep = ' | '; | |
| 14 | |
| 15 group('ServerOperationQueue', () { | |
| 16 ServerOperationQueue queue; | |
| 17 | |
| 18 setUp(() { | |
| 19 queue = new ServerOperationQueue(); | |
| 20 }); | |
| 21 | |
| 22 group('add', () { | |
| 23 group('MergeableOperation', () { | |
| 24 test('false', () { | |
| 25 var operationA = mockMergeableOperation(ServerOperationPriority.SEARCH ); | |
| 26 var operationB = mockMergeableOperation(ServerOperationPriority.SEARCH ); | |
| 27 when(operationA.mergeWith(operationB)).thenReturn(false); | |
| 28 queue.add(operationA); | |
| 29 queue.add(operationB); | |
| 30 expect(queue.take(), operationA); | |
| 31 expect(queue.take(), operationB); | |
| 32 expect(queue.take(), null); | |
|
Brian Wilkerson
2014/06/02 14:32:18
Should this (and line 42) be "isNull"?
scheglov
2014/06/02 17:56:59
As I see it now, we actually don't need mergeable
| |
| 33 }); | |
| 34 | |
| 35 test('true', () { | |
| 36 var operationA = mockMergeableOperation(ServerOperationPriority.SEARCH ); | |
| 37 var operationB = mockMergeableOperation(ServerOperationPriority.SEARCH ); | |
| 38 when(operationA.mergeWith(operationB)).thenReturn(true); | |
| 39 queue.add(operationA); | |
| 40 queue.add(operationB); | |
| 41 expect(queue.take(), operationA); | |
| 42 expect(queue.take(), null); | |
| 43 }); | |
| 44 }); | |
| 45 | |
| 46 test('false', () { | |
|
Brian Wilkerson
2014/06/02 14:32:18
This test is duplicated on line 58.
scheglov
2014/06/02 17:56:59
Removed.
| |
| 47 var operation = mockOperation(ServerOperationPriority.SEARCH); | |
| 48 queue.add(operation); | |
| 49 expect(queue.isEmpty, isFalse); | |
| 50 }); | |
| 51 }); | |
| 52 | |
| 53 group('isEmpty', () { | |
| 54 test('true', () { | |
| 55 expect(queue.isEmpty, isTrue); | |
| 56 }); | |
| 57 | |
| 58 test('false', () { | |
| 59 var operation = mockOperation(ServerOperationPriority.SEARCH); | |
| 60 queue.add(operation); | |
| 61 expect(queue.isEmpty, isFalse); | |
| 62 }); | |
| 63 }); | |
| 64 | |
| 65 group('take', () { | |
| 66 test('empty', () { | |
| 67 expect(queue.take(), isNull); | |
| 68 }); | |
| 69 | |
| 70 test('use priorities', () { | |
| 71 var operationA = mockOperation(ServerOperationPriority.SEARCH); | |
| 72 var operationB = mockOperation(ServerOperationPriority.REFACTORING); | |
| 73 var operationC = mockOperation(ServerOperationPriority.ANALYSIS); | |
| 74 queue.add(operationA); | |
| 75 queue.add(operationB); | |
| 76 queue.add(operationC); | |
| 77 expect(queue.take(), operationC); | |
| 78 expect(queue.take(), operationA); | |
| 79 expect(queue.take(), operationB); | |
| 80 expect(queue.take(), isNull); | |
| 81 }); | |
| 82 }); | |
| 83 }); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 /** | |
| 88 * Return a [ServerOperation] mock with the given priority. | |
| 89 */ | |
| 90 ServerOperation mockOperation(ServerOperationPriority priority) { | |
| 91 ServerOperation operation = new ServerOperationMock(); | |
| 92 when(operation.priority).thenReturn(priority); | |
| 93 return operation; | |
| 94 } | |
| 95 | |
| 96 | |
| 97 /** | |
| 98 * Return a [MergeableOperation] mock with the given priority. | |
| 99 */ | |
| 100 MergeableOperation mockMergeableOperation(ServerOperationPriority priority) { | |
| 101 MergeableOperation operation = new MergeableOperationMock(); | |
| 102 when(operation.priority).thenReturn(priority); | |
| 103 return operation; | |
| 104 } | |
| 105 | |
| 106 | |
| 107 class ServerOperationMock extends TypedMock implements ServerOperation { | |
| 108 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 class MergeableOperationMock extends TypedMock implements MergeableOperation { | |
| 113 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 114 } | |
| OLD | NEW |