Skip to content

Commit 85113bb

Browse files
committed
Make tests compile again
1 parent 2d6d63d commit 85113bb

7 files changed

+80
-94
lines changed

example/lib/generated_plugin_registrant.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// ignore_for_file: lines_longer_than_80_chars
6+
57
import 'package:url_launcher_web/url_launcher_web.dart';
68

79
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

test/fake_cache_manager.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FakeCacheManager extends Mock implements CacheManager {
2525
ExpectedData returns(
2626
String url,
2727
List<int> imageData, {
28-
Duration delayBetweenChunks,
28+
Duration? delayBetweenChunks,
2929
}) {
3030
const chunkSize = 8;
3131
final chunks = <Uint8List>[
@@ -58,7 +58,7 @@ class FakeCacheManager extends Mock implements CacheManager {
5858
String url,
5959
List<Uint8List> chunks,
6060
List<int> imageData,
61-
Duration delayBetweenChunks,
61+
Duration? delayBetweenChunks,
6262
) async* {
6363
var totalSize = imageData.length;
6464
var downloaded = 0;
@@ -80,7 +80,7 @@ class FakeImageCacheManager extends Mock implements ImageCacheManager {
8080
ExpectedData returns(
8181
String url,
8282
List<int> imageData, {
83-
Duration delayBetweenChunks,
83+
Duration? delayBetweenChunks,
8484
}) {
8585
const chunkSize = 8;
8686
final chunks = <Uint8List>[
@@ -115,7 +115,7 @@ class FakeImageCacheManager extends Mock implements ImageCacheManager {
115115
String url,
116116
List<Uint8List> chunks,
117117
List<int> imageData,
118-
Duration delayBetweenChunks,
118+
Duration? delayBetweenChunks,
119119
) async* {
120120
var totalSize = imageData.length;
121121
var downloaded = 0;
@@ -138,5 +138,7 @@ class ExpectedData {
138138
final int totalSize;
139139
final int chunkSize;
140140

141-
const ExpectedData({this.chunks, this.totalSize, this.chunkSize});
141+
const ExpectedData({required this.chunks, required this.totalSize, required
142+
this
143+
.chunkSize,});
142144
}

test/image_cache_manager_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ void main() {
2323
setUp(() {});
2424

2525
tearDown(() {
26-
PaintingBinding.instance.imageCache.clear();
27-
PaintingBinding.instance.imageCache.clearLiveImages();
26+
PaintingBinding.instance?.imageCache?.clear();
27+
PaintingBinding.instance?.imageCache?.clearLiveImages();
2828
});
2929

3030
test('Supplying an ImageCacheManager should call getImageFile', () async {
@@ -109,7 +109,7 @@ void main() {
109109
result.addListener(
110110
ImageStreamListener((ImageInfo image, bool synchronousCall) {
111111
imageAvailable.complete();
112-
}, onError: (dynamic error, StackTrace stackTrace) {
112+
}, onError: (dynamic error, StackTrace? stackTrace) {
113113
caughtError.complete(error);
114114
}));
115115
final dynamic err = await caughtError.future;
@@ -132,7 +132,7 @@ void main() {
132132
result.addListener(
133133
ImageStreamListener((ImageInfo image, bool synchronousCall) {
134134
imageAvailable.complete();
135-
}, onError: (dynamic error, StackTrace stackTrace) {
135+
}, onError: (dynamic error, StackTrace? stackTrace) {
136136
caughtError.complete(error);
137137
}));
138138
final dynamic err = await caughtError.future;

test/image_provider_test.dart

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ import 'rendering_tester.dart';
1919
void main() {
2020
TestRenderingFlutterBinding();
2121

22-
FakeCacheManager cacheManager;
22+
late FakeCacheManager cacheManager;
2323

2424
setUp(() {
2525
cacheManager = FakeCacheManager();
2626
});
2727

2828
tearDown(() {
29-
cacheManager = null;
30-
PaintingBinding.instance.imageCache.clear();
31-
PaintingBinding.instance.imageCache.clearLiveImages();
29+
PaintingBinding.instance?.imageCache?.clear();
30+
PaintingBinding.instance?.imageCache?.clearLiveImages();
3231
});
3332

3433
test('Expect thrown exception with statusCode - evicts from cache', () async {
@@ -40,23 +39,23 @@ void main() {
4039
final ImageProvider imageProvider = CachedNetworkImageProvider(
4140
nonconst(requestUrl),
4241
cacheManager: cacheManager);
43-
expect(imageCache.pendingImageCount, 0);
44-
expect(imageCache.statusForKey(imageProvider).untracked, true);
42+
expect(imageCache?.pendingImageCount, 0);
43+
expect(imageCache?.statusForKey(imageProvider).untracked, true);
4544

4645
final result = imageProvider.resolve(ImageConfiguration.empty);
4746

48-
expect(imageCache.pendingImageCount, 1);
49-
expect(imageCache.statusForKey(imageProvider).pending, true);
47+
expect(imageCache?.pendingImageCount, 1);
48+
expect(imageCache?.statusForKey(imageProvider).pending, true);
5049

5150
result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) {},
52-
onError: (dynamic error, StackTrace stackTrace) {
51+
onError: (dynamic error, StackTrace? stackTrace) {
5352
caughtError.complete(error);
5453
}));
5554

5655
final dynamic err = await caughtError.future;
5756

58-
expect(imageCache.pendingImageCount, 0);
59-
expect(imageCache.statusForKey(imageProvider).untracked, true);
57+
expect(imageCache?.pendingImageCount, 0);
58+
expect(imageCache?.statusForKey(imageProvider).untracked, true);
6059

6160
expect(
6261
err,
@@ -90,7 +89,7 @@ void main() {
9089
};
9190
final result = imageProvider.resolve(ImageConfiguration.empty);
9291
result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) {},
93-
onError: (dynamic error, StackTrace stackTrace) {
92+
onError: (dynamic error, StackTrace? stackTrace) {
9493
caughtError.complete(true);
9594
}));
9695
expect(await caughtError.future, true);
@@ -119,7 +118,7 @@ void main() {
119118
onChunk: (ImageChunkEvent event) {
120119
events.add(event);
121120
},
122-
onError: (dynamic error, StackTrace stackTrace) {
121+
onError: (dynamic error, StackTrace? stackTrace) {
123122
imageAvailable.completeError(error as Object, stackTrace);
124123
},
125124
));
@@ -133,18 +132,6 @@ void main() {
133132
expect(events[i].expectedTotalBytes, kTransparentImage.length);
134133
}
135134
}, skip: isBrowser); // Browser loads images through <img> not Http.
136-
137-
test('Expect assertionError when url is null', () {
138-
expect(() => CachedNetworkImageProvider(null, cacheManager: cacheManager),
139-
throwsAssertionError);
140-
});
141-
142-
test('Expect assertionError when scale is null', () {
143-
expect(
144-
() => CachedNetworkImageProvider('foo',
145-
scale: null, cacheManager: cacheManager),
146-
throwsAssertionError);
147-
});
148135
}
149136

150137
class FakeCodec implements Codec {

test/image_stream_completer_test.dart

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FakeFrameInfo implements FrameInfo {
2222
@override
2323
Image get image => _image;
2424

25-
int get imageHandleCount => image.debugGetOpenHandleStackTraces().length;
25+
int get imageHandleCount => image.debugGetOpenHandleStackTraces()!.length;
2626

2727
FakeFrameInfo clone() {
2828
return FakeFrameInfo(
@@ -34,10 +34,10 @@ class FakeFrameInfo implements FrameInfo {
3434

3535
class MockCodec implements Codec {
3636
@override
37-
int frameCount;
37+
int frameCount = 1;
3838

3939
@override
40-
int repetitionCount;
40+
int repetitionCount = 1;
4141

4242
int numFramesAsked = 0;
4343

@@ -64,7 +64,7 @@ class MockCodec implements Codec {
6464

6565
class FakeEventReportingImageStreamCompleter extends ImageStreamCompleter {
6666
FakeEventReportingImageStreamCompleter(
67-
{Stream<ImageChunkEvent> chunkEvents}) {
67+
{Stream<ImageChunkEvent>? chunkEvents}) {
6868
if (chunkEvents != null) {
6969
chunkEvents.listen(
7070
(ImageChunkEvent event) {
@@ -76,9 +76,9 @@ class FakeEventReportingImageStreamCompleter extends ImageStreamCompleter {
7676
}
7777

7878
void main() {
79-
Image image20x10;
80-
Image image200x100;
81-
Image image300x100;
79+
late Image image20x10;
80+
late Image image200x100;
81+
late Image image300x100;
8282
setUp(() async {
8383
image20x10 = await createTestImage(width: 20, height: 10);
8484
image200x100 = await createTestImage(width: 200, height: 100);
@@ -110,7 +110,7 @@ void main() {
110110
await tester.idle();
111111
expect(mockCodec.numFramesAsked, 0);
112112

113-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
113+
final listener = (ImageInfo image, bool synchronousCall) {};
114114
imageStream.addListener(ImageStreamListener(listener));
115115
await tester.idle();
116116
expect(mockCodec.numFramesAsked, 1);
@@ -126,7 +126,7 @@ void main() {
126126
scale: 1.0,
127127
);
128128

129-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
129+
final listener = (ImageInfo image, bool synchronousCall) {};
130130
imageStream.addListener(ImageStreamListener(listener));
131131
await tester.idle();
132132
expect(mockCodec.numFramesAsked, 0);
@@ -147,7 +147,7 @@ void main() {
147147
scale: 1.0,
148148
);
149149

150-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
150+
final listener = (ImageInfo image, bool synchronousCall) {};
151151
imageStream.addListener(ImageStreamListener(listener));
152152
await tester.idle();
153153
expect(firstCodec.numFramesAsked, 0);
@@ -177,7 +177,7 @@ void main() {
177177
await tester.idle();
178178
expect(mockCodec.numFramesAsked, 0);
179179

180-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
180+
final listener = (ImageInfo image, bool synchronousCall) {};
181181
final streamListener = ImageStreamListener(listener);
182182
imageStream.addListener(streamListener);
183183
await tester.idle();
@@ -343,7 +343,7 @@ void main() {
343343
scale: 1.0,
344344
);
345345

346-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
346+
final listener = (ImageInfo image, bool synchronousCall) {};
347347
imageStream.addListener(ImageStreamListener(listener));
348348
codecStream.add(mockCodec);
349349
// MultiImageStreamCompleter only sets an error handler for the next
@@ -536,7 +536,7 @@ void main() {
536536
scale: 1.0,
537537
);
538538

539-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
539+
final listener = (ImageInfo image, bool synchronousCall) {};
540540
imageStream.addListener(ImageStreamListener(listener));
541541
final handle = imageStream.keepAlive();
542542

@@ -579,11 +579,11 @@ void main() {
579579
);
580580

581581
final emittedImages1 = <ImageInfo>[];
582-
final ImageListener listener1 = (ImageInfo image, bool synchronousCall) {
582+
final listener1 = (ImageInfo image, bool synchronousCall) {
583583
emittedImages1.add(image);
584584
};
585585
final emittedImages2 = <ImageInfo>[];
586-
final ImageListener listener2 = (ImageInfo image, bool synchronousCall) {
586+
final listener2 = (ImageInfo image, bool synchronousCall) {
587587
emittedImages2.add(image);
588588
};
589589
imageStream.addListener(ImageStreamListener(listener1));
@@ -627,7 +627,7 @@ void main() {
627627
scale: 1.0,
628628
);
629629

630-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
630+
final listener = (ImageInfo image, bool synchronousCall) {};
631631
imageStream.addListener(ImageStreamListener(listener));
632632

633633
codecStream.add(mockCodec);
@@ -664,7 +664,7 @@ void main() {
664664

665665
dynamic capturedException;
666666
final ImageErrorListener errorListener =
667-
(dynamic exception, StackTrace stackTrace) {
667+
(dynamic exception, StackTrace? stackTrace) {
668668
capturedException = exception;
669669
};
670670

@@ -699,7 +699,7 @@ void main() {
699699
scale: 1.0,
700700
);
701701

702-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
702+
final listener = (ImageInfo image, bool synchronousCall) {};
703703
imageStream.addListener(ImageStreamListener(listener));
704704

705705
codecStream.add(mockCodec);
@@ -735,7 +735,7 @@ void main() {
735735
);
736736

737737
var onImageCount = 0;
738-
final ImageListener activeListener =
738+
final activeListener =
739739
(ImageInfo image, bool synchronousCall) {
740740
onImageCount += 1;
741741
};
@@ -747,7 +747,7 @@ void main() {
747747
expect(lastListenerDropped, false);
748748
final handle = imageStream.keepAlive();
749749
expect(lastListenerDropped, false);
750-
SchedulerBinding.instance
750+
SchedulerBinding.instance!
751751
.debugAssertNoTransientCallbacks('Only passive listeners');
752752

753753
codecStream.add(mockCodec);
@@ -758,17 +758,17 @@ void main() {
758758
final frame1 = FakeFrameInfo(Duration.zero, image20x10);
759759
mockCodec.completeNextFrame(frame1);
760760
await tester.idle();
761-
SchedulerBinding.instance
761+
SchedulerBinding.instance!
762762
.debugAssertNoTransientCallbacks('Only passive listeners');
763763
await tester.pump();
764764
expect(onImageCount, 0);
765765

766766
imageStream.addListener(ImageStreamListener(activeListener));
767767

768-
final frame2 = FakeFrameInfo(Duration.zero, image10x10);
768+
final frame2 = FakeFrameInfo(Duration.zero, image10x10!);
769769
mockCodec.completeNextFrame(frame2);
770770
await tester.idle();
771-
expect(SchedulerBinding.instance.transientCallbackCount, 1);
771+
expect(SchedulerBinding.instance!.transientCallbackCount, 1);
772772
await tester.pump();
773773

774774
expect(onImageCount, 1);
@@ -778,17 +778,17 @@ void main() {
778778

779779
mockCodec.completeNextFrame(frame1);
780780
await tester.idle();
781-
expect(SchedulerBinding.instance.transientCallbackCount, 1);
781+
expect(SchedulerBinding.instance!.transientCallbackCount, 1);
782782
await tester.pump();
783783

784784
expect(onImageCount, 1);
785785

786-
SchedulerBinding.instance
786+
SchedulerBinding.instance!
787787
.debugAssertNoTransientCallbacks('Only passive listeners');
788788

789789
mockCodec.completeNextFrame(frame2);
790790
await tester.idle();
791-
SchedulerBinding.instance
791+
SchedulerBinding.instance!
792792
.debugAssertNoTransientCallbacks('Only passive listeners');
793793
await tester.pump();
794794

@@ -811,7 +811,7 @@ void main() {
811811
scale: 1.0,
812812
);
813813

814-
final ImageListener listener = (ImageInfo image, bool synchronousCall) {};
814+
final listener = (ImageInfo image, bool synchronousCall) {};
815815
imageStream.addListener(ImageStreamListener(listener));
816816

817817
codecStream.add(firstCodec);
@@ -850,9 +850,4 @@ void main() {
850850
expect(firstCodec.numFramesAsked, 3);
851851
expect(secondCodec.numFramesAsked, 1);
852852
});
853-
854-
test('Expect assertion error when codec stream is null', () {
855-
expect(() => MultiImageStreamCompleter(codec: null, scale: 1.0),
856-
throwsAssertionError);
857-
});
858853
}

0 commit comments

Comments
 (0)