diff --git a/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java b/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java index d30416519..92f7cf589 100644 --- a/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java +++ b/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java @@ -16,6 +16,7 @@ package google.registry.beam.spec11; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; @@ -34,6 +35,7 @@ import google.registry.testing.DatastoreEntityExtension; import google.registry.testing.FakeClock; import google.registry.util.ResourceUtils; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; import org.apache.beam.sdk.coders.KvCoder; @@ -48,12 +50,8 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; /** * Unit tests for {@link Spec11Pipeline}. @@ -62,9 +60,8 @@ import org.mockito.quality.Strictness; * Therefore we cannot fully test the pipeline but only test the two separate sink IO functions, * assuming that date is sourcede correctly the {@code BigQueryIO}. */ -@ExtendWith(MockitoExtension.class) -@MockitoSettings(strictness = Strictness.STRICT_STUBS) class Spec11PipelineTest { + private static final String DATE = "2020-01-27"; private static final String SAFE_BROWSING_API_KEY = "api-key"; private static final String REPORTING_BUCKET_URL = "reporting_bucket"; @@ -123,6 +120,11 @@ class Spec11PipelineTest { KvCoder.of( SerializableCoder.of(Subdomain.class), SerializableCoder.of(ThreatMatch.class)))); + assertWithMessage( + "Beam pipelines don't run in an App Engine environment, and thus the tests shouldn't be" + + " mocking one either") + .that(isAppEngine()) + .isFalse(); } @Test @@ -193,6 +195,25 @@ class Spec11PipelineTest { .containsExactlyElementsIn(expectedFileContents.subList(1, expectedFileContents.size())); } + // Adapted from Guava's MoreExecutors (where it is a private method) + private static boolean isAppEngine() { + if (System.getProperty("com.google.appengine.runtime.environment") == null) { + return false; + } else { + try { + return Class.forName("com.google.apphosting.api.ApiProxy") + .getMethod("getCurrentEnvironment") + .invoke(null) + != null; + } catch (ClassNotFoundException + | InvocationTargetException + | IllegalAccessException + | NoSuchMethodException e) { + return false; + } + } + } + /** Returns the text contents of a file under the beamBucket/results directory. */ private ImmutableList resultFileContents() throws Exception { File resultFile =