GetDefinitions { public Map<PhysicalHostName, PhysicalHost> getPhysicalHost(){ fetchPhysicalHosts(); Map<PhysicalHostName, PhysicalHost> map = new HashMap<PhysicalHostName, PhysicalHost>(); if (physicalHostList!=null){ for (PhysicalHost physicalHost : physicalHostList){ map.put(physicalHost.getHostName(),physicalHost); } } return map; } GetDefinitions(DataBroker dataBroker); Map<NodeType, NodeDefinition> getNodeDefinition(); Map<MatchItemName, MatchItemDefinition> getMatchItemDefinition(); Map<ConnectionType, ConnectionDefinition> getConnectionDefinition(); Map<ActionName, ActionDefinition> getActionDefinition(); Map<ParameterName, ConditionParameterDefinition> getConditionParameterDefinition(); Map<PhysicalHostName, PhysicalHost> getPhysicalHost();  }
@Test public void testGetPhysicalHost() throws Exception { Map<PhysicalHostName, PhysicalHost> map1 = new HashMap<PhysicalHostName, PhysicalHost>(); PhysicalHostName physicalHostName = mock(PhysicalHostName.class); PhysicalHost physicalHost = mock(PhysicalHost.class); map1.put(physicalHostName,physicalHost); List<PhysicalHost> physicalHostList = new ArrayList<PhysicalHost>(); physicalHostList.add(physicalHost); Class<GetDefinitions> class_1 = GetDefinitions.class; Field field = class_1.getDeclaredField("physicalHostList"); field.setAccessible(true); field.set(getDefinitions, physicalHostList); CheckedFuture physicalHostsFuture = mock(CheckedFuture.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(physicalHostsFuture); when(physicalHost.getHostName()).thenReturn(physicalHostName); Assert.assertEquals(getDefinitions.getPhysicalHost(), map1); }