blob: 8104d5fb23efd40ee8702d5b961b1c7a203f4f22 [file] [log] [blame]
Rahul Ravikumar9359ac22019-07-15 17:07:52 -07001/*
2 * Copyright 2019 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.work
18
19import android.content.Context
20import androidx.test.core.app.ApplicationProvider
21import androidx.test.ext.junit.runners.AndroidJUnit4
22import androidx.test.filters.SmallTest
23import org.hamcrest.CoreMatchers.notNullValue
24import org.hamcrest.MatcherAssert.assertThat
25import org.hamcrest.Matchers.`is`
26import org.junit.Before
27import org.junit.Test
28import org.junit.runner.RunWith
29import org.mockito.Mockito.mock
30import org.mockito.Mockito.times
31import org.mockito.Mockito.verify
32
33@RunWith(AndroidJUnit4::class)
34@SmallTest
35class InputMergerFactoryTest {
36 private lateinit var context: Context
37 private lateinit var factory: InputMergerFactory
38 private lateinit var configuration: Configuration
39
40 @Before
41 fun setUp() {
42 context = ApplicationProvider.getApplicationContext()
43 factory = mock(InputMergerFactory::class.java)
44 configuration = Configuration.Builder()
45 .setInputMergerFactory(factory)
46 .build()
47 }
48
49 @Test
50 fun testInputMergerFactory() {
51 val name = ArrayCreatingInputMerger::class.java.name
52 val merger = configuration.inputMergerFactory.createInputMergerWithDefaultFallback(name)
53 assertThat(merger, notNullValue())
54 verify(factory, times(1)).createInputMerger(name)
55 }
56
57 @Test
58 fun testInputMergerFactory2() {
59 factory = object : InputMergerFactory() {
60 override fun createInputMerger(className: String): InputMerger? {
61 return OverwritingInputMerger()
62 }
63 }
64 configuration = Configuration.Builder()
65 .setInputMergerFactory(factory)
66 .build()
67
68 val name = ArrayCreatingInputMerger::class.java.name
69 val merger = configuration.inputMergerFactory.createInputMergerWithDefaultFallback(name)
70 val instanceCheck = merger is OverwritingInputMerger
71 assertThat(merger, notNullValue())
72 assertThat(instanceCheck, `is`(true))
73 }
74}