Skip to content

Commit

Permalink
Migrate usages of Truth8.assertThat to equivalent usages of `Truth.…
Browse files Browse the repository at this point in the history
…assertThat`.

The `Truth8` methods have been deprecated. Callers should move to `Truth`.

**If your project is also built outside the monorepo:** Some (but not all) of the CLs in this batch require Truth [1.4.0](https://github.com/google/truth/releases/tag/v1.4.0). If I see a presubmit failure, I'll look for a place to upgrade the version. Or you can point me there ahead of time.

PiperOrigin-RevId: 606267767
Change-Id: Ic1e37e2172e45f86efaaa23eeba6859a85a4c9bb
  • Loading branch information
cpovirk authored and copybara-github committed Feb 12, 2024
1 parent 84f2f50 commit cac9e76
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth8;
import java.util.List;
import java.util.Map;
import org.junit.After;
Expand Down Expand Up @@ -56,12 +55,12 @@ public void fromYamlData_whenNullYamlData_createEmptyConfigData() {
public void getSystemProperty_whenPropertyExists_returnsPropertyValue() {
System.setProperty(TEST_PROPERTY, "Test value");

Truth8.assertThat(TsunamiConfig.getSystemProperty(TEST_PROPERTY)).hasValue("Test value");
assertThat(TsunamiConfig.getSystemProperty(TEST_PROPERTY)).hasValue("Test value");
}

@Test
public void getSystemProperty_whenPropertyNotExists_returnsEmptyOptional() {
Truth8.assertThat(TsunamiConfig.getSystemProperty(TEST_PROPERTY)).isEmpty();
assertThat(TsunamiConfig.getSystemProperty(TEST_PROPERTY)).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.tsunami.common.net.UrlUtils.removeTrailingSlashes;
import static com.google.tsunami.common.net.UrlUtils.urlEncode;

import com.google.common.truth.Truth8;
import okhttp3.HttpUrl;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -127,44 +126,42 @@ public void removeTrailingSlashes_whenMultipleTrailingSlashes_removesTrailingSla

@Test
public void urlEncode_whenEmptyString_returnsOriginal() {
Truth8.assertThat(urlEncode("")).hasValue("");
assertThat(urlEncode("")).hasValue("");
}

@Test
public void urlEncode_whenNothingToEncode_returnsOriginal() {
Truth8.assertThat(urlEncode("abcdefghijklmnopqrstuvwxyz"))
.hasValue("abcdefghijklmnopqrstuvwxyz");
Truth8.assertThat(urlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
.hasValue("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Truth8.assertThat(urlEncode("0123456789")).hasValue("0123456789");
Truth8.assertThat(urlEncode("-_.*")).hasValue("-_.*");
assertThat(urlEncode("abcdefghijklmnopqrstuvwxyz")).hasValue("abcdefghijklmnopqrstuvwxyz");
assertThat(urlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZ")).hasValue("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
assertThat(urlEncode("0123456789")).hasValue("0123456789");
assertThat(urlEncode("-_.*")).hasValue("-_.*");
}

@Test
public void urlEncode_whenNotEncoded_returnsEncoded() {
Truth8.assertThat(urlEncode(" ")).hasValue("+");
Truth8.assertThat(urlEncode("()[]{}<>")).hasValue("%28%29%5B%5D%7B%7D%3C%3E");
Truth8.assertThat(urlEncode("?!@#$%^&=+,;:'\"`/\\|~"))
assertThat(urlEncode(" ")).hasValue("+");
assertThat(urlEncode("()[]{}<>")).hasValue("%28%29%5B%5D%7B%7D%3C%3E");
assertThat(urlEncode("?!@#$%^&=+,;:'\"`/\\|~"))
.hasValue("%3F%21%40%23%24%25%5E%26%3D%2B%2C%3B%3A%27%22%60%2F%5C%7C%7E");
}

@Test
public void urlEncode_whenAlreadyEncoded_encodesAgain() {
Truth8.assertThat(urlEncode("%2F")).hasValue("%252F");
Truth8.assertThat(urlEncode("%252F")).hasValue("%25252F");
assertThat(urlEncode("%2F")).hasValue("%252F");
assertThat(urlEncode("%252F")).hasValue("%25252F");
}

@Test
public void urlEncode_whenComplexEncoding_encodesCorrectly() {
Truth8.assertThat(urlEncode("£")).hasValue("%C2%A3");
Truth8.assertThat(urlEncode("つ")).hasValue("%E3%81%A4");
Truth8.assertThat(urlEncode("äëïöüÿ")).hasValue("%C3%A4%C3%AB%C3%AF%C3%B6%C3%BC%C3%BF");
Truth8.assertThat(urlEncode("ÄËÏÖÜŸ")).hasValue("%C3%84%C3%8B%C3%8F%C3%96%C3%9C%C5%B8");
assertThat(urlEncode("£")).hasValue("%C2%A3");
assertThat(urlEncode("つ")).hasValue("%E3%81%A4");
assertThat(urlEncode("äëïöüÿ")).hasValue("%C3%A4%C3%AB%C3%AF%C3%B6%C3%BC%C3%BF");
assertThat(urlEncode("ÄËÏÖÜŸ")).hasValue("%C3%84%C3%8B%C3%8F%C3%96%C3%9C%C5%B8");
}

@Test
public void urlEncode_whenUnicode_encodesOriginal() {
// EURO sign
Truth8.assertThat(urlEncode("\u20AC")).hasValue("%E2%82%AC");
assertThat(urlEncode("\u20AC")).hasValue("%E2%82%AC");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.common.truth.Truth8;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
Expand Down Expand Up @@ -153,7 +152,7 @@ public void setTrustAllCertificates_whenCliOptionEnabledAndCertIsInvalid_ignores
MockWebServer mockWebServer = startMockWebServerWithSsl();

HttpResponse response = httpClient.send(get(mockWebServer.url("/")).withEmptyHeaders().build());
Truth8.assertThat(response.bodyString()).hasValue("body");
assertThat(response.bodyString()).hasValue("body");

mockWebServer.shutdown();
}
Expand All @@ -168,7 +167,7 @@ public void setTrustAllCertificates_whenCliOptionEnabledAndCertIsInvalid_ignores
MockWebServer mockWebServer = startMockWebServerWithSsl();

HttpResponse response = httpClient.send(get(mockWebServer.url("/")).withEmptyHeaders().build());
Truth8.assertThat(response.bodyString()).hasValue("body");
assertThat(response.bodyString()).hasValue("body");

mockWebServer.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableListMultimap;
import com.google.common.truth.Truth8;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -116,7 +115,7 @@ public void get_whenRequestedHeaderExists_returnsRequestedHeader() {
.addHeader(com.google.common.net.HttpHeaders.CONTENT_TYPE, "text/html; charset=UTF-8")
.build();

Truth8.assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.ACCEPT)).hasValue("*/*");
assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.ACCEPT)).hasValue("*/*");
}

@Test
Expand All @@ -128,7 +127,7 @@ public void get_whenMultipleValuesExist_returnsFirstValue() {
.addHeader(com.google.common.net.HttpHeaders.ACCEPT, "text/html")
.build();

Truth8.assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.ACCEPT)).hasValue("*/*");
assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.ACCEPT)).hasValue("*/*");
}

@Test
Expand All @@ -140,7 +139,7 @@ public void get_whenRequestedHeaderDoesNotExist_returnsEmpty() {
.addHeader(com.google.common.net.HttpHeaders.ACCEPT, "text/html")
.build();

Truth8.assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.COOKIE)).isEmpty();
assertThat(httpHeaders.get(com.google.common.net.HttpHeaders.COOKIE)).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.common.truth.Truth8;
import com.google.protobuf.ByteString;
import okhttp3.HttpUrl;
import org.junit.Test;
Expand All @@ -43,7 +42,7 @@ public void bodyJson_whenValidResponseBody_returnsParsedJson() {
.setResponseUrl(TEST_URL)
.build();

Truth8.assertThat(httpResponse.bodyJson()).isPresent();
assertThat(httpResponse.bodyJson()).isPresent();
assertThat(httpResponse.bodyJson().get().isJsonObject()).isTrue();
assertThat(
httpResponse
Expand All @@ -64,7 +63,7 @@ public void bodyJson_whenEmptyResponseBody_returnsEmptyOptional() {
.setResponseUrl(TEST_URL)
.build();

Truth8.assertThat(httpResponse.bodyJson()).isEmpty();
assertThat(httpResponse.bodyJson()).isEmpty();
}

@Test
Expand All @@ -77,7 +76,7 @@ public void bodyJson_whenNonJsonResponseBody_returnsEmptyOptional() {
.setResponseUrl(TEST_URL)
.build();

Truth8.assertThat(httpResponse.bodyJson()).isEmpty();
assertThat(httpResponse.bodyJson()).isEmpty();
}

@Test
Expand Down Expand Up @@ -117,7 +116,7 @@ public void jsonFieldEqualsToValue_whenNonJsonResponseBody_returnsEmptyOptional(
.setResponseUrl(TEST_URL)
.build();

Truth8.assertThat(httpResponse.bodyJson()).isEmpty();
assertThat(httpResponse.bodyJson()).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.junit.Assert.assertThrows;

import com.google.common.net.MediaType;
import com.google.common.truth.Truth8;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
Expand Down Expand Up @@ -511,7 +510,7 @@ public void send_whenNotFollowRedirect_returnsFinalHttpResponse() throws IOExcep
.addHeader(CONTENT_LENGTH, "0")
.addHeader(LOCATION, RedirectDispatcher.REDIRECT_DESTINATION_PATH)
.build());
Truth8.assertThat(response.bodyString()).hasValue("");
assertThat(response.bodyString()).hasValue("");
assertThat(response)
.isEqualTo(
HttpResponse.builder()
Expand Down Expand Up @@ -550,7 +549,7 @@ public void sendAsync_whenNotFollowRedirect_returnsFinalHttpResponse()
.addHeader(CONTENT_LENGTH, "0")
.addHeader(LOCATION, RedirectDispatcher.REDIRECT_DESTINATION_PATH)
.build());
Truth8.assertThat(response.bodyString()).hasValue("");
assertThat(response.bodyString()).hasValue("");
assertThat(response)
.isEqualTo(
HttpResponse.builder()
Expand Down Expand Up @@ -667,7 +666,7 @@ protected void configure() {
httpClient.send(
get(String.format("https://%s:%d", host, port)).withEmptyHeaders().build(),
networkService);
Truth8.assertThat(response.bodyString()).hasValue("body");
assertThat(response.bodyString()).hasValue("body");

mockWebServer.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.common.base.Stopwatch;
import com.google.common.testing.FakeTicker;
import com.google.common.truth.Truth8;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.tsunami.plugin.PluginExecutor.PluginExecutorConfig;
Expand Down Expand Up @@ -61,10 +60,10 @@ public void executeAsync_whenSucceeded_returnsSucceededResult()
.executeAsync(executorConfig)
.get();

Truth8.assertThat(executionResult.exception()).isEmpty();
assertThat(executionResult.exception()).isEmpty();
assertThat(executionResult.isSucceeded()).isTrue();
assertThat(executionResult.executionStopwatch().elapsed()).isEqualTo(TICK_DURATION);
Truth8.assertThat(executionResult.resultData()).hasValue("result data");
assertThat(executionResult.resultData()).hasValue("result data");
}

@Test
Expand All @@ -84,12 +83,12 @@ public void executeAsync_whenFailedWithPluginExecutionException_returnsFailedRes
.executeAsync(executorConfig)
.get();

Truth8.assertThat(executionResult.exception()).isPresent();
assertThat(executionResult.exception()).isPresent();
assertThat(executionResult.exception().get()).hasCauseThat().isNull();
assertThat(executionResult.exception().get()).hasMessageThat().contains("test exception");
assertThat(executionResult.isSucceeded()).isFalse();
assertThat(executionResult.executionStopwatch().elapsed()).isEqualTo(TICK_DURATION);
Truth8.assertThat(executionResult.resultData()).isEmpty();
assertThat(executionResult.resultData()).isEmpty();
}

@Test
Expand All @@ -109,7 +108,7 @@ public void executeAsync_whenFailedWithUnknownException_returnsFailedResult()
.executeAsync(executorConfig)
.get();

Truth8.assertThat(executionResult.exception()).isPresent();
assertThat(executionResult.exception()).isPresent();
assertThat(executionResult.exception().get())
.hasCauseThat()
.isInstanceOf(RuntimeException.class);
Expand All @@ -119,6 +118,6 @@ public void executeAsync_whenFailedWithUnknownException_returnsFailedResult()
String.format("Plugin execution error on '%s'.", FAKE_MATCHING_RESULT.pluginId()));
assertThat(executionResult.isSucceeded()).isFalse();
assertThat(executionResult.executionStopwatch().elapsed()).isEqualTo(TICK_DURATION);
Truth8.assertThat(executionResult.resultData()).isEmpty();
assertThat(executionResult.resultData()).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.truth.Truth8;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.multibindings.MapBinder;
Expand Down Expand Up @@ -72,7 +71,7 @@ public void getPortScanners_whenMultiplePortScannersInstalled_returnsAllPortScan

ImmutableList<PluginMatchingResult<PortScanner>> portScanners = pluginManager.getPortScanners();

Truth8.assertThat(
assertThat(
portScanners.stream()
.map(pluginMatchingResult -> pluginMatchingResult.tsunamiPlugin().getClass()))
.containsExactly(FakePortScanner.class, FakePortScanner2.class);
Expand Down Expand Up @@ -104,7 +103,7 @@ public void getPortScanner_whenMultiplePortScannersInstalled_returnsTheFirstMatc
Optional<PluginMatchingResult<PortScanner>> firstMatchedPortScanner =
pluginManager.getPortScanner();

Truth8.assertThat(firstMatchedPortScanner).isPresent();
assertThat(firstMatchedPortScanner).isPresent();
assertThat(firstMatchedPortScanner.get().pluginDefinition())
.isEqualTo(allPortScanners.get(0).pluginDefinition());
assertThat(firstMatchedPortScanner.get().tsunamiPlugin().getClass())
Expand All @@ -119,7 +118,7 @@ public void getPortScanner_whenNoPortScannersInstalled_returnsEmptyOptional() {
new FakeVulnDetectorBootstrapModule())
.getInstance(PluginManager.class);

Truth8.assertThat(pluginManager.getPortScanner()).isEmpty();
assertThat(pluginManager.getPortScanner()).isEmpty();
}

@Test
Expand All @@ -138,7 +137,7 @@ public void getServiceFingerprinter_whenFingerprinterNotAnnotated_returnsEmpty()
Optional<PluginMatchingResult<ServiceFingerprinter>> fingerprinter =
pluginManager.getServiceFingerprinter(httpService);

Truth8.assertThat(fingerprinter).isEmpty();
assertThat(fingerprinter).isEmpty();
}

@Test
Expand All @@ -157,7 +156,7 @@ public void getServiceFingerprinter_whenFingerprinterHasMatch_returnsMatch() {
Optional<PluginMatchingResult<ServiceFingerprinter>> fingerprinter =
pluginManager.getServiceFingerprinter(httpService);

Truth8.assertThat(fingerprinter).isPresent();
assertThat(fingerprinter).isPresent();
assertThat(fingerprinter.get().matchedServices()).containsExactly(httpService);
}

Expand All @@ -177,7 +176,7 @@ public void getServiceFingerprinter_whenNoFingerprinterMatches_returnsEmpty() {
Optional<PluginMatchingResult<ServiceFingerprinter>> fingerprinter =
pluginManager.getServiceFingerprinter(httpsService);

Truth8.assertThat(fingerprinter).isEmpty();
assertThat(fingerprinter).isEmpty();
}

@Test
Expand All @@ -200,11 +199,11 @@ public void getServiceFingerprinter_whenForWebServiceAnnotationAndWebService_ret

Optional<PluginMatchingResult<ServiceFingerprinter>> fingerprinter =
pluginManager.getServiceFingerprinter(httpsService);
Truth8.assertThat(fingerprinter).isPresent();
assertThat(fingerprinter).isPresent();
assertThat(fingerprinter.get().matchedServices()).containsExactly(httpsService);

fingerprinter = pluginManager.getServiceFingerprinter(httpProxyService);
Truth8.assertThat(fingerprinter).isPresent();
assertThat(fingerprinter).isPresent();
assertThat(fingerprinter.get().matchedServices()).containsExactly(httpProxyService);
}

Expand All @@ -226,8 +225,8 @@ public void getServiceFingerprinter_whenForWebServiceAnnotationAndNonWebService_
Guice.createInjector(new FakePortScannerBootstrapModule(), FakeWebFingerprinter.getModule())
.getInstance(PluginManager.class);

Truth8.assertThat(pluginManager.getServiceFingerprinter(sshService)).isEmpty();
Truth8.assertThat(pluginManager.getServiceFingerprinter(rdpService)).isEmpty();
assertThat(pluginManager.getServiceFingerprinter(sshService)).isEmpty();
assertThat(pluginManager.getServiceFingerprinter(rdpService)).isEmpty();
}

@Test
Expand Down Expand Up @@ -262,11 +261,11 @@ public void getServiceFingerprinter_whenForWebServiceAnnotationAndNonWebService_
ImmutableList<PluginMatchingResult<VulnDetector>> vulnDetectors =
pluginManager.getVulnDetectors(fakeReconnaissanceReport);

Truth8.assertThat(
assertThat(
vulnDetectors.stream()
.map(pluginMatchingResult -> pluginMatchingResult.tsunamiPlugin().getClass()))
.containsExactly(FakeVulnDetector.class, FakeVulnDetector2.class);
Truth8.assertThat(vulnDetectors.stream().map(PluginMatchingResult::matchedServices))
assertThat(vulnDetectors.stream().map(PluginMatchingResult::matchedServices))
.containsExactly(
fakeReconnaissanceReport.getNetworkServicesList(),
fakeReconnaissanceReport.getNetworkServicesList());
Expand Down Expand Up @@ -471,7 +470,7 @@ public void getVulnDetectors_whenNoVulnDetectorsInstalled_returnsEmptyList() {
ImmutableList<PluginMatchingResult<VulnDetector>> remotePlugins =
pluginManager.getVulnDetectors(fakeReconnaissanceReport);

Truth8.assertThat(
assertThat(
remotePlugins.stream()
.map(pluginMatchingResult -> pluginMatchingResult.tsunamiPlugin().getClass()))
.containsExactly(FakeRemoteVulnDetector.class, FakeRemoteVulnDetector.class);
Expand Down
Loading

0 comments on commit cac9e76

Please sign in to comment.