### Question:
SlingshotUtil { public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; }  static String getUserId(final Resource resource); static String getContentPath(final Resource resource); static boolean isUser(final SlingHttpServletRequest request);  }### Answer:
@Test public void getUserId_deepPath() { Resource resource = context.resourceResolver().getResource("/content/slingshot/users/admin/hobby"); assertThat(SlingshotUtil.getUserId(resource), equalTo("admin")); }
@Test public void getUserId_exactPath() { Resource resource = context.resourceResolver().getResource("/content/slingshot/users/admin"); assertThat(SlingshotUtil.getUserId(resource), equalTo("admin")); }
@Test public void getUserId_noMatch() { Resource resource = context.resourceResolver().getResource("/content/slingshot/users"); assertThat(SlingshotUtil.getUserId(resource), nullValue()); }