static TopicName toTopicName(Topic topic) {
    Matcher matcher = TOPICS_PATTERN.matcher(topic.getName());
    checkArgument(
        matcher.find(),
        "Topic name must be in the format 'projects/{project_id}/topics/{topic_name}.");

    @SuppressWarnings("nullness")
    TopicName topicName = TopicName.of(matcher.group("projectId"), matcher.group("topicName"));
    return topicName;
  }
@Test
  public void testToTopicNameValid() {
    TopicName topicName =
        toTopicName(Topic.newBuilder().setName("projects/project-a/topics/topic-x").build());
    assertThat(topicName.getProject()).isEqualTo("project-a");
    assertThat(topicName.getTopic()).isEqualTo("topic-x");
  }