Skip to content

Commit

Permalink
Adding hack alternative method for assertThrows() since it was never …
Browse files Browse the repository at this point in the history
…released in JUnit4 (google uses a snapshot internally).

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=197941045
  • Loading branch information
hagbard authored and ronshapiro committed May 25, 2018
1 parent ddd7b8f commit e05db74
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.flogger.LazyArgs.lazy;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;

import com.google.common.base.Supplier;
import com.google.common.flogger.backend.KeyValueHandler;
Expand Down Expand Up @@ -261,4 +261,14 @@ public void close() {
logRecords = null;
}
}

// Hack version of the JUnit 4.13 assertThrows() method that's not available everywhere.
private static void assertThrows(Class<? extends RuntimeException> err, Runnable fn) {
try {
fn.run();
fail("expected exception of type " + err.getName());
} catch (RuntimeException e) {
assertThat(e).isInstanceOf(err);
}
}
}

0 comments on commit e05db74

Please sign in to comment.