1 /*
2  * Copyright (C) 2017 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.lifecycle
18 
19 import androidx.lifecycle.utils.processClass
20 import org.junit.Test
21 import org.junit.runner.RunWith
22 import org.junit.runners.Parameterized
23 
24 @RunWith(Parameterized::class)
25 class InvalidCasesTest(val name: String, val errorMsg: String) {
26     companion object {
27         @JvmStatic
28         @Parameterized.Parameters(name = "failingCase({0})")
datanull29         fun data(): Collection<Array<Any>> =
30             listOf(
31                 arrayOf<Any>("foo.InvalidFirstArg1", ErrorMessages.INVALID_FIRST_ARGUMENT),
32                 arrayOf<Any>("foo.InvalidFirstArg2", ErrorMessages.INVALID_FIRST_ARGUMENT),
33                 arrayOf<Any>("foo.InvalidSecondArg", ErrorMessages.INVALID_SECOND_ARGUMENT),
34                 arrayOf<Any>("foo.TooManyArgs1", ErrorMessages.TOO_MANY_ARGS),
35                 arrayOf<Any>("foo.TooManyArgs2", ErrorMessages.TOO_MANY_ARGS_NOT_ON_ANY),
36                 arrayOf<Any>("foo.InvalidMethodModifier", ErrorMessages.INVALID_METHOD_MODIFIER),
37                 arrayOf<Any>("foo.InvalidClassModifier", ErrorMessages.INVALID_CLASS_MODIFIER),
38                 arrayOf<Any>(
39                     "foo.InvalidInheritance1",
40                     ErrorMessages.INVALID_STATE_OVERRIDE_METHOD
41                 ),
42                 arrayOf<Any>("foo.InvalidInheritance2", ErrorMessages.INVALID_STATE_OVERRIDE_METHOD)
43             )
44     }
45 
46     @Test
47     fun shouldFailWithError() {
48         processClass(name).failsToCompile().withErrorContaining(errorMsg)
49     }
50 }
51