Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2140583f authored by Pavel Grafov's avatar Pavel Grafov Committed by Android (Google) Code Review
Browse files

Merge "Use assertExpectException in DPMS test."

parents 68fce9e9 a1ea8d96
Loading
Loading
Loading
Loading
+149 −336

File changed.

Preview size limit exceeded, changes collapsed.

+8 −3
Original line number Diff line number Diff line
@@ -23,12 +23,14 @@ public class TestUtils {
    private TestUtils() {
    }

    public interface ExceptionRunnable {
        void run() throws Exception;
    }

    public static void assertExpectException(Class<? extends Throwable> expectedExceptionType,
            String expectedExceptionMessageRegex, Runnable r) {
            String expectedExceptionMessageRegex, ExceptionRunnable r) {
        try {
            r.run();
            Assert.fail("Expected exception type " + expectedExceptionType.getName()
                    + " was not thrown");
        } catch (Throwable e) {
            Assert.assertTrue(
                    "Expected exception type was " + expectedExceptionType.getName()
@@ -37,6 +39,9 @@ public class TestUtils {
            if (expectedExceptionMessageRegex != null) {
                MoreAsserts.assertContainsRegex(expectedExceptionMessageRegex, e.getMessage());
            }
            return; // Pass.
        }
        Assert.fail("Expected exception type " + expectedExceptionType.getName()
                + " was not thrown");
    }
}