aboutsummaryrefslogtreecommitdiff
path: root/javatests/artifacts/dagger-android-ksp/app
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/artifacts/dagger-android-ksp/app')
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/build.gradle74
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml30
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt22
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt26
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt68
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt53
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt22
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt25
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml30
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml24
-rw-r--r--javatests/artifacts/dagger-android-ksp/app/src/sharedTest/kotlin/dagger/android/ksp/SimpleActivityTest.kt46
11 files changed, 420 insertions, 0 deletions
diff --git a/javatests/artifacts/dagger-android-ksp/app/build.gradle b/javatests/artifacts/dagger-android-ksp/app/build.gradle
new file mode 100644
index 000000000..434590a47
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/build.gradle
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+plugins {
+ id 'com.android.application'
+ id 'org.jetbrains.kotlin.android'
+ id 'com.google.devtools.ksp'
+}
+
+android {
+ namespace 'dagger.android.ksp'
+ compileSdkVersion 33
+ defaultConfig {
+ applicationId 'dagger.android.ksp'
+ minSdk 16
+ targetSdk 33
+ versionCode 1
+ versionName "1.0"
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+ testOptions {
+ unitTests.includeAndroidResources = true
+ }
+ sourceSets {
+ String sharedTestDir = 'src/sharedTest/java'
+ test {
+ java.srcDirs += sharedTestDir
+ }
+ androidTest {
+ java.srcDirs += sharedTestDir
+ }
+ }
+}
+
+dependencies {
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+
+ testImplementation 'com.google.truth:truth:1.0.1'
+ testImplementation 'org.robolectric:robolectric:4.11.1'
+ testImplementation 'androidx.core:core:1.3.2'
+ testImplementation 'androidx.test.ext:junit:1.1.5'
+ testImplementation 'androidx.test:runner:1.5.2'
+ testImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+
+ androidTestImplementation 'com.google.truth:truth:1.0.1'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.5'
+ androidTestImplementation 'androidx.test:runner:1.5.2'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+
+ // Dagger Android dependencies
+ implementation 'com.google.dagger:dagger:LOCAL-SNAPSHOT'
+ implementation 'com.google.dagger:dagger-android-support:LOCAL-SNAPSHOT'
+ implementation 'com.google.dagger:dagger-android:LOCAL-SNAPSHOT'
+ ksp 'com.google.dagger:dagger-android-processor:LOCAL-SNAPSHOT'
+ ksp "com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT"
+} \ No newline at end of file
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..89b0dbfd9
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<!--
+ ~ Copyright (C) 2023 The Dagger Authors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="dagger.android.ksp">
+
+ <application
+ android:name=".SimpleApplication"
+ android:label="@string/appName"
+ android:theme="@style/Theme.AppCompat.Light">
+ <activity android:name=".SimpleActivity" android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest> \ No newline at end of file
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt
new file mode 100644
index 000000000..8dd333dd5
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import javax.inject.Qualifier
+
+/** Qualifies bindings relating to [android.os.Build.MODEL]. */
+@Qualifier @Retention(AnnotationRetention.RUNTIME) internal annotation class Model
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt
new file mode 100644
index 000000000..25c0f72ba
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import android.os.Build.MODEL
+import dagger.Module
+import dagger.Provides
+
+@Module
+object ModelModule {
+ @Provides @Model fun provideModel(): String = MODEL
+}
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt
new file mode 100644
index 000000000..5b9b84b03
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import android.os.Bundle
+import android.util.Log
+import android.widget.TextView
+import dagger.Binds
+import dagger.Module
+import dagger.Subcomponent
+import dagger.android.AndroidInjector
+import dagger.android.support.DaggerAppCompatActivity
+import dagger.multibindings.ClassKey
+import dagger.multibindings.IntoMap
+import javax.inject.Inject
+
+/**
+ * The main activity of the application.
+ *
+ * <p>It can be injected with any binding from both {@link SimpleActivityComponent} and {@link
+ * SimpleApplication.SimpleComponent}.
+ */
+class SimpleActivity : DaggerAppCompatActivity() {
+ private val TAG: String = SimpleActivity::class.java.getSimpleName()
+
+ @Inject @UserName lateinit var userName: String
+ @Inject @Model lateinit var model: String
+
+ override protected fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ Log.i(TAG, "Injected with userName and model: " + userName + ", " + model)
+
+ setContentView(R.layout.activity_main)
+
+ val greeting = findViewById(R.id.greeting) as TextView
+ val text = getResources().getString(R.string.welcome, userName, model)
+ greeting.setText(text)
+ }
+}
+
+@Subcomponent
+interface SimpleActivityComponent : AndroidInjector<SimpleActivity> {
+
+ @Subcomponent.Factory interface Factory : AndroidInjector.Factory<SimpleActivity> {}
+}
+
+@Module(subcomponents = [SimpleActivityComponent::class], includes = [UserNameModule::class])
+interface InjectorModule {
+ @Binds
+ @IntoMap
+ @ClassKey(SimpleActivity::class)
+ fun bind(factory: SimpleActivityComponent.Factory): AndroidInjector.Factory<*>
+}
+
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt
new file mode 100644
index 000000000..37dfd0500
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import android.util.Log
+import dagger.Component
+import dagger.android.AndroidInjectionModule
+import dagger.android.AndroidInjector
+import dagger.android.DaggerApplication
+import javax.inject.Inject
+import javax.inject.Singleton
+
+/**
+ * A simple, skeletal application that demonstrates a dependency-injected application using the
+ * utilities in {@code dagger.android}.
+ */
+class SimpleApplication : DaggerApplication() {
+ private val TAG = SimpleApplication::class.java.getSimpleName()
+
+ @Inject @Model lateinit var model: String
+
+ override public fun onCreate() {
+ super.onCreate()
+ Log.i(TAG, "Injected with model: " + model)
+ }
+
+ override protected fun applicationInjector(): AndroidInjector<SimpleApplication> {
+ return DaggerSimpleComponent.factory().create(this)
+ }
+}
+
+@Singleton
+@Component(
+ modules =
+ [AndroidInjectionModule::class, InjectorModule::class, ModelModule::class]
+)
+interface SimpleComponent : AndroidInjector<SimpleApplication> {
+ @Component.Factory interface Factory : AndroidInjector.Factory<SimpleApplication> {}
+}
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt
new file mode 100644
index 000000000..3388c09c0
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import javax.inject.Qualifier
+
+/** Qualifies bindings relating to the user name. */
+@Qualifier @Retention(AnnotationRetention.RUNTIME) internal annotation class UserName
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt
new file mode 100644
index 000000000..2628398d2
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import dagger.Module
+import dagger.Provides
+
+@Module
+object UserNameModule {
+ @UserName @Provides fun provideUserName(): String = "ProdUser"
+}
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..4693e5513
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 The Dagger Authors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@android:color/background_light">
+
+ <TextView
+ android:id="@+id/greeting"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_alignParentTop="true"
+ android:textColor="@android:color/primary_text_light"
+ />
+</RelativeLayout> \ No newline at end of file
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..4bf0e39bf
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 The Dagger Authors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<resources>
+ <!--The app name [CHAR_LIMIT=25]-->
+ <string name="appName">Simple Dagger Android</string>
+
+ <!--The greeting message [CHAR_LIMIT=100]-->
+ <string name="welcome">Hello, %1$s! You are on build %2$s.</string>
+</resources> \ No newline at end of file
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/sharedTest/kotlin/dagger/android/ksp/SimpleActivityTest.kt b/javatests/artifacts/dagger-android-ksp/app/src/sharedTest/kotlin/dagger/android/ksp/SimpleActivityTest.kt
new file mode 100644
index 000000000..22a2efb2f
--- /dev/null
+++ b/javatests/artifacts/dagger-android-ksp/app/src/sharedTest/kotlin/dagger/android/ksp/SimpleActivityTest.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.android.ksp
+
+import android.content.Context
+import androidx.test.core.app.ActivityScenario
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.espresso.matcher.ViewMatchers.withText
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class SimpleActivityTest {
+ @Test
+ fun testActivityInject() {
+ ActivityScenario.launch(SimpleActivity::class.java).onActivity { activity ->
+ onView(withId(R.id.greeting))
+ .check(matches(withText("Hello, ProdUser! You are on build robolectric.")))
+ }
+ }
+
+ @Test
+ fun verifyApplicationInstance() {
+ assertThat((ApplicationProvider.getApplicationContext() as Context) is SimpleApplication)
+ .isTrue()
+ }
+}