HostRegistryImpl implements HostRegistry { @Override public ResourceHostInfo getResourceHostByContainerHost( final ContainerHostInfo containerHostInfo ) throws HostDisconnectedException { Preconditions.checkNotNull( containerHostInfo, "Container host info is null" ); for ( ResourceHostInfo resourceHostInfo : hosts.asMap().values() ) { for ( ContainerHostInfo containerHostInfo1 : resourceHostInfo.getContainers() ) { if ( containerHostInfo.getId().equals( containerHostInfo1.getId() ) ) { return resourceHostInfo; } } } throw new HostDisconnectedException( "Host is not connected" ); }  @Override void updateResourceHostEntryTimestamp( final String resourceHostId ); @Override ContainerHostInfo getContainerHostInfoById( final String id ); @Override ContainerHostInfo getContainerHostInfoByHostname( final String hostname ); @Override ContainerHostInfo getContainerHostInfoByContainerName( final String containerName ); @Override Set<ContainerHostInfo> getContainerHostsInfo(); @Override ResourceHostInfo getResourceHostInfoById( final String id ); @Override ResourceHostInfo getResourceHostInfoByHostname( final String hostname ); @Override Set<ResourceHostInfo> getResourceHostsInfo(); @Override ResourceHostInfo getResourceHostByContainerHost( final ContainerHostInfo containerHostInfo ); @Override HostInfo getHostInfoById( final String hostId ); @Override void removeResourceHost( final String id ); @Override void addHostListener( final HostListener listener ); @Override void removeHostListener( final HostListener listener ); void init(); void dispose(); @Override boolean pingHost( String hostIp );  }
@Test public void testGetParentByChild() throws Exception { ResourceHostInfo existingHost = registry.getResourceHostByContainerHost( containerHostInfo ); assertNotNull( existingHost ); ContainerHostInfo containerHostInfo1 = mock( ContainerHostInfo.class ); when( containerHostInfo1.getId() ).thenReturn( UUID.randomUUID().toString() ); try { registry.getResourceHostByContainerHost( containerHostInfo1 ); fail( "Expected HostDisconnectedException" ); } catch ( HostDisconnectedException e ) { } }