Merge "Add tests where constructor params have annotations" into oc-mr1-support-27.0-dev
diff --git a/room/compiler/src/test/kotlin/android/arch/persistence/room/processor/PojoProcessorTest.kt b/room/compiler/src/test/kotlin/android/arch/persistence/room/processor/PojoProcessorTest.kt
index bf34b4c..97cfe74 100644
--- a/room/compiler/src/test/kotlin/android/arch/persistence/room/processor/PojoProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/android/arch/persistence/room/processor/PojoProcessorTest.kt
@@ -552,7 +552,7 @@
}
@Test
- fun constructor_ambiguous_twoFieldsExcatMatch() {
+ fun constructor_ambiguous_twoFieldsExactMatch() {
val pojoCode = """
public String mName;
public String _name;
@@ -708,6 +708,18 @@
ProcessorErrors.TOO_MANY_POJO_CONSTRUCTORS_CHOOSING_NO_ARG)
}
+ @Test // added for b/69562125
+ fun constructor_withNullabilityAnnotation() {
+ singleRun("""
+ String mName;
+ public MyPojo(@android.support.annotation.NonNull String name) {}
+ """) { pojo ->
+ val constructor = pojo.constructor
+ assertThat(constructor, notNullValue())
+ assertThat(constructor!!.params.size, `is`(1))
+ }.compilesWithoutError()
+ }
+
@Test
fun recursion_1Level() {
singleRun(
diff --git a/room/integration-tests/testapp/src/androidTest/java/android/arch/persistence/room/integration/testapp/test/ConstructorTest.java b/room/integration-tests/testapp/src/androidTest/java/android/arch/persistence/room/integration/testapp/test/ConstructorTest.java
index 7a21d98..46c875c 100644
--- a/room/integration-tests/testapp/src/androidTest/java/android/arch/persistence/room/integration/testapp/test/ConstructorTest.java
+++ b/room/integration-tests/testapp/src/androidTest/java/android/arch/persistence/room/integration/testapp/test/ConstructorTest.java
@@ -28,6 +28,8 @@
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -40,7 +42,8 @@
@SuppressWarnings("SqlNoDataSourceInspection")
@SmallTest
public class ConstructorTest {
- @Database(version = 1, entities = {FullConstructor.class, PartialConstructor.class},
+ @Database(version = 1, entities = {FullConstructor.class, PartialConstructor.class,
+ EntityWithAnnotations.class},
exportSchema = false)
abstract static class MyDb extends RoomDatabase {
abstract MyDao dao();
@@ -59,6 +62,12 @@
@Query("SELECT * FROM pc WHERE a = :a")
PartialConstructor loadPartial(int a);
+
+ @Insert
+ void insertEntityWithAnnotations(EntityWithAnnotations... items);
+
+ @Query("SELECT * FROM EntityWithAnnotations")
+ EntityWithAnnotations getEntitiWithAnnotations();
}
@SuppressWarnings("WeakerAccess")
@@ -167,6 +176,50 @@
}
}
+ @SuppressWarnings("WeakerAccess")
+ @Entity
+ static class EntityWithAnnotations {
+ @PrimaryKey
+ @NonNull
+ public final String id;
+
+ @NonNull
+ public final String username;
+
+ @Nullable
+ public final String displayName;
+
+ EntityWithAnnotations(
+ @NonNull String id,
+ @NonNull String username,
+ @Nullable String displayName) {
+ this.id = id;
+ this.username = username;
+ this.displayName = displayName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ EntityWithAnnotations that = (EntityWithAnnotations) o;
+
+ if (!id.equals(that.id)) return false;
+ if (!username.equals(that.username)) return false;
+ return displayName != null ? displayName.equals(that.displayName)
+ : that.displayName == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id.hashCode();
+ result = 31 * result + username.hashCode();
+ result = 31 * result + (displayName != null ? displayName.hashCode() : 0);
+ return result;
+ }
+ }
+
private MyDb mDb;
private MyDao mDao;
@@ -193,4 +246,11 @@
PartialConstructor load = mDao.loadPartial(3);
assertThat(load, is(item));
}
+
+ @Test // for bug b/69562125
+ public void entityWithAnnotations() {
+ EntityWithAnnotations item = new EntityWithAnnotations("a", "b", null);
+ mDao.insertEntityWithAnnotations(item);
+ assertThat(mDao.getEntitiWithAnnotations(), is(item));
+ }
}