diff --git a/packages/flutter_driver/lib/src/driver/timeline_summary.dart b/packages/flutter_driver/lib/src/driver/timeline_summary.dart index 5a613e1105..8c97417104 100644 --- a/packages/flutter_driver/lib/src/driver/timeline_summary.dart +++ b/packages/flutter_driver/lib/src/driver/timeline_summary.dart @@ -162,7 +162,7 @@ class TimelineSummary { double _averageInMillis(Iterable durations) { if (durations.isEmpty) - return null; + throw new ArgumentError('durations is empty!'); final int total = durations.fold(0, (int t, Duration duration) => t + duration.inMilliseconds); return total / durations.length; @@ -170,7 +170,7 @@ class TimelineSummary { double _percentileInMillis(Iterable durations, double percentile) { if (durations.isEmpty) - return null; + throw new ArgumentError('durations is empty!'); assert(percentile >= 0.0 && percentile <= 100.0); final List doubles = durations.map((Duration duration) => duration.inMilliseconds.toDouble()).toList(); @@ -181,7 +181,7 @@ class TimelineSummary { double _maxInMillis(Iterable durations) { if (durations.isEmpty) - return null; + throw new ArgumentError('durations is empty!'); return durations .map((Duration duration) => duration.inMilliseconds.toDouble()) diff --git a/packages/flutter_driver/test/src/timeline_summary_test.dart b/packages/flutter_driver/test/src/timeline_summary_test.dart index 4a35dbf594..142a19892e 100644 --- a/packages/flutter_driver/test/src/timeline_summary_test.dart +++ b/packages/flutter_driver/test/src/timeline_summary_test.dart @@ -55,8 +55,11 @@ void main() { }); group('average_frame_build_time_millis', () { - test('returns null when there is no data', () { - expect(summarize(>[]).computeAverageFrameBuildTimeMillis(), isNull); + test('throws when there is no data', () { + expect( + () => summarize(>[]).computeAverageFrameBuildTimeMillis(), + throwsA(predicate((ArgumentError e) => e.message == 'durations is empty!')) + ); }); test('computes average frame build time in milliseconds', () { @@ -71,8 +74,11 @@ void main() { }); group('worst_frame_build_time_millis', () { - test('returns null when there is no data', () { - expect(summarize(>[]).computeWorstFrameBuildTimeMillis(), isNull); + test('throws when there is no data', () { + expect( + () => summarize(>[]).computeWorstFrameBuildTimeMillis(), + throwsA(predicate((ArgumentError e) => e.message == 'durations is empty!')) + ); }); test('computes worst frame build time in milliseconds', () { @@ -107,8 +113,11 @@ void main() { }); group('average_frame_rasterizer_time_millis', () { - test('returns null when there is no data', () { - expect(summarize(>[]).computeAverageFrameRasterizerTimeMillis(), isNull); + test('throws when there is no data', () { + expect( + () => summarize(>[]).computeAverageFrameRasterizerTimeMillis(), + throwsA(predicate((ArgumentError e) => e.message == 'durations is empty!')) + ); }); test('computes average frame rasterizer time in milliseconds', () { @@ -143,10 +152,14 @@ void main() { }); group('worst_frame_rasterizer_time_millis', () { - test('returns null when there is no data', () { - expect(summarize(>[]).computeWorstFrameRasterizerTimeMillis(), isNull); + test('throws when there is no data', () { + expect( + () => summarize(>[]).computeWorstFrameRasterizerTimeMillis(), + throwsA(predicate((ArgumentError e) => e.message == 'durations is empty!')) + ); }); + test('computes worst frame rasterizer time in milliseconds', () { expect( summarize(>[ @@ -186,10 +199,14 @@ void main() { }); group('percentile_frame_rasterizer_time_millis', () { - test('returns null when there is no data', () { - expect(summarize(>[]).computeWorstFrameRasterizerTimeMillis(), isNull); + test('throws when there is no data', () { + expect( + () => summarize(>[]).computePercentileFrameRasterizerTimeMillis(90.0), + throwsA(predicate((ArgumentError e) => e.message == 'durations is empty!')) + ); }); + const List> sequences = >[ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5],