KioApplicationProviderImpl implements KioApplicationProvider { @Override public Optional<Application> apply(final EC2InstanceContext context) { return cache.getUnchecked(context); } KioApplicationProviderImpl(final KioOperations kioOperations); @Override Optional<Application> apply(final EC2InstanceContext context);  }
@Test public void testApplicationFound() throws Exception { when(ec2InstanceContextMock.getApplicationId()).thenReturn(Optional.of(INSTANCE_ID)); when(kioOperationsMock.getApplicationById(eq(INSTANCE_ID))).thenReturn(new Application()); final Optional<Application> result = kioApplicationProvider.apply(ec2InstanceContextMock); assertThat(result).isPresent(); verify(ec2InstanceContextMock).getApplicationId(); verify(kioOperationsMock).getApplicationById(eq(INSTANCE_ID)); }
@Test public void testApplicationNotFoundInKio() throws Exception { when(ec2InstanceContextMock.getApplicationId()).thenReturn(Optional.of(INSTANCE_ID)); when(kioOperationsMock.getApplicationById(eq(INSTANCE_ID))).thenReturn(null); final Optional<Application> result = kioApplicationProvider.apply(ec2InstanceContextMock); assertThat(result).isEmpty(); verify(ec2InstanceContextMock).getApplicationId(); verify(kioOperationsMock).getApplicationById(eq(INSTANCE_ID)); }
@Test public void testApplicationNotFoundExceptionInKio() throws Exception { when(ec2InstanceContextMock.getApplicationId()).thenReturn(Optional.of(INSTANCE_ID)); when(kioOperationsMock.getApplicationById(eq(INSTANCE_ID))).thenThrow(new NotFoundException()); final Optional<Application> result = kioApplicationProvider.apply(ec2InstanceContextMock); assertThat(result).isEmpty(); verify(ec2InstanceContextMock).getApplicationId(); verify(kioOperationsMock).getApplicationById(eq(INSTANCE_ID)); }
@Test public void testApplicationNotFound() throws Exception { when(ec2InstanceContextMock.getApplicationId()).thenReturn(Optional.empty()); final Optional<Application> result = kioApplicationProvider.apply(ec2InstanceContextMock); assertThat(result).isEmpty(); verify(ec2InstanceContextMock).getApplicationId(); }