mirror of
https://github.com/google/nomulus
synced 2026-09-18 22:14:23 +00:00
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:
@@ -52,10 +52,10 @@ public class UrlFetchUtilsTest {
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final Random random = mock(Random.class);
|
||||
|
||||
@Before
|
||||
public void setupRandomZeroes() {
|
||||
Random random = mock(Random.class);
|
||||
inject.setStaticField(UrlFetchUtils.class, "random", random);
|
||||
doAnswer(
|
||||
info -> {
|
||||
Arrays.fill((byte[]) info.getArguments()[0], (byte) 0);
|
||||
@@ -69,7 +69,12 @@ public class UrlFetchUtilsTest {
|
||||
public void testSetPayloadMultipart() {
|
||||
HTTPRequest request = mock(HTTPRequest.class);
|
||||
setPayloadMultipart(
|
||||
request, "lol", "cat", CSV_UTF_8, "The nice people at the store say hello. ヘ(◕。◕ヘ)");
|
||||
request,
|
||||
"lol",
|
||||
"cat",
|
||||
CSV_UTF_8,
|
||||
"The nice people at the store say hello. ヘ(◕。◕ヘ)",
|
||||
random);
|
||||
ArgumentCaptor<HTTPHeader> headerCaptor = ArgumentCaptor.forClass(HTTPHeader.class);
|
||||
verify(request, times(2)).addHeader(headerCaptor.capture());
|
||||
List<HTTPHeader> addedHeaders = headerCaptor.getAllValues();
|
||||
@@ -97,7 +102,7 @@ public class UrlFetchUtilsTest {
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> setPayloadMultipart(request, "lol", "cat", CSV_UTF_8, payload));
|
||||
() -> setPayloadMultipart(request, "lol", "cat", CSV_UTF_8, payload, random));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
|
||||
Reference in New Issue
Block a user