'Junit5: Equivalent of @Rule and Expect

I have some code which I have written in old version of jUnit. Now I am trying to migrate.

How to write this in Junit5?

 @Test
  public void testSignatureFailureRuntimeException() throws Exception {
    thrown.expect(java.lang.IllegalArgumentException.class);
    HmacUtil hmacUtil = new HmacUtil(HmacUtil.SignatureAlgorithm.HMAC_SHA1, "");
  }
  @Test
  public void testDeploymentInfoWithEmptyConfig() {
    thrown.expect(NullPointerException.class);
    deploymentId = UUID.randomUUID().toString();
    FunctionDeploymentInfo.FunctionDeploymentInfoBuilder builder = FunctionDeploymentInfo.builder();
    FunctionDeploymentInfo fdi = builder
      .withDeploymentId(deploymentId)
      .withFulfilledBy(this.getClass().getName())
      .forPodTag(MicrodoseConstants.ONE_DATA)
      .withConfig(new JsonObject())
      .build();

    LocalMap<String, FunctionDeploymentInfo> deploymentInfo = vertx.sharedData().getLocalMap(deploymentInfoKey);
    deploymentInfo.clear();
    LocalMap<String, String> addressIndex = vertx.sharedData().getLocalMap(addressIndexKey);
    addressIndex.clear();

    fdi.registerDeploymentInfo(addressIndex, deploymentInfo);
  }

And another is @Rule


@ExtendWith(VertxExtension.class)
public class FunctionDeploymentInfoTest {

  @Rule
  public ExpectedException thrown = ExpectedException.none();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source