blob: 246e9a314cbe21e4b53b7e00ec150a1d57d5a2ec [file] [log] [blame]
Diego Velaf710acb2021-11-12 09:47:42 -08001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.window.layout
18
Diego Velad9a44f72022-01-20 15:32:44 -080019import androidx.window.core.ConsumerAdapter
Diego Velaf710acb2021-11-12 09:47:42 -080020import androidx.window.extensions.WindowExtensionsProvider
21import org.junit.Assert.assertNotNull
22import org.junit.Assert.assertNull
23import org.junit.Test
24
25/**
26 * An integration test to verify that if [WindowExtensionsProvider] is present then
27 * [SafeWindowLayoutComponentProvider.windowLayoutComponent] will return a value. This can fail if
28 * the implementation of window:extensions:extensions does not have the expected API.
29 */
30class SafeWindowLayoutComponentProviderTest {
31
32 /**
33 * Test that if [WindowExtensionsProvider] is available then
34 * [SafeWindowLayoutComponentProvider.windowLayoutComponent] returns a non-null value.
35 */
36 @Test
37 fun windowLayoutComponentIsAvailable_ifProviderIsAvailable() {
Diego Velad9a44f72022-01-20 15:32:44 -080038 val loader = SafeWindowLayoutComponentProviderTest::class.java.classLoader!!
39 val consumerAdapter = ConsumerAdapter(loader)
40 val safeComponent = SafeWindowLayoutComponentProvider(loader, consumerAdapter)
41 .windowLayoutComponent
Diego Velaf710acb2021-11-12 09:47:42 -080042
43 try {
44 val extensions = WindowExtensionsProvider.getWindowExtensions()
45 val actualComponent = extensions.windowLayoutComponent
46 if (actualComponent == null) {
47 assertNull(safeComponent)
48 } else {
49 assertNotNull(safeComponent)
50 }
51 } catch (e: UnsupportedOperationException) {
52 // Invalid implementation of extensions
53 assertNull(safeComponent)
54 }
55 }
56}