Skip to content

Commit

Permalink
use system-stubs-junit4
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Oct 25, 2024
1 parent 89d7e8d commit 3fb7cae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
13 changes: 9 additions & 4 deletions google-cloud-firestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,15 @@
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-lambda</artifactId>
<version>1.2.1</version>
<!-- <dependency>-->
<!-- <groupId>com.github.stefanbirkner</groupId>-->
<!-- <artifactId>system-lambda</artifactId>-->
<!-- <version>1.2.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-junit4</artifactId>
<version>2.1.7</version>
<scope>test</scope>
</dependency>
<!-- Need testing utility classes for generated gRPC clients tests -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

package com.google.cloud.firestore.telemetry;

import static com.github.stefanbirkner.systemlambda.SystemLambda.*;
// import static com.github.stefanbirkner.systemlambda.SystemLambda.*;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.firestore.FirestoreOptions;
import org.junit.Rule;
import org.junit.Test;
import uk.org.webcompere.systemstubs.rules.EnvironmentVariablesRule;

public class MetricsUtilTest {
@Rule public EnvironmentVariablesRule rule = new EnvironmentVariablesRule();

@Test
public void defaultOptionsUseEnabledMetricsUtil() {
MetricsUtil util =
Expand All @@ -35,18 +39,31 @@ public void defaultOptionsUseEnabledMetricsUtil() {
assertThat(util instanceof EnabledMetricsUtil).isTrue();
}

// @Test
// public void disabledMetricsUtilWhenEnvVarIsOff() throws Exception {
// withEnvironmentVariable("FIRESTORE_ENABLE_METRICS", "off")
// .execute(
// () -> {
// MetricsUtil util =
// MetricsUtil.getInstance(
// FirestoreOptions.newBuilder()
// .setProjectId("test-project")
// .setDatabaseId("(default)")
// .build());
// assertThat(util instanceof DisabledMetricsUtil).isTrue();
// });
// }

@Test
public void disabledMetricsUtilWhenEnvVarIsOff() throws Exception {
withEnvironmentVariable("FIRESTORE_ENABLE_METRICS", "off")
.execute(
() -> {
MetricsUtil util =
MetricsUtil.getInstance(
FirestoreOptions.newBuilder()
.setProjectId("test-project")
.setDatabaseId("(default)")
.build());
assertThat(util instanceof DisabledMetricsUtil).isTrue();
});
rule.set("FIRESTORE_ENABLE_METRICS", "off");

MetricsUtil util =
MetricsUtil.getInstance(
FirestoreOptions.newBuilder()
.setProjectId("test-project")
.setDatabaseId("(default)")
.build());
assertThat(util instanceof DisabledMetricsUtil).isTrue();
}
}

0 comments on commit 3fb7cae

Please sign in to comment.