LoadUserArtifactsCommand extends AbstractCommand { protected ObjectNode replaceLanguageWithLang(ObjectNode object) { ObjectNode newObject = objectMapper.createObjectNode(); newObject.put("lang", object.get("language").asText()); Iterator<String> fieldNames = object.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); if (!"language".equals(fieldName)) { newObject.set(fieldName, object.get(fieldName)); } } return newObject; } LoadUserArtifactsCommand();  LoadUserArtifactsCommand(HubConfig hubConfig); void setForceLoad(boolean forceLoad); @Override void execute(CommandContext context); void setHubConfig(HubConfig hubConfig); void setObjectMapper(ObjectMapper objectMapper);  }
@Test public void replaceLanguageWithLang() { ObjectNode object = ObjectMapperFactory.getObjectMapper().createObjectNode(); object.put("language", "zxx"); object.put("something", "else"); object = loadUserArtifactsCommand.replaceLanguageWithLang(object); assertEquals("zxx", object.get("lang").asText()); assertEquals("else", object.get("something").asText()); assertFalse(object.has("language")); assertEquals("lang", object.fieldNames().next(), "lang should still be the first field name in the JSON object"); }