Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions core/src/test/java/com/google/common/truth/ExpectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public void warnWhenExpectIsNotRule() {
public void bash() throws Exception {
Runnable task = () -> expect.that(3).isEqualTo(4);
List<Future<?>> results = new ArrayList<>();
ExecutorService executor = newFixedThreadPool(10);
for (int i = 0; i < 1000; i++) {
results.add(executor.submit(task));
try (ExecutorService executor = newFixedThreadPool(10)) {
for (int i = 0; i < 1000; i++) {
results.add(executor.submit(task));
}
}
executor.shutdown();
for (Future<?> result : results) {
result.get();
}
Expand All @@ -195,33 +195,33 @@ public void bash() throws Exception {

@Test
public void failWhenCallingThatAfterTest() {
ExecutorService executor = newSingleThreadExecutor();
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
assertThrows(IllegalStateException.class, () -> expect.that(3));
});
executor.shutdown();
try (ExecutorService executor = newSingleThreadExecutor()) {
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
assertThrows(IllegalStateException.class, () -> expect.that(3));
});
}
}

@Test
public void failWhenCallingFailingAssertionMethodAfterTest() {
ExecutorService executor = newSingleThreadExecutor();
/*
* We wouldn't expect people to do this exactly. The point is that, if someone were to call
* expect.that(3).isEqualTo(4), we would always either fail the test or throw an
* IllegalStateException, not record a "failure" that we never read.
*/
IntegerSubject expectThat3 = expect.that(3);
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
IllegalStateException expected =
assertThrows(IllegalStateException.class, () -> expectThat3.isEqualTo(4));
assertThat(expected).hasCauseThat().isInstanceOf(AssertionError.class);
});
executor.shutdown();
try (ExecutorService executor = newSingleThreadExecutor()) {
/*
* We wouldn't expect people to do this exactly. The point is that, if someone were to call
* expect.that(3).isEqualTo(4), we would always either fail the test or throw an
* IllegalStateException, not record a "failure" that we never read.
*/
IntegerSubject expectThat3 = expect.that(3);
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
IllegalStateException expected =
assertThrows(IllegalStateException.class, () -> expectThat3.isEqualTo(4));
assertThat(expected).hasCauseThat().isInstanceOf(AssertionError.class);
});
}
}
}
Loading