Skip to content

Commit

Permalink
Fix test interference (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka authored and dflemstr committed Mar 3, 2019
1 parent f014a40 commit eb2acdf
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a stage that was interrupted"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,20 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a future that was interrupted"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

@Test
public void testCancelledMismatchFormatting() throws Exception {
final SettableFuture<Void> future = SettableFuture.create();

try {
// Cancel the future
future.cancel(true);
final StringDescription description = new StringDescription();
SUT.describeMismatch(future, description);
// Cancel the future
future.cancel(true);
final StringDescription description = new StringDescription();
SUT.describeMismatch(future, description);

assertThat(description.toString(), is("a future that was cancelled"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
}
assertThat(description.toString(), is("a future that was cancelled"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a stage that was not completed"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a future that was not done"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a stage that was interrupted"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a future that was interrupted"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a stage that was not done"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.common.util.concurrent.SettableFuture;
import java.io.IOException;
import java.util.concurrent.Future;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.Test;
Expand Down Expand Up @@ -71,8 +70,8 @@ public void testInterruptedMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a future that was not completed"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand All @@ -88,8 +87,8 @@ public void testCancelledMismatchFormatting() throws Exception {

assertThat(description.toString(), is("a future that was cancelled"));
} finally {
// This will cause the future's thread to throw InterruptedException and make it return
future.cancel(true);
// Clear the interrupted flag to avoid interference between tests
Thread.interrupted();
}
}

Expand Down

0 comments on commit eb2acdf

Please sign in to comment.