1 /* 2 * Copyright (C) 2020 The Dagger Authors. 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 dagger.hilt.android.processor.internal.androidentrypoint; 18 19 import static com.google.testing.compile.CompilationSubject.assertThat; 20 import static dagger.hilt.android.testing.compile.HiltCompilerTests.compiler; 21 22 import com.google.testing.compile.Compilation; 23 import com.google.testing.compile.JavaFileObjects; 24 import javax.tools.JavaFileObject; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 @RunWith(JUnit4.class) 30 public class ActivityGeneratorTest { 31 32 @Test generate_componentActivity()33 public void generate_componentActivity() { 34 JavaFileObject myActivity = 35 JavaFileObjects.forSourceLines( 36 "test.MyActivity", 37 "package test;", 38 "", 39 "import androidx.activity.ComponentActivity;", 40 "import dagger.hilt.android.AndroidEntryPoint;", 41 "", 42 "@AndroidEntryPoint(ComponentActivity.class)", 43 "public class MyActivity extends Hilt_MyActivity {", 44 "}"); 45 Compilation compilation = compiler().compile(myActivity); 46 assertThat(compilation).succeeded(); 47 } 48 49 @Test generate_baseHiltComponentActivity()50 public void generate_baseHiltComponentActivity() { 51 JavaFileObject baseActivity = 52 JavaFileObjects.forSourceLines( 53 "test.BaseActivity", 54 "package test;", 55 "", 56 "import androidx.activity.ComponentActivity;", 57 "import dagger.hilt.android.AndroidEntryPoint;", 58 "", 59 "@AndroidEntryPoint(ComponentActivity.class)", 60 "public class BaseActivity extends Hilt_BaseActivity {", 61 "}"); 62 JavaFileObject myActivity = 63 JavaFileObjects.forSourceLines( 64 "test.MyActivity", 65 "package test;", 66 "", 67 "import androidx.activity.ComponentActivity;", 68 "import dagger.hilt.android.AndroidEntryPoint;", 69 "", 70 "@AndroidEntryPoint(BaseActivity.class)", 71 "public class MyActivity extends Hilt_MyActivity {", 72 "}"); 73 Compilation compilation = compiler().compile(baseActivity, myActivity); 74 assertThat(compilation).succeeded(); 75 } 76 } 77