### Question:
BeanstalkResource extends ResourceProvider { @Override public Attributes getAttributes() { File configFile = new File(configPath); if (!configFile.exists()) { return Attributes.empty(); } Attributes.Builder attrBuilders = Attributes.newBuilder(); try (JsonParser parser = JSON_FACTORY.createParser(configFile)) { parser.nextToken(); if (!parser.isExpectedStartObjectToken()) { logger.log(Level.WARNING, "Invalid Beanstalk config: ", configPath); return attrBuilders.build(); } while (parser.nextToken() != JsonToken.END_OBJECT) { parser.nextValue(); String value = parser.getText(); switch (parser.getCurrentName()) { case DEVELOPMENT_ID: attrBuilders.setAttribute(ResourceAttributes.SERVICE_INSTANCE, value); break; case VERSION_LABEL: attrBuilders.setAttribute(ResourceAttributes.SERVICE_VERSION, value); break; case ENVIRONMENT_NAME: attrBuilders.setAttribute(ResourceAttributes.SERVICE_NAMESPACE, value); break; default: parser.skipChildren(); } } } catch (IOException e) { logger.log(Level.WARNING, "Could not parse Beanstalk config.", e); return Attributes.empty(); } attrBuilders.setAttribute( ResourceAttributes.CLOUD_PROVIDER, AwsResourceConstants.cloudProvider()); return attrBuilders.build(); } BeanstalkResource(); @VisibleForTesting  BeanstalkResource(String configPath); @Override Attributes getAttributes();  }### Answer:
@Test void testCreateAttributes(@TempDir File tempFolder) throws IOException { File file = new File(tempFolder, "beanstalk.config"); String content = "{\"noise\": \"noise\", \"deployment_id\":4,\"" + "version_label\":\"2\",\"environment_name\":\"HttpSubscriber-env\"}"; Files.write(content.getBytes(Charsets.UTF_8), file); BeanstalkResource populator = new BeanstalkResource(file.getPath()); Attributes attributes = populator.getAttributes(); assertThat(attributes) .isEqualTo( Attributes.of( ResourceAttributes.CLOUD_PROVIDER, "aws", ResourceAttributes.SERVICE_INSTANCE, "4", ResourceAttributes.SERVICE_VERSION, "2", ResourceAttributes.SERVICE_NAMESPACE, "HttpSubscriber-env")); }
@Test void testConfigFileMissing() { BeanstalkResource populator = new BeanstalkResource("a_file_never_existing"); Attributes attributes = populator.getAttributes(); assertThat(attributes.isEmpty()).isTrue(); }
@Test void testBadConfigFile(@TempDir File tempFolder) throws IOException { File file = new File(tempFolder, "beanstalk.config"); String content = "\"deployment_id\":4,\"version_label\":\"2\",\"" + "environment_name\":\"HttpSubscriber-env\"}"; Files.write(content.getBytes(Charsets.UTF_8), file); BeanstalkResource populator = new BeanstalkResource(file.getPath()); Attributes attributes = populator.getAttributes(); assertThat(attributes.isEmpty()).isTrue(); }