### Question:
WebtopNamingSiteUtils { public Set<String> getSiteNodes(Session session) { String siteOrServerID = session.getID().getSessionServerID(); String siteID; if (query.isSite(siteOrServerID)) { siteID = siteOrServerID; } else { siteID = query.getSiteID(siteOrServerID); if (siteID == null) { return new HashSet<String>(Arrays.asList(siteOrServerID)); } } try { return query.getSiteNodes(siteID); } catch (Exception e) { String err = "Failed to find nodes for Site ID: " + siteOrServerID; debug.error(err, e); throw new IllegalStateException(err); } } @Inject  WebtopNamingSiteUtils(@Named(SessionConstants.SESSION_DEBUG) Debug debug, WebtopNamingQuery query); Set<String> getSiteNodes(Session session); Set<URL> getSiteNodeURLs(Session session);  }### Answer:
@Test (expectedExceptions = IllegalStateException.class) public void shouldReturnThrowRuntimeIfErrorQueryingWebtopNaming() throws Exception { String serverID = "SERVER"; String siteID = "SITE"; given(mockSessionID.getSessionServerID()).willReturn(serverID); given(mockQuery.getSiteID(eq(serverID))).willReturn(siteID); given(mockQuery.getSiteNodes(anyString())).willThrow(new Exception()); utils.getSiteNodes(mockSession); }
@Test public void shouldResolveServerToBePartOfSite() throws Exception { String serverID = "SERVER"; String siteID = "SITE"; given(mockSessionID.getSessionServerID()).willReturn(serverID); given(mockQuery.getSiteID(eq(serverID))).willReturn(siteID); utils.getSiteNodes(mockSession); verify(mockQuery).getSiteNodes(eq(siteID)); }
@Test public void shouldReturnServerIDIfServerNotInSite() { String serverID = "SERVER"; given(mockSessionID.getSessionServerID()).willReturn(serverID); given(mockQuery.getSiteID(eq(serverID))).willReturn(null); Set<String> result = utils.getSiteNodes(mockSession); result.contains(serverID); }