### Question:
ResourceUtility { public static Resource getBaseServerOrService(Resource resource) { if (resource == null) { throw new IllegalArgumentException("resource is null"); } Resource current, parent = resource; do { current = parent; parent = current.getParentResource(); } while (parent != null && parent.getResourceType().getCategory() != PLATFORM); return current; } private  ResourceUtility(); static Resource getChildResource(Resource parent, ResourceType type, String key); @NotNull static Set<Resource> getChildResources(Resource parentResource,
                                                  ResourceFilter filter); static Resource getBaseServerOrService(Resource resource); static Resource getAncestorResourceOfType(Resource resource, String parentType); static boolean isAncestor(Resource resource, Resource possibleAncestor);  }### Answer:
@Test(expectedExceptions = { IllegalArgumentException.class }) public void getBaseServerOrServiceShouldThrowIllegalArgumentExceptionOnNull() throws Exception { getBaseServerOrService(null); }
@Test public void getBaseServerOrServiceOfPlatform() throws Exception { Resource platform = new Resource(); platform.setResourceType(TEST_PLATFORM_TYPE); assertSame(platform, getBaseServerOrService(platform)); }
@Test public void getBaseServerOrServiceOfTopLevelServer() throws Exception { Resource topLevelServer = new Resource(); topLevelServer.setResourceType(TEST_TOP_LEVEL_SERVER_TYPE); assertSame(topLevelServer, getBaseServerOrService(topLevelServer)); }
@Test public void getBaseServerOrServiceOfTopLevelService() throws Exception { Resource topLevelService = new Resource(); topLevelService.setResourceType(new ResourceType("test topLevelService", "test plugin", SERVICE, null)); assertSame(topLevelService, getBaseServerOrService(topLevelService)); }
@Test public void getBaseServerOrServiceOfNestedService() throws Exception { ResourceType testServiceType = new ResourceType("test service", "test plugin", SERVICE, TEST_TOP_LEVEL_SERVER_TYPE); Resource service = new Resource(); service.setResourceType(testServiceType); Resource topLevelServer = new Resource(); topLevelServer.setResourceType(TEST_TOP_LEVEL_SERVER_TYPE); topLevelServer.addChildResource(service); Resource platform = new Resource(); platform.setResourceType(TEST_PLATFORM_TYPE); platform.addChildResource(topLevelServer); assertSame(topLevelServer, getBaseServerOrService(service)); }