Unnecessary new (#20138)
* enable lint unnecessary_new * fix tests * fix tests * fix tests
This commit is contained in:
committed by
GitHub
parent
d7a0dcaa4a
commit
d927c93310
@@ -20,7 +20,7 @@ export 'package:test/test.dart' hide TypeMatcher, isInstanceOf; // Defines a 'pa
|
||||
|
||||
/// A matcher that compares the type of the actual value to the type argument T.
|
||||
// TODO(ianh): Remove this once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||
Matcher isInstanceOf<T>() => new test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
|
||||
void tryToDelete(Directory directory) {
|
||||
// This should not be necessary, but it turns out that
|
||||
@@ -42,7 +42,7 @@ String getFlutterRoot() {
|
||||
if (platform.environment.containsKey('FLUTTER_ROOT'))
|
||||
return platform.environment['FLUTTER_ROOT'];
|
||||
|
||||
Error invalidScript() => new StateError('Invalid script: ${platform.script}');
|
||||
Error invalidScript() => StateError('Invalid script: ${platform.script}');
|
||||
|
||||
Uri scriptUri;
|
||||
switch (platform.script.scheme) {
|
||||
@@ -50,7 +50,7 @@ String getFlutterRoot() {
|
||||
scriptUri = platform.script;
|
||||
break;
|
||||
case 'data':
|
||||
final RegExp flutterTools = new RegExp(r'(file://[^"]*[/\\]flutter_tools[/\\][^"]+\.dart)', multiLine: true);
|
||||
final RegExp flutterTools = RegExp(r'(file://[^"]*[/\\]flutter_tools[/\\][^"]+\.dart)', multiLine: true);
|
||||
final Match match = flutterTools.firstMatch(Uri.decodeFull(platform.script.path));
|
||||
if (match == null)
|
||||
throw invalidScript();
|
||||
@@ -69,7 +69,7 @@ String getFlutterRoot() {
|
||||
}
|
||||
|
||||
CommandRunner<Null> createTestCommandRunner([FlutterCommand command]) {
|
||||
final FlutterCommandRunner runner = new FlutterCommandRunner();
|
||||
final FlutterCommandRunner runner = FlutterCommandRunner();
|
||||
if (command != null)
|
||||
runner.addCommand(command);
|
||||
return runner;
|
||||
@@ -79,7 +79,7 @@ CommandRunner<Null> createTestCommandRunner([FlutterCommand command]) {
|
||||
void updateFileModificationTime(String path,
|
||||
DateTime baseTime,
|
||||
int seconds) {
|
||||
final DateTime modificationTime = baseTime.add(new Duration(seconds: seconds));
|
||||
final DateTime modificationTime = baseTime.add(Duration(seconds: seconds));
|
||||
fs.file(path).setLastModifiedSync(modificationTime);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ final Matcher isProcessExit = isInstanceOf<ProcessExit>();
|
||||
Future<String> createProject(Directory temp, {List<String> arguments}) async {
|
||||
arguments ??= <String>['--no-pub'];
|
||||
final String projectPath = fs.path.join(temp.path, 'flutter_project');
|
||||
final CreateCommand command = new CreateCommand();
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<Null> runner = createTestCommandRunner(command);
|
||||
await runner.run(<String>['create']..addAll(arguments)..add(projectPath));
|
||||
return projectPath;
|
||||
|
||||
@@ -58,7 +58,7 @@ void testUsingContext(String description, dynamic testMethod(), {
|
||||
final File settingsFile = fs.file(
|
||||
fs.path.join(configDir.path, '.flutter_settings')
|
||||
);
|
||||
return new Config(settingsFile);
|
||||
return Config(settingsFile);
|
||||
}
|
||||
|
||||
test(description, () async {
|
||||
@@ -67,20 +67,20 @@ void testUsingContext(String description, dynamic testMethod(), {
|
||||
name: 'mocks',
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => buildConfig(fs),
|
||||
DeviceManager: () => new MockDeviceManager(),
|
||||
Doctor: () => new MockDoctor(),
|
||||
FlutterVersion: () => new MockFlutterVersion(),
|
||||
HttpClient: () => new MockHttpClient(),
|
||||
DeviceManager: () => MockDeviceManager(),
|
||||
Doctor: () => MockDoctor(),
|
||||
FlutterVersion: () => MockFlutterVersion(),
|
||||
HttpClient: () => MockHttpClient(),
|
||||
IOSSimulatorUtils: () {
|
||||
final MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils();
|
||||
final MockIOSSimulatorUtils mock = MockIOSSimulatorUtils();
|
||||
when(mock.getAttachedDevices()).thenReturn(<IOSSimulator>[]);
|
||||
return mock;
|
||||
},
|
||||
Logger: () => new BufferLogger(),
|
||||
OperatingSystemUtils: () => new MockOperatingSystemUtils(),
|
||||
SimControl: () => new MockSimControl(),
|
||||
Usage: () => new MockUsage(),
|
||||
XcodeProjectInterpreter: () => new MockXcodeProjectInterpreter(),
|
||||
Logger: () => BufferLogger(),
|
||||
OperatingSystemUtils: () => MockOperatingSystemUtils(),
|
||||
SimControl: () => MockSimControl(),
|
||||
Usage: () => MockUsage(),
|
||||
XcodeProjectInterpreter: () => MockXcodeProjectInterpreter(),
|
||||
},
|
||||
body: () {
|
||||
final String flutterRoot = getFlutterRoot();
|
||||
@@ -154,11 +154,11 @@ class MockDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<Device> getAllConnectedDevices() => new Stream<Device>.fromIterable(devices);
|
||||
Stream<Device> getAllConnectedDevices() => Stream<Device>.fromIterable(devices);
|
||||
|
||||
@override
|
||||
Stream<Device> getDevicesById(String deviceId) {
|
||||
return new Stream<Device>.fromIterable(
|
||||
return Stream<Device>.fromIterable(
|
||||
devices.where((Device device) => device.id == deviceId));
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ class MockDoctor extends Doctor {
|
||||
final List<DoctorValidator> superValidators = super.validators;
|
||||
return superValidators.map((DoctorValidator v) {
|
||||
if (v is AndroidValidator) {
|
||||
return new MockAndroidWorkflowValidator();
|
||||
return MockAndroidWorkflowValidator();
|
||||
}
|
||||
return v;
|
||||
}).toList();
|
||||
@@ -261,7 +261,7 @@ class MockUsage implements Usage {
|
||||
Stream<Map<String, dynamic>> get onSend => null;
|
||||
|
||||
@override
|
||||
Future<Null> ensureAnalyticsSent() => new Future<Null>.value();
|
||||
Future<Null> ensureAnalyticsSent() => Future<Null>.value();
|
||||
|
||||
@override
|
||||
void printWelcome() { }
|
||||
@@ -287,7 +287,7 @@ class MockXcodeProjectInterpreter implements XcodeProjectInterpreter {
|
||||
|
||||
@override
|
||||
XcodeProjectInfo getInfo(String projectPath) {
|
||||
return new XcodeProjectInfo(
|
||||
return XcodeProjectInfo(
|
||||
<String>['Runner'],
|
||||
<String>['Debug', 'Release'],
|
||||
<String>['Runner'],
|
||||
|
||||
@@ -26,12 +26,12 @@ import 'common.dart';
|
||||
|
||||
class MockApplicationPackageStore extends ApplicationPackageStore {
|
||||
MockApplicationPackageStore() : super(
|
||||
android: new AndroidApk(
|
||||
android: AndroidApk(
|
||||
id: 'io.flutter.android.mock',
|
||||
file: fs.file('/mock/path/to/android/SkyShell.apk'),
|
||||
launchActivity: 'io.flutter.android.mock.MockActivity'
|
||||
),
|
||||
iOS: new BuildableIOSApp(new MockIosProject())
|
||||
iOS: BuildableIOSApp(MockIosProject())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ typedef Process ProcessFactory(List<String> command);
|
||||
|
||||
/// A ProcessManager that starts Processes by delegating to a ProcessFactory.
|
||||
class MockProcessManager implements ProcessManager {
|
||||
ProcessFactory processFactory = (List<String> commands) => new MockProcess();
|
||||
ProcessFactory processFactory = (List<String> commands) => MockProcess();
|
||||
bool succeed = true;
|
||||
List<String> commands;
|
||||
|
||||
@@ -132,11 +132,11 @@ class MockProcessManager implements ProcessManager {
|
||||
if (!succeed) {
|
||||
final String executable = command[0];
|
||||
final List<String> arguments = command.length > 1 ? command.sublist(1) : <String>[];
|
||||
throw new ProcessException(executable, arguments);
|
||||
throw ProcessException(executable, arguments);
|
||||
}
|
||||
|
||||
commands = command;
|
||||
return new Future<Process>.value(processFactory(command));
|
||||
return Future<Process>.value(processFactory(command));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -151,8 +151,8 @@ class MockProcess extends Mock implements Process {
|
||||
Stream<List<int>> stdin,
|
||||
this.stdout = const Stream<List<int>>.empty(),
|
||||
this.stderr = const Stream<List<int>>.empty(),
|
||||
}) : exitCode = exitCode ?? new Future<int>.value(0),
|
||||
stdin = stdin ?? new MemoryIOSink();
|
||||
}) : exitCode = exitCode ?? Future<int>.value(0),
|
||||
stdin = stdin ?? MemoryIOSink();
|
||||
|
||||
@override
|
||||
final int pid;
|
||||
@@ -185,8 +185,8 @@ class PromptingProcess implements Process {
|
||||
await _stdoutController.close();
|
||||
}
|
||||
|
||||
final StreamController<List<int>> _stdoutController = new StreamController<List<int>>();
|
||||
final CompleterIOSink _stdin = new CompleterIOSink();
|
||||
final StreamController<List<int>> _stdoutController = StreamController<List<int>>();
|
||||
final CompleterIOSink _stdin = CompleterIOSink();
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stdout => _stdoutController.stream;
|
||||
@@ -209,7 +209,7 @@ class PromptingProcess implements Process {
|
||||
|
||||
/// An IOSink that completes a future with the first line written to it.
|
||||
class CompleterIOSink extends MemoryIOSink {
|
||||
final Completer<List<int>> _completer = new Completer<List<int>>();
|
||||
final Completer<List<int>> _completer = Completer<List<int>>();
|
||||
|
||||
Future<List<int>> get future => _completer.future;
|
||||
|
||||
@@ -235,7 +235,7 @@ class MemoryIOSink implements IOSink {
|
||||
|
||||
@override
|
||||
Future<Null> addStream(Stream<List<int>> stream) {
|
||||
final Completer<Null> completer = new Completer<Null>();
|
||||
final Completer<Null> completer = Completer<Null>();
|
||||
stream.listen((List<int> data) {
|
||||
add(data);
|
||||
}).onDone(() => completer.complete(null));
|
||||
@@ -271,7 +271,7 @@ class MemoryIOSink implements IOSink {
|
||||
|
||||
@override
|
||||
void addError(dynamic error, [StackTrace stackTrace]) {
|
||||
throw new UnimplementedError();
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -286,8 +286,8 @@ class MemoryIOSink implements IOSink {
|
||||
|
||||
/// A Stdio that collects stdout and supports simulated stdin.
|
||||
class MockStdio extends Stdio {
|
||||
final MemoryIOSink _stdout = new MemoryIOSink();
|
||||
final StreamController<List<int>> _stdin = new StreamController<List<int>>();
|
||||
final MemoryIOSink _stdout = MemoryIOSink();
|
||||
final StreamController<List<int>> _stdin = StreamController<List<int>>();
|
||||
|
||||
@override
|
||||
IOSink get stdout => _stdout;
|
||||
@@ -304,8 +304,8 @@ class MockStdio extends Stdio {
|
||||
|
||||
class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
|
||||
final List<Device> _devices = <Device>[];
|
||||
final StreamController<Device> _onAddedController = new StreamController<Device>.broadcast();
|
||||
final StreamController<Device> _onRemovedController = new StreamController<Device>.broadcast();
|
||||
final StreamController<Device> _onAddedController = StreamController<Device>.broadcast();
|
||||
final StreamController<Device> _onRemovedController = StreamController<Device>.broadcast();
|
||||
|
||||
MockPollingDeviceDiscovery() : super('mock');
|
||||
|
||||
@@ -370,7 +370,7 @@ class MockDeviceLogReader extends DeviceLogReader {
|
||||
@override
|
||||
String get name => 'MockLogReader';
|
||||
|
||||
final StreamController<String> _linesController = new StreamController<String>.broadcast();
|
||||
final StreamController<String> _linesController = StreamController<String>.broadcast();
|
||||
|
||||
@override
|
||||
Stream<String> get logLines => _linesController.stream;
|
||||
@@ -384,7 +384,7 @@ class MockDeviceLogReader extends DeviceLogReader {
|
||||
|
||||
void applyMocksToCommand(FlutterCommand command) {
|
||||
command
|
||||
..applicationPackages = new MockApplicationPackageStore();
|
||||
..applicationPackages = MockApplicationPackageStore();
|
||||
}
|
||||
|
||||
/// Common functionality for tracking mock interaction
|
||||
@@ -392,7 +392,7 @@ class BasicMock {
|
||||
final List<String> messages = <String>[];
|
||||
|
||||
void expectMessages(List<String> expectedMessages) {
|
||||
final List<String> actualMessages = new List<String>.from(messages);
|
||||
final List<String> actualMessages = List<String>.from(messages);
|
||||
messages.clear();
|
||||
expect(actualMessages, unorderedEquals(expectedMessages));
|
||||
}
|
||||
@@ -461,6 +461,6 @@ class MockResidentCompiler extends BasicMock implements ResidentCompiler {
|
||||
Future<CompilerOutput> recompile(String mainPath, List<String> invalidatedFiles, {String outputPath, String packagesFilePath}) async {
|
||||
fs.file(outputPath).createSync(recursive: true);
|
||||
fs.file(outputPath).writeAsStringSync('compiled_kernel_output');
|
||||
return new CompilerOutput(outputPath, 0);
|
||||
return CompilerOutput(outputPath, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user