Code inspector test clean up.

Make sure code inspector tests fail if the grandfather list contains
things that no longer exists in code

Change-Id: Ib114909959040275a9d9aebd81ecbe3d96d3af03
Test: make RunSettingsRoboTests -j40
Fix: 37686032
This commit is contained in:
Fan Zhang
2017-05-15 14:55:47 -07:00
parent 9834bd82da
commit 51449262db
7 changed files with 31 additions and 25 deletions

View File

@@ -24,6 +24,8 @@ import java.io.InputStreamReader;
import java.lang.reflect.Modifier;
import java.util.List;
import static com.google.common.truth.Truth.assertWithMessage;
/**
* Inspector takes a list of class objects and perform static code analysis in its {@link #run()}
* method.
@@ -46,6 +48,17 @@ public abstract class CodeInspector {
*/
public abstract void run();
protected void assertNoObsoleteInGrandfatherList(String listName, List<String> list) {
final StringBuilder obsoleteGrandfatherItems = new StringBuilder(
listName + " contains item that should not be grandfathered.\n");
for (String c : list) {
obsoleteGrandfatherItems.append(c).append("\n");
}
assertWithMessage(obsoleteGrandfatherItems.toString())
.that(list)
.isEmpty();
}
protected boolean isConcreteSettingsClass(Class clazz) {
// Abstract classes
if (Modifier.isAbstract(clazz.getModifiers())) {

View File

@@ -51,9 +51,11 @@ public class InstrumentableFragmentCodeInspector extends CodeInspector {
}
final String className = clazz.getName();
// If it's a fragment, it must also be instrumentable.
final boolean whitelisted =
grandfather_notImplementingInstrumentable.remove(className);
if (Fragment.class.isAssignableFrom(clazz)
&& !Instrumentable.class.isAssignableFrom(clazz)
&& !grandfather_notImplementingInstrumentable.contains(className)) {
&& !whitelisted) {
broken.add(className);
}
}
@@ -65,5 +67,7 @@ public class InstrumentableFragmentCodeInspector extends CodeInspector {
assertWithMessage(sb.toString())
.that(broken.isEmpty())
.isTrue();
assertNoObsoleteInGrandfatherList("grandfather_not_implementing_instrumentable",
grandfather_notImplementingInstrumentable);
}
}

View File

@@ -91,7 +91,7 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
// If it's a SettingsPreferenceFragment, it must also be Indexable.
final boolean implementsIndexable = Indexable.class.isAssignableFrom(clazz);
if (!implementsIndexable) {
if (!notImplementingIndexableGrandfatherList.contains(className)) {
if (!notImplementingIndexableGrandfatherList.remove(className)) {
notImplementingIndexable.add(className);
}
continue;
@@ -99,7 +99,7 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
final boolean hasSearchIndexProvider = hasSearchIndexProvider(clazz);
// If it implements Indexable, it must also implement the index provider field.
if (!hasSearchIndexProvider) {
if (!notImplementingIndexProviderGrandfatherList.contains(className)) {
if (!notImplementingIndexProviderGrandfatherList.remove(className)) {
notImplementingIndexProvider.add(className);
}
continue;
@@ -109,14 +109,14 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
final boolean isSharingPrefControllers = DashboardFragmentSearchIndexProviderInspector
.isSharingPreferenceControllers(clazz);
if (!isSharingPrefControllers) {
if (!notSharingPrefControllersGrandfatherList.contains(className)) {
if (!notSharingPrefControllersGrandfatherList.remove(className)) {
notSharingPreferenceControllers.add(className);
}
continue;
}
// Must be in SearchProviderRegistry
if (SearchIndexableResources.getResourceByName(className) == null) {
if (!notInSearchIndexableRegistryGrandfatherList.contains(className)) {
if (!notInSearchIndexableRegistryGrandfatherList.remove(className)) {
notInSearchProviderRegistry.add(className);
}
continue;
@@ -145,6 +145,15 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
assertWithMessage(notInProviderRegistryError)
.that(notInSearchProviderRegistry)
.isEmpty();
assertNoObsoleteInGrandfatherList("grandfather_not_implementing_indexable",
notImplementingIndexableGrandfatherList);
assertNoObsoleteInGrandfatherList("grandfather_not_implementing_index_provider",
notImplementingIndexProviderGrandfatherList);
assertNoObsoleteInGrandfatherList("grandfather_not_in_search_index_provider_registry",
notInSearchIndexableRegistryGrandfatherList);
assertNoObsoleteInGrandfatherList(
"grandfather_not_sharing_pref_controllers_with_search_provider",
notSharingPrefControllersGrandfatherList);
}
private boolean hasSearchIndexProvider(Class clazz) {