Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12eee03b authored by Matías Hernández's avatar Matías Hernández
Browse files

Add test to verify that no-Metric MetricStyle-to-view doesn't throw

Bug: 433727001
Test: atest NotificationMetricStyleTest
Flag: android.app.api_metric_style
Change-Id: I2e0902f3c55a7245a2214e126f4f1cc8106e8c5d
parent 3d6ade0b
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -679,6 +679,32 @@ public class NotificationMetricStyleTest {
        assertThat(container.findViewById(R.id.metric_unit_1).getVisibility()).isEqualTo(GONE);
    }

    @Test
    public void makeContentViews_emptyMetrics_noException() {
        FrameLayout container = new FrameLayout(mContext);
        Notification.Builder noMetrics = new Notification.Builder(mContext, "channel")
                .setStyle(new MetricStyle());

        RemoteViews basic = noMetrics.getStyle().makeContentView();
        RemoteViews expanded = noMetrics.getStyle().makeExpandedContentView();
        RemoteViews headsUp = noMetrics.getStyle().makeHeadsUpContentView();
        RemoteViews compactHeadsUp = noMetrics.getStyle().makeCompactHeadsUpContentView();

        if (basic != null) {
            container.addView(basic.apply(mContext, container));
        }
        if (expanded != null) {
            container.addView(expanded.apply(mContext, container));
        }
        if (headsUp != null) {
            container.addView(headsUp.apply(mContext, container));
        }
        if (compactHeadsUp != null) {
            container.addView(compactHeadsUp.apply(mContext, container));
        }
        // No crashes.
    }

    private void withLocale(Locale locale, Runnable r) {
        Locale previous = Locale.getDefault();
        try {