Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 247655269
  • Loading branch information
cpovirk authored and copybara-github committed May 10, 2019
1 parent c76eb21 commit afe84d0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ void assertException(String msg, FileChannel file, long off, long len, int maxAl
msg + " - no exception",
Exception.class,
() -> new BufferedFile(file, off, len, maxAlloc));
assertWithMessage(msg + " - exception, ").that(expect).isSameAs(ex.getClass());
assertWithMessage(msg + " - exception, ").that(expect).isSameInstanceAs(ex.getClass());
}

void assertException(String msg, BufferedFile instance, long off, int len, Class<?> expect) {
Exception ex =
assertThrows(msg + " - no exception", Exception.class, () -> instance.getBuffer(off, len));
assertWithMessage(msg + " - exception, ").that(expect).isSameAs(ex.getClass());
assertWithMessage(msg + " - exception, ").that(expect).isSameInstanceAs(ex.getClass());
}

void assertCase(String msg, BufferedFile instance, long off, int len, int expectLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testEndOfCentralDirectory_notPresent() throws Exception {
() -> zipIn.endOfCentralDirectory());
assertWithMessage(subcase + "caught exception")
.that(ex.getClass())
.isSameAs(IllegalStateException.class);
.isSameInstanceAs(IllegalStateException.class);
}

@Test
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testEndOfCentralDirectory_tooLateToRead() throws Exception {
() -> zipIn.endOfCentralDirectory());
assertWithMessage(subcase + "caught exception")
.that(ex.getClass())
.isSameAs(IndexOutOfBoundsException.class);
.isSameInstanceAs(IndexOutOfBoundsException.class);
}

@Test
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testEndOfCentralDirectory_goodHidenByBad() throws Exception {
() -> zipIn.endOfCentralDirectory());
assertWithMessage(subcase + "caught exception")
.that(ex.getClass())
.isSameAs(IndexOutOfBoundsException.class);
.isSameInstanceAs(IndexOutOfBoundsException.class);
}

@Test
Expand All @@ -190,7 +190,7 @@ public void testEndOfCentralDirectory_truncatedComment() throws Exception {
() -> zipIn.endOfCentralDirectory());
assertWithMessage(subcase + "caught exception")
.that(ex.getClass())
.isSameAs(IllegalArgumentException.class);
.isSameInstanceAs(IllegalArgumentException.class);
}

