Diego Vela | f710acb | 2021-11-12 09:47:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package androidx.window.layout |
| 18 | |
Diego Vela | d9a44f7 | 2022-01-20 15:32:44 -0800 | [diff] [blame] | 19 | import androidx.window.core.ConsumerAdapter |
Diego Vela | f710acb | 2021-11-12 09:47:42 -0800 | [diff] [blame] | 20 | import androidx.window.extensions.WindowExtensionsProvider |
| 21 | import org.junit.Assert.assertNotNull |
| 22 | import org.junit.Assert.assertNull |
| 23 | import 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 | */ |
| 30 | class 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 Vela | d9a44f7 | 2022-01-20 15:32:44 -0800 | [diff] [blame] | 38 | val loader = SafeWindowLayoutComponentProviderTest::class.java.classLoader!! |
| 39 | val consumerAdapter = ConsumerAdapter(loader) |
| 40 | val safeComponent = SafeWindowLayoutComponentProvider(loader, consumerAdapter) |
| 41 | .windowLayoutComponent |
Diego Vela | f710acb | 2021-11-12 09:47:42 -0800 | [diff] [blame] | 42 | |
| 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 | } |