### Question:
ApplicationIOProvider { public AwsResource getOutput(String name) { Optional<OutputDescription> optionalOutputDescription = applicationDetailSupplier.get() .outputDescriptions().stream() .filter(d -> d.name().equalsIgnoreCase(name)) .findFirst(); if (!optionalOutputDescription.isPresent()) { String outputs = applicationDetailSupplier.get().outputDescriptions().stream() .map(OutputDescription::name) .collect(Collectors.joining(",")); throw new IllegalArgumentException("no output by name: " + name + "; outputs: " + outputs); } OutputDescription desc = optionalOutputDescription.get(); String arn; if (desc.kinesisStreamsOutputDescription() != null) { arn = desc.kinesisStreamsOutputDescription().resourceARN(); } else if (desc.kinesisFirehoseOutputDescription() != null) { arn = desc.kinesisFirehoseOutputDescription().resourceARN(); } else if (desc.lambdaOutputDescription() != null) { arn = desc.lambdaOutputDescription().resourceARN(); } else { throw new IllegalStateException("Unknown destination for output named " + name); } return new AwsResource(arn); } ApplicationIOProvider(String applicationName);  ApplicationIOProvider(KinesisAnalyticsClient client, String applicationName); AwsResource getInput(); AwsResource getOutput(String name);  }### Answer:
@Test public void getOutput_GivenApplicationDetailSpecifyingMultipleOutputStreams_ShouldReturnOutputByName() { AwsResource expected = new AwsResource(streamArnPrefix + "foo"); configureOutputs( outputStreamDescription(expected), outputStreamDescription(new AwsResource(streamArnPrefix + "bar")) ); Assert.assertEquals(expected, wrapper.getOutput("foo")); }
@Test(expected = IllegalArgumentException.class) public void getOutput_GivenNameOfNonexistentOutput_ShouldThrow() { configureOutputs(OutputDescription.builder().name("asdf").build()); wrapper.getOutput("doesnotexist"); }
@Test public void getOutput_OnSecondInvocation_ShouldNotRequestApplicationDetail() { configureOutputs( outputStreamDescription(new AwsResource(streamArnPrefix + "foo")), outputStreamDescription(new AwsResource(streamArnPrefix + "bar")) ); wrapper.getOutput("foo"); Mockito.verify(client) .describeApplication(DescribeApplicationRequest.builder().applicationName(applicationName).build()); wrapper.getOutput("bar"); Mockito.verifyNoMoreInteractions(client); }
@Test public void getOutput_GivenFirehoseDestination_ShouldReturnFirehoseArn() { AwsResource firehose = new AwsResource( "arn:aws:firehose:us-east-1:123456789012:deliverystream/my-deliverystream" ); KinesisFirehoseOutputDescription firehoseOutputDescription = KinesisFirehoseOutputDescription.builder() .resourceARN(firehose.getArn()).build(); OutputDescription d = OutputDescription.builder().name(firehose.getResource()) .kinesisFirehoseOutputDescription(firehoseOutputDescription).build(); configureOutputs(d); Assert.assertEquals(firehose, wrapper.getOutput(firehose.getResource())); }
@Test public void getOutput_GivenLambdaDestination_ShouldReturnLambdaArn() { AwsResource lambda = new AwsResource( "arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords" ); LambdaOutputDescription lambdaOutputDescription = LambdaOutputDescription.builder() .resourceARN(lambda.getArn()).build(); OutputDescription d = OutputDescription.builder().name(lambda.getResource()) .lambdaOutputDescription(lambdaOutputDescription).build(); configureOutputs(d); Assert.assertEquals(lambda, wrapper.getOutput(lambda.getResource())); }
@Test(expected = IllegalStateException.class) public void getOutput_GivenUnknownDestination_ShouldThrow() { String name = "INTENTIONALLY_UNRESOLVABLE_OUTPUT_DESTNATION"; configureOutputs(OutputDescription.builder().name(name).build()); wrapper.getOutput(name); }