Unverified Commit b6655330 authored by Ayush Bherwani's avatar Ayush Bherwani Committed by GitHub

[MediaQueryData] adds assertions to MediaQueryData Constructor (#53003)

parent e4a61dfd
......@@ -102,7 +102,21 @@ class MediaQueryData {
this.highContrast = false,
this.disableAnimations = false,
this.boldText = false,
});
}) : assert(size != null),
assert(devicePixelRatio != null),
assert(textScaleFactor != null),
assert(platformBrightness != null),
assert(padding != null),
assert(viewInsets != null),
assert(systemGestureInsets != null),
assert(viewPadding != null),
assert(physicalDepth != null),
assert(alwaysUse24HourFormat != null),
assert(accessibleNavigation != null),
assert(invertColors != null),
assert(highContrast != null),
assert(disableAnimations != null),
assert(boldText != null);
/// Creates data for a media query based on the given window.
///
......
......@@ -564,4 +564,170 @@ void main() {
expect(outsideBoldTextOverride, false);
expect(insideBoldTextOverride, true);
});
test('size parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(size: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('size != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('devicePixelRatio parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(devicePixelRatio: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('devicePixelRatio != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('textScaleFactor parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(textScaleFactor: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('textScaleFactor != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('platformBrightness parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(platformBrightness: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('platformBrightness != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('padding parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(padding: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('padding != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('viewInsets parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(viewInsets: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('viewInsets != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('systemGestureInsets parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(systemGestureInsets: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('systemGestureInsets != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('viewPadding parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(viewPadding: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('viewPadding != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('physicalDepth parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(physicalDepth: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('physicalDepth != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('alwaysUse24HourFormat parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(alwaysUse24HourFormat: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('alwaysUse24HourFormat != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('accessibleNavigation parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(accessibleNavigation: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('accessibleNavigation != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('invertColors parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(invertColors: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('invertColors != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('highContrast parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(highContrast: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('highContrast != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('disableAnimations parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(disableAnimations: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('disableAnimations != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
test('boldText parameter in MediaQueryData cannot be null', () {
try {
MediaQueryData(boldText: null);
} on AssertionError catch (error) {
expect(error.toString(), contains('boldText != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('The assert was never called when it should have been');
});
}
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