GoEnvironment { public boolean hasAWSUseIamRole() { if (!has(AWS_USE_IAM_ROLE)) { return false; } String useIamRoleValue = get(AWS_USE_IAM_ROLE); Boolean result = BooleanUtils.toBooleanObject(useIamRoleValue); if (result == null) { throw new IllegalArgumentException(getEnvInvalidFormatMessage(AWS_USE_IAM_ROLE, useIamRoleValue, validUseIamRoleValues.toString())); } else { return result.booleanValue(); } } GoEnvironment();  GoEnvironment(Map<String, String> defaultEnvironment); GoEnvironment putAll(Map<String, String> existing); Map<String,String> asMap(); String get(String name); String getOrElse(String name, String defaultValue); boolean has(String name); boolean isAbsent(String name); String traceBackUrl(); String triggeredUser(); String replaceVariables(String str); String artifactsLocationTemplate(); String artifactsLocationTemplate(String pipeline, String stageName, String jobName, String pipelineCounter, String stageCounter); boolean hasAWSUseIamRole();  }
@Test public void shouldGetHasAWSUseIamRoleTrueIfSetToTrue() { GoEnvironment sut = new GoEnvironment(mockEnvironmentVariables .with(AWS_USE_IAM_ROLE,"True") .build()); Boolean result = sut.hasAWSUseIamRole(); assertThat(result, is(Boolean.TRUE)); }
@Test public void shouldGetHasAWSUseIamRoleFalseIfSetToFalse() { GoEnvironment sut = new GoEnvironment(mockEnvironmentVariables .with(AWS_USE_IAM_ROLE,"False") .build()); Boolean result = sut.hasAWSUseIamRole(); assertThat(result, is(Boolean.FALSE)); }
@Test public void shouldThrowExceptionIfAWSUseIamRoleNotWithinExpectedValues() { GoEnvironment sut = new GoEnvironment(mockEnvironmentVariables .with(AWS_USE_IAM_ROLE,"blue") .build()); try { sut.hasAWSUseIamRole(); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals( "Unexpected value in AWS_USE_IAM_ROLE environment variable; was blue, " + "but expected one of the following [true, false, yes, no, on, off]", e.getMessage()); } }