### Question:
RegistryConnection { public String getAddress(String name) { Location address = null; List<Location> locations = this.locationRegistry.getEntitiesWithTag(name); if (!locations.isEmpty()) { address = locations.get(0); } else { for (Location location : this.locationRegistry.getAll()) { if (name.equalsIgnoreCase(location.getName()) || name.equalsIgnoreCase(location.getTag())) { address = location; break; } } } if (address == null) { return name; } return address.getAddressString(); }  String getAddress(String name);  }### Answer:
@Test public void testGetAdressHome() { when(this.location.getAddressString()).thenReturn("Pforzheim"); when(this.registry.getEntitiesWithTag("Home")).thenReturn(Collections.singletonList(this.location)); assertThat(this.connection.getAddress("Home"), equalTo("Pforzheim")); }
@Test public void testGetAdressWork() { when(this.location.getAddressString()).thenReturn("Pforzheim"); when(this.registry.getEntitiesWithTag("Work")).thenReturn(Collections.singletonList(this.location)); assertThat(this.connection.getAddress("Work"), equalTo("Pforzheim")); }
@Test public void testGetAdressOther() { when(this.location.getAddressString()).thenReturn("Pforzheim"); when(this.location.getName()).thenReturn("friend"); List<Location> locations = new ArrayList<>(); locations.add(this.location2); locations.add(this.location); when(this.location2.getName()).thenReturn("other"); when(this.registry.getAll()).thenReturn(locations); assertThat(this.connection.getAddress("friend"), equalTo("Pforzheim")); }
@Test public void testGetAdressNotInRegistry() { when(this.location.getName()).thenReturn("friend"); List<Location> locations = new ArrayList<>(); locations.add(this.location2); locations.add(this.location); when(this.location2.getName()).thenReturn("other"); when(this.registry.getAll()).thenReturn(locations); assertThat(this.connection.getAddress("bla"), equalTo("bla")); }