### Question:
StackResponseHardwareInfoProvider implements ResponseProvider { @Override public StackV4Response providerEntriesToStackResponse(Stack stack, StackV4Response stackResponse) { Set<HardwareInfoGroupV4Response> hardwareInfoResponses = stack.getInstanceGroups().stream() .map(instanceGroup -> hardwareInfoGroupResponse(stack, instanceGroup)) .collect(Collectors.toSet()); stackResponse.setHardwareInfoGroups(hardwareInfoResponses); return stackResponse; }  @Override StackV4Response providerEntriesToStackResponse(Stack stack, StackV4Response stackResponse); @Override String type();  }### Answer:
@Test public void testProviderEntriesToStackResponseEmptyInstanceGroup() { Stack stack = new Stack(); stack.setInstanceGroups(emptySet()); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(0L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseWhenOneInstanceMetadataPresented() { when(hostGroupService.findHostGroupInClusterByName(anyLong(), anyString())).thenReturn(Optional.of(TestUtil.hostGroup())); Stack stack = TestUtil.stack(); stack.setInstanceGroups(Sets.newHashSet(TestUtil.instanceGroup(1L, InstanceGroupType.GATEWAY, TestUtil.gcpTemplate(1L)))); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(1L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseClusterNull() { Stack stack = new Stack(); InstanceMetaData instanceMetaData = new InstanceMetaData(); stack.setInstanceGroups(getInstanceGroups(instanceMetaData)); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(1L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseClusterNotNullButFQDNNull() { Stack stack = new Stack(); InstanceMetaData instanceMetaData = new InstanceMetaData(); stack.setInstanceGroups(getInstanceGroups(instanceMetaData)); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(1L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseClusterNotNullAndFQDNNotNull() { Stack stack = new Stack(); Cluster cluster = new Cluster(); cluster.setId(1L); stack.setCluster(cluster); InstanceMetaData instanceMetaData = new InstanceMetaData(); instanceMetaData.setId(1L); instanceMetaData.setDiscoveryFQDN("fqdn"); stack.setInstanceGroups(getInstanceGroups(instanceMetaData)); StackV4Response stackResponse = new StackV4Response(); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, stackResponse); Assert.assertEquals(1L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseMultipleInstanceGroup() { Stack stack = new Stack(); stack.setCluster(new Cluster()); Set<InstanceGroup> instanceGroups = getInstanceGroups(new InstanceMetaData()); instanceGroups.addAll(getInstanceGroups(new InstanceMetaData())); stack.setInstanceGroups(instanceGroups); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(2L, actual.getHardwareInfoGroups().size()); }
@Test public void testProviderEntriesToStackResponseConvertsResult() { Stack stack = new Stack(); Cluster cluster = new Cluster(); cluster.setId(1L); stack.setCluster(cluster); InstanceMetaData instanceMetaData = new InstanceMetaData(); instanceMetaData.setId(1L); instanceMetaData.setDiscoveryFQDN("fqdn"); stack.setInstanceGroups(getInstanceGroups(instanceMetaData)); StackV4Response actual = underTest.providerEntriesToStackResponse(stack, new StackV4Response()); Assert.assertEquals(1L, actual.getHardwareInfoGroups().size()); }