Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 436175027
  • Loading branch information
Googler authored and copybara-github committed Mar 21, 2022
1 parent f585783 commit ccbcefd
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.docgen;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
Expand Down Expand Up @@ -120,16 +121,24 @@ private void checkExpandMulti(String docs, String expected) {
"<a href=\"#common-definitions\">Common Definitions</a>");
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testRefNotFound() {
String docs = "<a href=\"${link foo.bar}\">bar</a>";
multiPageExpander.expand(docs);
assertThrows(
IllegalArgumentException.class,
() -> {
multiPageExpander.expand(docs);
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testIncorrectStaticPageHeadingLink() {
String docs = "<a href=\"${link common-definitions.label-expansion}\">Label Expansion</a>";
multiPageExpander.expand(docs);
assertThrows(
IllegalArgumentException.class,
() -> {
multiPageExpander.expand(docs);
});
}

@Test public void testRuleHeadingLink() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.google.devtools.build.lib.actions;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertThrows;

import com.google.devtools.build.lib.actions.ResourceSet.ResourceSetConverter;
import com.google.devtools.common.options.OptionsParsingException;
Expand Down Expand Up @@ -44,21 +44,18 @@ public void testConverterParsesExpectedFormat() throws Exception {
assertThat(resources.getLocalTestCount()).isEqualTo(Integer.MAX_VALUE);
}

@Test(expected = OptionsParsingException.class)
@Test
public void testConverterThrowsWhenGivenInsufficientInputs() throws Exception {
converter.convert("0,0,");
fail();
assertThrows(OptionsParsingException.class, () -> converter.convert("0,0,"));
}

@Test(expected = OptionsParsingException.class)
@Test
public void testConverterThrowsWhenGivenTooManyInputs() throws Exception {
converter.convert("0,0,0,");
fail();
assertThrows(OptionsParsingException.class, () -> converter.convert("0,0,0,"));
}

@Test(expected = OptionsParsingException.class)
@Test
public void testConverterThrowsWhenGivenNegativeInputs() throws Exception {
converter.convert("-1,0,0");
fail();
assertThrows(OptionsParsingException.class, () -> converter.convert("-1,0,0"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void testUpload() throws Exception {
}
}

@Test(expected = ConnectException.class, timeout = 30000)
@Test(timeout = 30000)
public void connectTimeout() throws Exception {
ServerChannel server = testServer.start(new ChannelInboundHandlerAdapter() {});
testServer.stop(server);
Expand All @@ -347,13 +347,15 @@ public void connectTimeout() throws Exception {
AuthAndTLSOptions authAndTlsOptions = Options.getDefaults(AuthAndTLSOptions.class);
HttpCacheClient blobStore =
createHttpBlobStore(server, /* timeoutSeconds= */ 1, credentials, authAndTlsOptions);
getFromFuture(
blobStore.downloadBlob(remoteActionExecutionContext, DIGEST, new ByteArrayOutputStream()));

fail("Exception expected");
assertThrows(
ConnectException.class,
() ->
getFromFuture(
blobStore.downloadBlob(
remoteActionExecutionContext, DIGEST, new ByteArrayOutputStream())));
}

@Test(expected = UploadTimeoutException.class, timeout = 30000)
@Test(timeout = 30000)
public void uploadTimeout() throws Exception {
ServerChannel server = null;
try {
Expand All @@ -372,16 +374,20 @@ protected void channelRead0(
HttpCacheClient blobStore =
createHttpBlobStore(server, /* timeoutSeconds= */ 1, credentials, authAndTlsOptions);
byte[] data = "File Contents".getBytes(Charsets.US_ASCII);
getFromFuture(
blobStore.uploadBlob(
remoteActionExecutionContext, DIGEST_UTIL.compute(data), ByteString.copyFrom(data)));
fail("Exception expected");
assertThrows(
UploadTimeoutException.class,
() ->
getFromFuture(
blobStore.uploadBlob(
remoteActionExecutionContext,
DIGEST_UTIL.compute(data),
ByteString.copyFrom(data))));
} finally {
testServer.stop(server);
}
}

@Test(expected = DownloadTimeoutException.class, timeout = 30000)
@Test(timeout = 30000)
public void downloadTimeout() throws Exception {
ServerChannel server = null;
try {
Expand All @@ -399,10 +405,12 @@ protected void channelRead0(
AuthAndTLSOptions authAndTlsOptions = Options.getDefaults(AuthAndTLSOptions.class);
HttpCacheClient blobStore =
createHttpBlobStore(server, /* timeoutSeconds= */ 1, credentials, authAndTlsOptions);
getFromFuture(
blobStore.downloadBlob(
remoteActionExecutionContext, DIGEST, new ByteArrayOutputStream()));
fail("Exception expected");
assertThrows(
DownloadTimeoutException.class,
() ->
getFromFuture(
blobStore.downloadBlob(
remoteActionExecutionContext, DIGEST, new ByteArrayOutputStream())));
} finally {
testServer.stop(server);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.util;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -147,24 +148,24 @@ public void testEnsureCapacity() throws Exception {
assertThat(list.get(last)).isEqualTo(last);
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testRemoveExceptionEmpty() throws Exception {
list.remove(0);
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(0));
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testRemoveExceptionFilled() throws Exception {
for (int i = 0; i < 15; i++) {
list.add(i);
}
list.remove(15);
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(15));
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testGetException() throws Exception {
for (int i = 0; i < 15; i++) {
list.add(i);
}
list.get(15);
assertThrows(IndexOutOfBoundsException.class, () -> list.get(15));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.devtools.coverageoutputgenerator.LcovMergerTestUtils.createLinesExecution2;
import static com.google.devtools.coverageoutputgenerator.LcovMergerTestUtils.createSourceFile1;
import static com.google.devtools.coverageoutputgenerator.LcovMergerTestUtils.createSourceFile2;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -158,14 +159,18 @@ public void testFilterSourcesNoFilter() throws Exception {
assertThat(filteredSources).containsExactly(validSource1, validSource2);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testFilterSourcesNullCoverage() {
Coverage.filterOutMatchingSources(null, ImmutableList.of());
assertThrows(
IllegalArgumentException.class,
() -> Coverage.filterOutMatchingSources(null, ImmutableList.of()));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testFilterSourcesNullRegex() {
Coverage.filterOutMatchingSources(new Coverage(), null);
assertThrows(
IllegalArgumentException.class,
() -> Coverage.filterOutMatchingSources(new Coverage(), null));
}

private List<String> getSourceFileNames(
Expand Down Expand Up @@ -195,14 +200,16 @@ public void testGetOnlyTheseSources() throws Exception {
.containsExactly("source/common/protobuf/utility.cc", "source/common/grpc/common.cc");
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testGetOnlyTheseSourcesNullCoverage() {
Coverage.getOnlyTheseSources(null, new HashSet<>());
assertThrows(
IllegalArgumentException.class, () -> Coverage.getOnlyTheseSources(null, new HashSet<>()));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testGetOnlyTheseSourcesNullSources() {
Coverage.getOnlyTheseSources(new Coverage(), null);
assertThrows(
IllegalArgumentException.class, () -> Coverage.getOnlyTheseSources(new Coverage(), null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.devtools.coverageoutputgenerator;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -79,46 +80,61 @@ public void parseFlagsTestReportsFileOutputFileMultipleFilterSources() {
assertThat(flags.filterSources()).containsExactly("first_filter", "second_filter");
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestCoverageDirAndReportsFile() {
LcovMergerFlags.parseFlags(
new String[] {"--reports_file=my_reports_file", "--coverage_dir=my_coverage_dir"});
assertThrows(
IllegalArgumentException.class,
() ->
LcovMergerFlags.parseFlags(
new String[] {"--reports_file=my_reports_file", "--coverage_dir=my_coverage_dir"}));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestEmptyFlags() {
LcovMergerFlags.parseFlags(new String[] {});
assertThrows(IllegalArgumentException.class, () -> LcovMergerFlags.parseFlags(new String[] {}));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestNoOutputFile() {
LcovMergerFlags.parseFlags(
new String[] {
"--reports_file=my_reports_file",
});
assertThrows(
IllegalArgumentException.class,
() ->
LcovMergerFlags.parseFlags(
new String[] {
"--reports_file=my_reports_file",
}));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestUnknownFlag() {
LcovMergerFlags.parseFlags(
new String[] {
"--fake_flag=my_reports_file",
});
assertThrows(
IllegalArgumentException.class,
() ->
LcovMergerFlags.parseFlags(
new String[] {
"--fake_flag=my_reports_file",
}));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestInvalidFlagValue() {
LcovMergerFlags.parseFlags(
new String[] {
"--reports_file", "--output_file=my_file",
});
assertThrows(
IllegalArgumentException.class,
() ->
LcovMergerFlags.parseFlags(
new String[] {
"--reports_file", "--output_file=my_file",
}));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void parseFlagsTestInvalidFlagValueWithoutDashes() {
LcovMergerFlags.parseFlags(
new String[] {
"reports_file", "--output_file=my_file",
});
assertThrows(
IllegalArgumentException.class,
() ->
LcovMergerFlags.parseFlags(
new String[] {
"reports_file", "--output_file=my_file",
}));
}
}

0 comments on commit ccbcefd

Please sign in to comment.