Remove the use of InjectRule in UrlFetchUtilsTest

Random used to be a static variable which requires InjectRule to mock it in unit tests. It is now a singleton, which ensures that the same instance is called every time and Random.nextBytes() generates results that distribute uniformly between each call.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217592767
This commit is contained in:
jianglai 2018-10-17 14:53:23 -07:00
parent 84c3544097
commit 4140ef6315
5 changed files with 35 additions and 12 deletions

View file

@ -14,6 +14,7 @@
package google.registry.config;
import static com.google.common.base.Randoms.insecureRandom;
import static com.google.common.base.Suppliers.memoize;
import static google.registry.config.ConfigUtils.makeUrl;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@ -34,6 +35,7 @@ import java.lang.annotation.Retention;
import java.net.URI;
import java.net.URL;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.inject.Named;
@ -1257,6 +1259,17 @@ public final class RegistryConfig {
.build())
.build();
}
/**
* Returns a singleton random number generator.
*
* @see google.registry.util.UrlFetchUtils
*/
@Singleton
@Provides
public static Random provideRandom() {
return insecureRandom();
}
}
/**