title: Junit5 in Android Studio: assertThrows and Java 8
body: <p>Upgrading to JUnit5, we faced a limitation:</p>
  
  <pre><code>@Test(expected = NullPointerException.class)
  </code></pre>
  
  <p>is no longer possible. We should use <em><code>org.junit.jupiter.api.Assertions.assertThrows</code></em> these days. Normally, it takes a <em>lambda</em>, and it works if we set</p>
  
  <pre><code>android.compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
  }
  </code></pre>
  
  <p>The problem is that we'd prefer to stay at Java 7 for the release build (it would require huge amount of testing to prove that all ancient devices that we still strive to support, work correctly with Java 8).</p>
  
  <p>Is there a clean way to set <code>sourceCompatibility</code> for unit test only in Android Studio?</p>