static SubscriptionName toSubscriptionName(Subscription subscription) {
    Matcher matcher = SUBSCRIPTIONS_PATTERN.matcher(subscription.getName());
    checkArgument(
        matcher.find(),
        "Subscription name must be in the format"
            + " 'projects/{project_id}/subscriptions/{subscription_name}.");

    @SuppressWarnings("nullness")
    SubscriptionName subscriptionName =
        SubscriptionName.of(matcher.group("projectId"), matcher.group("subscriptionName"));
    return subscriptionName;
  }
@Test
  public void testToSubscriptionNameInvalidShouldFail() {
    assertThrows(
        IllegalArgumentException.class,
        () ->
            toSubscriptionName(
                Subscription.newBuilder().setName("project-a.topic-x-sub0").build()));
  }