Unverified Commit cf54d6a2 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from file system test (#74919)

parent a664731a
......@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/signals.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -147,15 +147,12 @@ void main() {
});
group('LocalFileSystem', () {
MockIoProcessSignal mockSignal;
FakeProcessSignal fakeSignal;
ProcessSignal signalUnderTest;
StreamController<io.ProcessSignal> controller;
setUp(() {
mockSignal = MockIoProcessSignal();
signalUnderTest = ProcessSignal(mockSignal);
controller = StreamController<io.ProcessSignal>();
when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream);
fakeSignal = FakeProcessSignal();
signalUnderTest = ProcessSignal(fakeSignal);
});
testUsingContext('deletes system temp entry on a fatal signal', () async {
......@@ -173,7 +170,7 @@ void main() {
expect(temp.existsSync(), isTrue);
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
expect(temp.existsSync(), isFalse);
......@@ -181,5 +178,10 @@ void main() {
});
}
class MockIoProcessSignal extends Mock implements io.ProcessSignal {}
class MockFile extends Mock implements File {}
class FakeProcessSignal extends Fake implements io.ProcessSignal {
final StreamController<io.ProcessSignal> controller = StreamController<io.ProcessSignal>();
@override
Stream<io.ProcessSignal> watch() => controller.stream;
}
class FakeFile extends Fake implements File {}
......@@ -9,7 +9,7 @@ import 'dart:io' as io;
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -57,12 +57,10 @@ void main() {
}, flutterIOOverrides);
});
testUsingContext('ProcessSignal signals are properly delegated', () async {
final MockIoProcessSignal mockSignal = MockIoProcessSignal();
final ProcessSignal signalUnderTest = ProcessSignal(mockSignal);
final StreamController<io.ProcessSignal> controller = StreamController<io.ProcessSignal>();
final FakeProcessSignal signal = FakeProcessSignal();
final ProcessSignal signalUnderTest = ProcessSignal(signal);
when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream);
controller.add(mockSignal);
signal.controller.add(signal);
expect(signalUnderTest, await signalUnderTest.watch().first);
});
......@@ -104,4 +102,9 @@ void main() {
});
}
class MockIoProcessSignal extends Mock implements io.ProcessSignal {}
class FakeProcessSignal extends Fake implements io.ProcessSignal {
final StreamController<io.ProcessSignal> controller = StreamController<io.ProcessSignal>();
@override
Stream<io.ProcessSignal> watch() => controller.stream;
}
......@@ -16,16 +16,13 @@ import '../../src/common.dart';
void main() {
group('Signals', () {
Signals signals;
MockIoProcessSignal mockSignal;
FakeProcessSignal fakeSignal;
ProcessSignal signalUnderTest;
StreamController<io.ProcessSignal> controller;
setUp(() {
signals = Signals.test();
mockSignal = MockIoProcessSignal();
signalUnderTest = ProcessSignal(mockSignal);
controller = StreamController<io.ProcessSignal>();
when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream);
fakeSignal = FakeProcessSignal();
signalUnderTest = ProcessSignal(fakeSignal);
});
testWithoutContext('signal handler runs', () async {
......@@ -35,7 +32,7 @@ void main() {
completer.complete();
});
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
});
......@@ -55,7 +52,7 @@ void main() {
completer.complete();
});
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
});
......@@ -74,7 +71,7 @@ void main() {
},
);
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
await errSub.cancel();
expect(errList, contains(exn));
......@@ -97,7 +94,7 @@ void main() {
},
);
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await errSub.cancel();
expect(errList, isEmpty);
......@@ -125,19 +122,16 @@ void main() {
},
);
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
await errSub.cancel();
expect(errList, isEmpty);
});
testWithoutContext('only handlers for the correct signal run', () async {
final MockIoProcessSignal mockSignal2 = MockIoProcessSignal();
final StreamController<io.ProcessSignal> controller2 = StreamController<io.ProcessSignal>();
final FakeProcessSignal mockSignal2 = FakeProcessSignal();
final ProcessSignal otherSignal = ProcessSignal(mockSignal2);
when(mockSignal2.watch()).thenAnswer((Invocation invocation) => controller2.stream);
final Completer<void> completer = Completer<void>();
signals.addHandler(signalUnderTest, (ProcessSignal s) {
expect(s, signalUnderTest);
......@@ -155,7 +149,7 @@ void main() {
},
);
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
await errSub.cancel();
expect(errList, isEmpty);
......@@ -192,10 +186,15 @@ void main() {
second = true;
});
controller.add(mockSignal);
fakeSignal.controller.add(fakeSignal);
await completer.future;
});
});
}
class MockIoProcessSignal extends Mock implements io.ProcessSignal {}
class FakeProcessSignal extends Fake implements io.ProcessSignal {
final StreamController<io.ProcessSignal> controller = StreamController<io.ProcessSignal>();
@override
Stream<io.ProcessSignal> watch() => controller.stream;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment