1/* 2 * Copyright 2018 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.navigation.safe.args.generator 18 19import androidx.navigation.safe.args.generator.models.Destination 20import androidx.navigation.safe.args.generator.models.ResReference 21import com.squareup.javapoet.ClassName 22import org.hamcrest.CoreMatchers.`is` 23import org.hamcrest.MatcherAssert.assertThat 24import org.junit.Test 25import org.junit.runner.RunWith 26import org.junit.runners.JUnit4 27 28@RunWith(JUnit4::class) 29class DestinationTest { 30 31 @Test 32 fun fullName() { 33 val name = Destination.createName(id("main"), "foo.sub.ClassName", "some.app") 34 assertThat(name, `is`(ClassName.get("foo.sub", "ClassName"))) 35 } 36 37 @Test 38 fun relativeWithSubpackage() { 39 val name = Destination.createName(id("main"), ".sub.ClassName", "some.app") 40 assertThat(name, `is`(ClassName.get("some.app.sub", "ClassName"))) 41 } 42 43 @Test 44 fun fullNameNoPackage() { 45 val name = Destination.createName(id("main"), "ClassName", "some.app") 46 assertThat(name, `is`(ClassName.get("", "ClassName"))) 47 } 48 49 @Test 50 fun idOnly() { 51 val name = Destination.createName(id("main"), "", "some.app") 52 assertThat(name, `is`(ClassName.get("foo.bar", "Main"))) 53 } 54} 55 56private fun id(name: String) = ResReference("foo.bar", "id", name)