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.rxjava2.layout
18 
19 import android.app.Activity
20 import android.content.Context
21 import androidx.window.core.ExperimentalWindowApi
22 import androidx.window.layout.FoldingFeature
23 import androidx.window.layout.WindowInfoTracker
24 import androidx.window.layout.WindowLayoutInfo
25 import kotlinx.coroutines.flow.flowOf
26 import org.junit.Test
27 import org.mockito.kotlin.mock
28 import org.mockito.kotlin.whenever
29 
30 /** Tests for the RxJava 2 adapters. */
31 @OptIn(ExperimentalWindowApi::class)
32 class WindowInfoTrackerRxTest {
33 
34     @Test
testWindowLayoutInfoObservablenull35     fun testWindowLayoutInfoObservable() {
36         val activity = mock<Activity>()
37         val feature = mock<FoldingFeature>()
38         val expected = WindowLayoutInfo(listOf(feature))
39         val mockTracker = mock<WindowInfoTracker>()
40         whenever(mockTracker.windowLayoutInfo(activity)).thenReturn(flowOf(expected))
41 
42         val testSubscriber = mockTracker.windowLayoutInfoObservable(activity).test()
43 
44         testSubscriber.assertValue(expected)
45     }
46 
47     @Test
testWindowLayoutInfoFlowablenull48     fun testWindowLayoutInfoFlowable() {
49         val activity = mock<Activity>()
50         val feature = mock<FoldingFeature>()
51         val expected = WindowLayoutInfo(listOf(feature))
52         val mockTracker = mock<WindowInfoTracker>()
53         whenever(mockTracker.windowLayoutInfo(activity)).thenReturn(flowOf(expected))
54 
55         val testSubscriber = mockTracker.windowLayoutInfoFlowable(activity).test()
56 
57         testSubscriber.assertValue(expected)
58     }
59 
60     @Test
testWindowLayoutInfoObservable_contextnull61     fun testWindowLayoutInfoObservable_context() {
62         val activity = mock<Context>()
63         val feature = mock<FoldingFeature>()
64         val expected = WindowLayoutInfo(listOf(feature))
65         val mockTracker = mock<WindowInfoTracker>()
66         whenever(mockTracker.windowLayoutInfo(activity)).thenReturn(flowOf(expected))
67 
68         val testSubscriber = mockTracker.windowLayoutInfoObservable(activity).test()
69 
70         testSubscriber.assertValue(expected)
71     }
72 
73     @Test
testWindowLayoutInfoFlowable_contextnull74     fun testWindowLayoutInfoFlowable_context() {
75         val activity = mock<Context>()
76         val feature = mock<FoldingFeature>()
77         val expected = WindowLayoutInfo(listOf(feature))
78         val mockTracker = mock<WindowInfoTracker>()
79         whenever(mockTracker.windowLayoutInfo(activity)).thenReturn(flowOf(expected))
80 
81         val testSubscriber = mockTracker.windowLayoutInfoFlowable(activity).test()
82 
83         testSubscriber.assertValue(expected)
84     }
85 }
86