mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Fix mismatch in types of Predicates being used
We're going to need to switch away from Guava's Functions and Predicates for everything and replace them with the java.util versions. Unfortunately there does not appear to be an automated tool to do this all at once. Refaster got close but doesn't seem to care about these particular types of mismatch (I suspect we're using a different version of the JDK than the outside world; ours is OK with Guava classes). This also bumps up Guava to 0.23, which is needed for some new functionality used in combination with Java 8 features. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=170531539
This commit is contained in:
parent
447b83f7db
commit
a50ef39c04
9 changed files with 80 additions and 68 deletions
|
@ -14,13 +14,13 @@
|
|||
|
||||
package google.registry.model;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.EntityClasses.ALL_CLASSES;
|
||||
import static google.registry.model.EntityClasses.CLASS_TO_KIND_FUNCTION;
|
||||
import static google.registry.util.TypeUtils.hasAnnotation;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||
|
@ -35,14 +35,9 @@ public class EntityClassesTest {
|
|||
|
||||
// This implements the manual ordering we've been using for the EntityClasses class lists.
|
||||
private static final Ordering<Class<?>> QUALIFIED_CLASS_NAME_ORDERING =
|
||||
Ordering.natural().onResultOf(new Function<Class<?>, String>() {
|
||||
@Override
|
||||
public String apply(Class<?> clazz) {
|
||||
// Return only the part of the class name after the package name, which is the class
|
||||
// name plus any outer class names.
|
||||
return clazz.getCanonicalName().substring(clazz.getPackage().getName().length());
|
||||
}
|
||||
});
|
||||
Ordering.natural()
|
||||
.onResultOf(
|
||||
clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length()));
|
||||
|
||||
@Test
|
||||
public void testEntityClasses_inAlphabeticalOrder() throws Exception {
|
||||
|
@ -51,23 +46,30 @@ public class EntityClassesTest {
|
|||
|
||||
@Test
|
||||
public void testEntityClasses_baseEntitiesHaveUniqueKinds() throws Exception {
|
||||
assertThat(FluentIterable.from(ALL_CLASSES)
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.transform(CLASS_TO_KIND_FUNCTION))
|
||||
.named("base entity kinds")
|
||||
.containsNoDuplicates();
|
||||
assertThat(
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.map(CLASS_TO_KIND_FUNCTION)
|
||||
.collect(toImmutableSet()))
|
||||
.named("base entity kinds")
|
||||
.containsNoDuplicates();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() throws Exception {
|
||||
Set<String> baseEntityKinds = FluentIterable.from(ALL_CLASSES)
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.transform(CLASS_TO_KIND_FUNCTION)
|
||||
.toSet();
|
||||
Set<String> entitySubclassKinds = FluentIterable.from(ALL_CLASSES)
|
||||
.filter(hasAnnotation(EntitySubclass.class))
|
||||
.transform(CLASS_TO_KIND_FUNCTION)
|
||||
.toSet();
|
||||
Set<String> baseEntityKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.map(CLASS_TO_KIND_FUNCTION)
|
||||
.collect(toSet());
|
||||
Set<String> entitySubclassKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(EntitySubclass.class))
|
||||
.map(CLASS_TO_KIND_FUNCTION)
|
||||
.collect(toSet());
|
||||
assertThat(baseEntityKinds).named("base entity kinds").containsAllIn(entitySubclassKinds);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue