Skip to content

Commit 5bc4cbf

Browse files
committed
Checkstyle fixes for Cloud Monitoring sample tests.
Changed to using Truth for assertions.
1 parent d1857b0 commit 5bc4cbf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

monitoring/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<groupId>com.jcabi</groupId>
5050
<artifactId>jcabi-matchers</artifactId>
5151
</dependency>
52+
<dependency>
53+
<groupId>com.google.truth</groupId>
54+
<artifactId>truth</artifactId>
55+
<version>0.28</version>
56+
<scope>test</scope>
57+
</dependency>
5258
</dependencies>
5359

5460
<build>

monitoring/src/test/java/CloudMonitoringAuthSampleTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,16 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import static com.jcabi.matchers.RegexMatchers.*;
18-
import static org.junit.Assert.*;
17+
import static com.google.common.truth.Truth.assertThat;
1918

2019
import org.junit.After;
2120
import org.junit.Before;
2221
import org.junit.Test;
2322

2423
import java.io.ByteArrayOutputStream;
2524
import java.io.PrintStream;
26-
import java.util.regex.Pattern;
2725

2826
/**
2927
* Tests the Cloud Monitoring auth sample.
@@ -51,15 +49,19 @@ public void tearDown() {
5149
@Test
5250
public void testUsage() throws Exception {
5351
CloudMonitoringAuthSample.main(new String[] { });
54-
assertEquals("Usage: CloudMonitoringAuthSample <project-name>\n", stderr.toString());
52+
assertThat(stderr.toString())
53+
.named("stderr")
54+
.isEqualTo("Usage: CloudMonitoringAuthSample <project-name>\n");
5555
}
5656

5757
@Test
5858
public void testListTimeSeries() throws Exception {
5959
CloudMonitoringAuthSample.main(new String[] { "cloud-samples-tests" });
6060
String out = stdout.toString();
61-
assertThat(out, containsPattern("Timeseries.list raw response:"));
62-
assertThat(out, containsPattern("\\{\\s*\"kind\" *: *\"cloudmonitoring#listTimeseriesResponse\","));
63-
assertThat(out, containsPattern(".*oldest.*"));
61+
assertThat(out).named("stdout").contains("Timeseries.list raw response:");
62+
assertThat(out)
63+
.named("stdout")
64+
.containsMatch("\\{\\s*\"kind\" *: *\"cloudmonitoring#listTimeseriesResponse\",");
65+
assertThat(out).named("stdout").containsMatch(".*oldest.*");
6466
}
6567
}

0 commit comments

Comments
 (0)