### Question:
JobNameConfiguration { public static void configureJobName(final PipelineOptions options, final String... parts) { try { options.as(ApplicationNameOptions.class).setAppName("JdbcAvroJob"); } catch (Exception e) { LOGGER.warn("Unable to configure ApplicationName", e); } if (options.getJobName() == null || "auto".equals(options.getJobName())) { final String randomPart = Integer.toHexString(ThreadLocalRandom.current().nextInt()); final String jobName = String.format( "dbeam-%s-%s", Arrays.stream(parts) .filter(p -> !Strings.isNullOrEmpty(p)) .map(JobNameConfiguration::normalizeString) .collect(Collectors.joining("-")), randomPart); options.setJobName(jobName); } }  static void configureJobName(final PipelineOptions options, final String... parts);  }### Answer:
@Test public void shouldConfigureJobName() { PipelineOptions pipelineOptions = PipelineOptionsFactory.create(); pipelineOptions.setJobName(null); JobNameConfiguration.configureJobName(pipelineOptions, "some_db", "some_table"); Assert.assertEquals( "JdbcAvroJob", pipelineOptions.as(ApplicationNameOptions.class).getAppName()); assertThat(pipelineOptions.getJobName(), startsWith("dbeam-somedb-sometable-")); }
@Test public void shouldConfigureJobNameWhenJobNameIsAuto() { PipelineOptions pipelineOptions = PipelineOptionsFactory.create(); pipelineOptions.setJobName("auto"); JobNameConfiguration.configureJobName(pipelineOptions, "some_db", "some_table"); Assert.assertEquals( "JdbcAvroJob", pipelineOptions.as(ApplicationNameOptions.class).getAppName()); assertThat(pipelineOptions.getJobName(), startsWith("dbeam-somedb-sometable-")); }
@Test public void shouldConfigureJobNameWithEmptyTableName() { PipelineOptions pipelineOptions = PipelineOptionsFactory.create(); pipelineOptions.setJobName(null); JobNameConfiguration.configureJobName(pipelineOptions, "some_db", null); Assert.assertEquals( "JdbcAvroJob", pipelineOptions.as(ApplicationNameOptions.class).getAppName()); assertThat(pipelineOptions.getJobName(), startsWith("dbeam-somedb-")); Assert.assertEquals(3, pipelineOptions.getJobName().split("-").length); }