Add JUnit 4 TestRule for running tests with a specific target SDK

Refactors code to replace lots of custom code for testing behavior for
specific target SDK versions, whether it is try...finally... blocks or
methods using lambdas with a JUnit 4 TestRule.

As the tests were JUnit 3 that also required switching them from
extending TestCase to extending TestCaseWithRules which adds support
for JUnit 4 TestRules to TestCase.

This is preparation work for some follow up work on ObjectStreamClass.

Test: atest \ \ \ \ \ \ \
Bug: 109930347

Change-Id: I4ea11288eb344eaeb2e6cc9f3225748e518e1827
9 files changed