### Question:
GcpNetworkInterfaceProvider { Map<String, Optional<NetworkInterface>> provide(AuthenticatedContext authenticatedContext, List<CloudResource> instances) { String instanceNamePrefix = getInstanceNamePrefix(instances); List<Instance> gcpInstances = getInstances(authenticatedContext, instanceNamePrefix); return getNetworkMap(gcpInstances, instances); }  List<Instance> getInstances(AuthenticatedContext authenticatedContext, String instanceNamePrefix);  }### Answer:
@Test public void testProvideShouldReturnsTheNetworkInterfaces() throws IOException { InstanceList gcpInstancesFirstPage = createGcpInstancesFirstPage(); InstanceList gcpInstancesSecondPage = createGcpInstancesSecondPage(); InstanceList gcpInstancesThirdPage = createGcpInstancesThirdPage(); when(computeInstancesMock.execute()) .thenReturn(gcpInstancesFirstPage) .thenReturn(gcpInstancesSecondPage) .thenReturn(gcpInstancesThirdPage); Map<String, Optional<NetworkInterface>> actual = underTest.provide(authenticatedContext, instances); assertEquals(3, actual.size()); assertEquals(actual.get(INSTANCE_NAME_1), getNetworkForInstance(gcpInstancesFirstPage, INSTANCE_NAME_1)); assertEquals(actual.get(INSTANCE_NAME_2), getNetworkForInstance(gcpInstancesSecondPage, INSTANCE_NAME_2)); assertEquals(actual.get(INSTANCE_NAME_3), getNetworkForInstance(gcpInstancesThirdPage, INSTANCE_NAME_3)); }
@Test public void testProvideShouldReturnsMapWithoutNetworkWhenTheThereAreMissingNodes() throws IOException { InstanceList gcpInstances = createGcpInstancesWithMissingNode(); when(computeInstancesMock.execute()).thenReturn(gcpInstances); Map<String, Optional<NetworkInterface>> actual = underTest.provide(authenticatedContext, instances); assertEquals(3, actual.size()); assertEquals(actual.get(INSTANCE_NAME_1), getNetworkForInstance(gcpInstances, INSTANCE_NAME_1)); assertEquals(actual.get(INSTANCE_NAME_2), getNetworkForInstance(gcpInstances, INSTANCE_NAME_2)); assertEquals(actual.get(INSTANCE_NAME_3), getNetworkForInstance(gcpInstances, INSTANCE_NAME_3)); }
@Test public void testProvideShouldReturnsMapWithoutNetworkWhenTheThereAreNoResponseFromGcp() throws IOException { when(computeInstancesMock.execute()).thenReturn(new InstanceList()); Map<String, Optional<NetworkInterface>> actual = underTest.provide(authenticatedContext, instances); assertEquals(3, actual.size()); assertFalse(actual.get(INSTANCE_NAME_1).isPresent()); assertFalse(actual.get(INSTANCE_NAME_2).isPresent()); assertFalse(actual.get(INSTANCE_NAME_3).isPresent()); }
@Test public void testProvideShouldReturnsMapWithoutNetworkWhenTheGcpThrowsException() throws IOException { when(computeInstancesMock.execute()).thenThrow(new IOException("Error happened on GCP side.")); Map<String, Optional<NetworkInterface>> actual = underTest.provide(authenticatedContext, instances); assertEquals(3, actual.size()); assertFalse(actual.get(INSTANCE_NAME_1).isPresent()); assertFalse(actual.get(INSTANCE_NAME_2).isPresent()); assertFalse(actual.get(INSTANCE_NAME_3).isPresent()); }