@Test
Expand Down Expand Up @@ -340,7 +340,7 @@ public void testScanEntries() throws Exception {
public void handle(
ZipIn in, LocalFileHeader header, DirectoryEntry dirEntry, ByteBuffer data)
throws IOException {
assertThat(in).isSameAs(zipIn);
assertThat(in).isSameInstanceAs(zipIn);
String filename = "pkg/f" + count + ".class";
assertThat(header.getFilename()).isEqualTo(filename);
assertThat(dirEntry.getFilename()).isEqualTo(filename);
Expand Down Expand Up @@ -578,7 +578,7 @@ public void testEntryWith() throws Exception {
if (header != null) {
ZipEntry zipEntry = zipIn.entryWith(header);
assertThat(zipEntry.getDirEntry()).isNotNull();
assertThat(zipEntry.getHeader()).isSameAs(header);
assertThat(zipEntry.getHeader()).isSameInstanceAs(header);
assertThat(zipEntry.getHeader().getFilename()).isEqualTo(name);
assertThat(zipEntry.getDirEntry().getFilename()).isEqualTo(name);
assertThat(header.getFilename()).isEqualTo(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,30 @@ private void setupRoots() {
@Test
public void testGetSourceArtifactYieldsSameArtifact() throws Exception {
assertThat(artifactFactory.getSourceArtifact(fooRelative, clientRoot))
.isSameAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
.isSameInstanceAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
}

@Test
public void testGetSourceArtifactUnnormalized() throws Exception {
assertThat(
artifactFactory.getSourceArtifact(
PathFragment.create("foo/./foosource.txt"), clientRoot))
.isSameAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
.isSameInstanceAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
}

@Test
public void testResolveArtifact_noDerived_simpleSource() throws Exception {
assertThat(artifactFactory.resolveSourceArtifact(fooRelative, MAIN))
.isSameAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
.isSameInstanceAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
assertThat(artifactFactory.resolveSourceArtifact(barRelative, MAIN))
.isSameAs(artifactFactory.getSourceArtifact(barRelative, clientRoRoot));
.isSameInstanceAs(artifactFactory.getSourceArtifact(barRelative, clientRoRoot));
}

@Test
public void testResolveArtifact_inExternalRepo() throws Exception {
Artifact a1 = artifactFactory.getSourceArtifact(alienRelative, alienRoot);
Artifact a2 = artifactFactory.resolveSourceArtifact(alienRelative, MAIN);
assertThat(a1).isSameAs(a2);
assertThat(a1).isSameInstanceAs(a2);
}

@Test
Expand All @@ -154,9 +154,10 @@ public void testResolveArtifact_noDerived_derivedRoot() throws Exception {
@Test
public void testResolveArtifact_noDerived_simpleSource_other() throws Exception {
Artifact actual = artifactFactory.resolveSourceArtifact(fooRelative, MAIN);
assertThat(actual).isSameAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
assertThat(actual).isSameInstanceAs(artifactFactory.getSourceArtifact(fooRelative, clientRoot));
actual = artifactFactory.resolveSourceArtifact(barRelative, MAIN);
assertThat(actual).isSameAs(artifactFactory.getSourceArtifact(barRelative, clientRoRoot));
assertThat(actual)
.isSameInstanceAs(artifactFactory.getSourceArtifact(barRelative, clientRoRoot));
}

@Test
Expand Down Expand Up @@ -231,8 +232,8 @@ public void testSetGeneratingActionIdempotenceNewActionGraph() throws Exception
Action action = new ActionsTestUtil.NullAction(NULL_ACTION_OWNER, a, b);
ActionConflictException e =
assertThrows(ActionConflictException.class, () -> actionGraph.registerAction(action));
assertThat(e.getArtifact()).isSameAs(a);
assertThat(actionGraph.getGeneratingAction(a)).isSameAs(originalAction);
assertThat(e.getArtifact()).isSameInstanceAs(a);
assertThat(actionGraph.getGeneratingAction(a)).isSameInstanceAs(originalAction);
}

private static class MockPackageRootResolver implements PackageRootResolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void simpleCounter() throws Exception {
CountingQueueVisitor counter = new CountingQueueVisitor();
counter.enqueue();
counter.awaitQuiescence(/*interruptWorkers=*/ false);
assertThat(counter.getCount()).isSameAs(10);
assertThat(counter.getCount()).isSameInstanceAs(10);
}

@Test
Expand Down Expand Up @@ -100,12 +100,12 @@ public void externalDepWithInterrupt() throws Exception {
public void callerOwnedPool() throws Exception {
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
assertThat(executor.getActiveCount()).isSameAs(0);
assertThat(executor.getActiveCount()).isSameInstanceAs(0);

CountingQueueVisitor counter = new CountingQueueVisitor(executor);
counter.enqueue();
counter.awaitQuiescence(/*interruptWorkers=*/ false);
assertThat(counter.getCount()).isSameAs(10);
assertThat(counter.getCount()).isSameInstanceAs(10);

executor.shutdown();
assertThat(executor.awaitTermination(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS))
Expand All @@ -118,7 +118,7 @@ public void doubleCounter() throws Exception {
counter.enqueue();
counter.enqueue();
counter.awaitQuiescence(/*interruptWorkers=*/ false);
assertThat(counter.getCount()).isSameAs(10);
assertThat(counter.getCount()).isSameInstanceAs(10);
}

@Test
Expand All @@ -136,7 +136,7 @@ public void run() {
// The exception from the worker thread should be re-thrown from the main thread.
Exception e =
assertThrows(Exception.class, () -> visitor.awaitQuiescence(/*interruptWorkers=*/ false));
assertThat(e).isSameAs(myException);
assertThat(e).isSameInstanceAs(myException);
}

// Regression test for "AbstractQueueVisitor loses track of jobs if thread allocation fails".
Expand Down Expand Up @@ -165,7 +165,7 @@ public void execute(Runnable command) {
Error expected =
assertThrows(Error.class, () -> counter.awaitQuiescence(/*interruptWorkers=*/ false));
assertThat(expected).hasMessageThat().isEqualTo("Could not create thread (fakeout)");
assertThat(counter.getCount()).isSameAs(5);
assertThat(counter.getCount()).isSameInstanceAs(5);

executor.shutdown();
assertThat(executor.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
Expand Down Expand Up @@ -354,7 +354,7 @@ private static void assertFailFast(
if (interrupt) {
assertThat(e).isInstanceOf(InterruptedException.class);
} else {
assertThat(e).isSameAs(THROWABLE);
assertThat(e).isSameInstanceAs(THROWABLE);
}
assertWithMessage("got: " + visitedList + "\nwant: " + Arrays.toString(expectedVisited))
.that(Sets.newHashSet(visitedList))
Expand Down Expand Up @@ -399,7 +399,7 @@ public void run() {

Exception e =
assertThrows(Exception.class, () -> visitor.awaitQuiescence(/*interruptWorkers=*/ true));
assertThat(e).isSameAs(THROWABLE);
assertThat(e).isSameInstanceAs(THROWABLE);

assertThat(wasInterrupted.get()).isTrue();
assertThat(executor.isShutdown()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected byte[] getFastDigest(Path path) throws IOException {
path.getParentDirectory().createDirectoryAndParents();
FileSystemUtils.writeContentAsLatin1(path, "content");
IOException e = assertThrows(IOException.class, () -> createShareable(path));
assertThat(e).isSameAs(exception);
assertThat(e).isSameInstanceAs(exception);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void testSerializePropagatesSerializationExceptionFromCustomCodec() throw
.serialize(any(SerializationContext.class), eq(original), any(CodedOutputStream.class));
SerializationException e =
assertThrows(SerializationException.class, () -> underTest.serialize(original));
assertThat(e).isSameAs(staged);
assertThat(e).isSameInstanceAs(staged);
}

@Test
Expand All @@ -152,7 +152,7 @@ public void testSerializePropagatesIOExceptionFromCustomCodecsAsSerializationExc
.serialize(any(SerializationContext.class), eq(original), any(CodedOutputStream.class));
SerializationException e =
assertThrows(SerializationException.class, () -> underTest.serialize(original));
assertThat(e).hasCauseThat().isSameAs(staged);
assertThat(e).hasCauseThat().isSameInstanceAs(staged);
}

@Test
Expand All @@ -164,7 +164,7 @@ public void testDeserializePropagatesSerializationExceptionFromCustomCodec() thr
SerializationException thrown =
assertThrows(
SerializationException.class, () -> underTest.deserialize(underTest.serialize(1)));
assertThat(thrown).isSameAs(staged);
assertThat(thrown).isSameInstanceAs(staged);
}

@Test
Expand All @@ -177,7 +177,7 @@ public void testDeserializePropagatesIOExceptionFromCustomCodecAsSerializationEx
SerializationException e =
assertThrows(
SerializationException.class, () -> underTest.deserialize(underTest.serialize(1)));
assertThat(e).hasCauseThat().isSameAs(staged);
assertThat(e).hasCauseThat().isSameInstanceAs(staged);
}

@Test
Expand Down

0 comments on commit afe84d0

Please sign in to comment.