Clean up some weird patterns and dead code from a case in `JSTypeTest`.
package com.google.javascript.rhino.jstype;
+import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static com.google.javascript.rhino.jstype.TernaryValue.FALSE;
import static com.google.javascript.rhino.jstype.TernaryValue.TRUE;
@@ -57,9 +58,9 @@ import com.google.javascript.rhino.jstype.JSType.TypePair;
import com.google.javascript.rhino.testing.Asserts;
import com.google.javascript.rhino.testing.BaseJSTypeTestCase;
import com.google.javascript.rhino.testing.MapBasedScope;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
// TODO(nicksantos): Split some of this up into per-class unit tests.
public class JSTypeTest extends BaseJSTypeTestCase {
@@ -5568,15 +5569,22 @@ public class JSTypeTest extends BaseJSTypeTestCase {
}
public void testRegisterProperty() {
- int i = 0;
- List<JSType> allObjects = new ArrayList<>();
- for (JSType type : types) {
- String propName = "ALF" + i++;
- if (type instanceof ObjectType) {
-
- ObjectType objType = (ObjectType) type;
- objType.defineDeclaredProperty(propName, UNKNOWN_TYPE, null);
- objType.defineDeclaredProperty("allHaz", UNKNOWN_TYPE, null);
+ // Get a subset of our list of standard types to test containing just ObjectTypes and already
+ // cast to ObjectType.
+ ImmutableList<ObjectType> objectTypes =
+ types
+ .stream()
+ .map(JSType::toMaybeObjectType)
+ .filter(Objects::nonNull)
+ .collect(toImmutableList());
+ assertThat(objectTypes).isNotEmpty();
+
+ for (int i = 0; i < objectTypes.size(); i++) {
+ ObjectType type = objectTypes.get(i);
+ String propName = "ALF" + i;
+
+ type.defineDeclaredProperty(propName, UNKNOWN_TYPE, null);
+ type.defineDeclaredProperty("allHaz", UNKNOWN_TYPE, null);
// We exclude {a: number, b: string} because, for inline record types,
// we register their properties on a sentinel object literal in the registry.
@@ -5584,10 +5592,8 @@ public class JSTypeTest extends BaseJSTypeTestCase {
assertTypeEquals(type, registry.getGreatestSubtypeWithProperty(type, propName));
}
- assertTypeEquals(NO_TYPE,
- registry.getGreatestSubtypeWithProperty(type, "GRRR"));
- allObjects.add(type);
- }
+ // We don't define property "GRRR" on any of our ObjectTypes.
+ assertTypeEquals(NO_TYPE, registry.getGreatestSubtypeWithProperty(type, "GRRR"));
}
}
