### Question:
DefaultApplicationIdBuilder implements ApplicationIdBuilder, StreamsExecutionEnvironmentAware { @Override public ApplicationId buildApplicationId(final TopologyMetadata metadata, final Conf streamsConfig) { var id = streamsConfig.getOptionalString("streams." + StreamsConfig.APPLICATION_ID_CONFIG); return id.map(ApplicationId::new).orElseGet(() -> new ApplicationId(normalize(build(metadata, environment)))); }  @Override void setExecutionEnvironment(final StreamsExecutionEnvironment environment); @Override ApplicationId buildApplicationId(final TopologyMetadata metadata, final Conf streamsConfig);  }### Answer:
@Test public void shouldReturnApplicationIdWhenConfigured() { final String applicationId = "user-defined-application-id"; TopologyMetadata metadata = getTopologyMetadata("dummy"); ApplicationId result = builderWithUserEnv.buildApplicationId( metadata, Conf.of("streams." + StreamsConfig.APPLICATION_ID_CONFIG, applicationId)); Assertions.assertEquals(applicationId, result.toString()); }
@Test public void shouldGenerateIdUsingNameAndVersionPrefixedGivenUserEnv() { TopologyMetadata metadata = getTopologyMetadata("dummy"); ApplicationId result = builderWithUserEnv.buildApplicationId( metadata, Conf.empty()); Assertions.assertEquals("test-dummy-1-0", result.toString()); }
@Test public void shouldGenerateIdUsingNameAndVersionNotPrefixedGivenInternalEnv() { TopologyMetadata metadata = getTopologyMetadata("dummy"); ApplicationId result = builderWithInternalEnv.buildApplicationId( metadata, Conf.empty()); Assertions.assertEquals("dummy-1-0", result.toString()); }
@Test public void shouldGenerateNormalizedIdUsingNameAndVersionWhenNoOneIsConfigured() { TopologyMetadata metadata = getTopologyMetadata("example.package.MyTopology"); ApplicationId result = builderWithUserEnv.buildApplicationId( metadata, Conf.empty()); Assertions.assertEquals("test-example-package-my-topology-1-0", result.toString()); }