Utils { public static Properties loadEnvironmentProperties(Map<String, String> env) { String scannerParams = env.get(SONARQUBE_SCANNER_PARAMS); Properties props = new Properties(); if (scannerParams != null) { try { JsonValue jsonValue = Json.parse(scannerParams); JsonObject jsonObject = jsonValue.asObject(); Iterator<Member> it = jsonObject.iterator(); while (it.hasNext()) { Member member = it.next(); String key = member.getName(); String value = member.getValue().asString(); props.put(key, value); } } catch (Exception e) { throw new IllegalStateException("Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable", e); } } return props; } private  Utils(); static Properties loadEnvironmentProperties(Map<String, String> env); static void deleteQuietly(Path f);  }
@Test public void shouldHandleNullParams() { assertThat(Utils.loadEnvironmentProperties(createSonarQubeScannerProps(null))).isEmpty(); }
@Test public void shouldHandleParams() { String props = "{\"sonar.login\" : \"admin\"}"; assertThat(Utils.loadEnvironmentProperties(createSonarQubeScannerProps(props))).containsExactly(entry("sonar.login", "admin")); }
@Test public void shouldHandleEmptyJsonInParams() { String props = "{}"; assertThat(Utils.loadEnvironmentProperties(createSonarQubeScannerProps(props))).isEmpty(); }
@Test public void shouldHandleJsonErrorsInParams() { String props = ""; exception.expect(IllegalStateException.class); exception.expectMessage("Failed to parse JSON"); assertThat(Utils.loadEnvironmentProperties(createSonarQubeScannerProps(props))).isEmpty(); }