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

Commit a1ea8d96 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Use assertExpectException in DPMS test.

Otherwise it is too easy to forget fail().

Change-Id: I0cd8eb46d621dd18f6face867680fd207a6a70ca
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
parent c7db8d79
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");
    }
}