Make StarlarkBuiltinDoc.getJavaMethods() sorted and deterministic
The function was returning a collection; its order was dependent on a hashmap implementation. To avoid writing brittle tests that depend on the function, sort the output.
@@ -17,10 +17,12 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import java.text.Collator;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Locale;
import java.util.TreeMap;
import javax.annotation.Nullable;
@@ -111,11 +113,14 @@ public final class StarlarkBuiltinDoc extends StarlarkDoc {
}
public Collection<StarlarkMethodDoc> getJavaMethods() {
- ImmutableList.Builder<StarlarkMethodDoc> returnedMethods = ImmutableList.builder();
+ ImmutableSortedSet.Builder<StarlarkMethodDoc> methods =
+ new ImmutableSortedSet.Builder<>(Comparator.comparing(StarlarkMethodDoc::getName));
+
if (javaConstructor != null) {
- returnedMethods.add(javaConstructor);
+ methods.add(javaConstructor);
}
- return returnedMethods.addAll(javaMethods.values()).build();
+ methods.addAll(javaMethods.values());
+ return methods.build();
}
public ImmutableCollection<? extends StarlarkMethodDoc> getMethods() {
