diff options
Diffstat (limited to 'javatests/artifacts/dagger/lazyclasskey/app')
12 files changed, 371 insertions, 0 deletions
diff --git a/javatests/artifacts/dagger/lazyclasskey/app/build.gradle b/javatests/artifacts/dagger/lazyclasskey/app/build.gradle new file mode 100644 index 000000000..b44309afd --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/build.gradle @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 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' +} + +android { + + namespace 'dagger.lazyclasskey' + compileSdkVersion 33 + defaultConfig { + applicationId 'dagger.lazyclasskey' + minSdk 16 + targetSdk 33 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + debug { + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile( + 'proguard-android-optimize.txt'), + 'proguard-rules.pro' + + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.errorprone:error_prone_annotations:2.15.0' + + androidTestImplementation 'androidx.test:core:1.5.0-alpha02' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation "androidx.test:runner:1.5.2" + androidTestImplementation "androidx.test:rules:1.5.0" + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + // Dagger dependencies + implementation "com.google.dagger:dagger:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" +} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/proguard-rules.pro b/javatests/artifacts/dagger/lazyclasskey/app/proguard-rules.pro new file mode 100644 index 000000000..95980023c --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/proguard-rules.pro @@ -0,0 +1,5 @@ + +-dontwarn com.google.errorprone.annotations.MustBeClosed + # TODO(b/324097623) Remove the keep rules once test won't be affected by obfuscation +-keep class kotlin.** +-keep class javax.** { *; } diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/androidTest/java/dagger/lazyclasskey/FlowerAppTest.java b/javatests/artifacts/dagger/lazyclasskey/app/src/androidTest/java/dagger/lazyclasskey/FlowerAppTest.java new file mode 100644 index 000000000..86e1401bd --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/androidTest/java/dagger/lazyclasskey/FlowerAppTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withResourceName; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.startsWith; + +import android.content.Intent; +import androidx.test.core.app.ActivityScenario; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class FlowerAppTest { + @Test + public void testFlowerAppWithR8DoesNotCrash() { + Intent mainIntent = + new Intent(ApplicationProvider.getApplicationContext(), FlowerActivity.class); + try (ActivityScenario<FlowerActivity> scenario = ActivityScenario.launch(mainIntent)) { + onView(withResourceName("flower_info")) + .check(matches(withText(startsWith(Lily.class.getSimpleName())))); + } + } +} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/AndroidManifest.xml b/javatests/artifacts/dagger/lazyclasskey/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..cec40616b --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/AndroidManifest.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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.lazyclasskey"> + <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34"/> + <application + android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:taskAffinity="" + android:label="@string/app_name"> + <activity + android:name=".FlowerActivity" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + </application> +</manifest> + diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Flower.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Flower.java new file mode 100644 index 000000000..34161a1f9 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Flower.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +/** Base class for flowers. */ +interface Flower {} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerActivity.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerActivity.java new file mode 100644 index 000000000..005012733 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerActivity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +import android.os.Bundle; +import android.widget.TextView; +import androidx.activity.ComponentActivity; +import java.util.Locale; +import java.util.Map; + +/** Displays flower price information. */ +public final class FlowerActivity extends ComponentActivity { + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Map<Class<?>, Integer> flowerPrices = DaggerFlowerComponent.create().getFlowerMap(); + setContentView(R.layout.flower_activity); + if (!flowerPrices.containsKey(Rose.class)) { + throw new IllegalStateException("Rose price not found"); + } + if (!flowerPrices.containsKey(Lily.class)) { + throw new IllegalStateException("Lily price not found"); + } + ((TextView) findViewById(R.id.flower_info)) + .setText( + String.format( + Locale.US, + "%s : %d dollar, %s : %d dollar", + Lily.class.getSimpleName(), + flowerPrices.get(Lily.class), + Rose.class.getSimpleName(), + flowerPrices.get(Rose.class))); + } + + class ProguardClassNames { + Rose rose; + Lily lily; + } +} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerComponent.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerComponent.java new file mode 100644 index 000000000..1302126ed --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerComponent.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +import dagger.Component; +import java.util.Map; + +/** Dagger component for flower bindings. */ +@Component(modules = FlowerModule.class) +public interface FlowerComponent { + Map<Class<?>, Integer> getFlowerMap(); +} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerModule.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerModule.java new file mode 100644 index 000000000..4f9b61c0d --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/FlowerModule.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +import dagger.Module; +import dagger.Provides; +import dagger.multibindings.IntoMap; +import dagger.multibindings.LazyClassKey; + +/** Module for providing flower prices. */ +@Module +abstract class FlowerModule { + @IntoMap + @LazyClassKey(Lily.class) + @Provides + static int lilyPrice() { + return 1; + } + + @IntoMap + @LazyClassKey(Rose.class) + @Provides + static int rosePrice() { + return 2; + } +} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Lily.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Lily.java new file mode 100644 index 000000000..c8c21be78 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Lily.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +/** Stores info for Lily. */ +final class Lily implements Flower {} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Rose.java b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Rose.java new file mode 100644 index 000000000..abdd87a50 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/java/dagger/lazyclasskey/Rose.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 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.lazyclasskey; + +/** Stores information for Rose. */ +final class Rose implements Flower {} diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/layout/flower_activity.xml b/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/layout/flower_activity.xml new file mode 100644 index 000000000..400691d74 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/layout/flower_activity.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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. + --> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + <TextView android:id="@+id/flower_info" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> +</LinearLayout> + diff --git a/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/values/strings.xml b/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..72ad12a27 --- /dev/null +++ b/javatests/artifacts/dagger/lazyclasskey/app/src/main/res/values/strings.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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 name of the application [CHAR LIMIT=25] --> + <string name="app_name">Flower Demo</string> +</resources> + |