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 testToSubscriptionNameValid() {
    SubscriptionName subscriptionName =
        toSubscriptionName(
            Subscription.newBuilder()
                .setName("projects/project-a/subscriptions/topic-x-sub0")
                .build());
    assertThat(subscriptionName.getProject()).isEqualTo("project-a");
    assertThat(subscriptionName.getSubscription()).isEqualTo("topic-x-sub0");
  }