### Question:
NamedTransformImageServlet extends SlingSafeMethodsServlet implements OptingServlet { @Override public final boolean accepts(final SlingHttpServletRequest request) { if (request == null) { return false; } final String suffix = request.getRequestPathInfo().getSuffix(); if (StringUtils.isBlank(suffix)) { return false; } final String transformName = PathInfoUtil.getFirstSuffixSegment(request); if (!this.namedImageTransformers.keySet().contains(transformName)) { return false; } final String lastSuffix = PathInfoUtil.getLastSuffixSegment(request); final Matcher matcher = lastSuffixPattern.matcher(lastSuffix); if (!matcher.matches()) { return false; } return true; }  @Override final boolean accepts(final SlingHttpServletRequest request); static final String NAME_IMAGE; static final String NAMED_IMAGE_FILENAME_PATTERN; static final String DEFAULT_FILENAME_PATTERN; static final String RT_LOCAL_SOCIAL_IMAGE; static final String RT_REMOTE_SOCIAL_IMAGE; }### Answer:
@Test public void testAccepts() { assertTrue(servlet.accepts(request)); assertFalse(servlet.accepts(null)); final RequestPathInfo rpi = Mockito.mock(RequestPathInfo.class); when(rpi.getSuffix()).thenReturn(null); when(request.getRequestPathInfo()).thenReturn(rpi); assertFalse(servlet.accepts(request)); }
@Test public void testAccepts_invalidNamedTransform() { MockSlingHttpServletRequest request = new MockSlingHttpServletRequest( "/path", "", "transform", "unknown/image.png", ""); final boolean result = servlet.accepts(request); assertFalse(result); }
@Test public void testAccepts_invalidLastSuffix() { MockSlingHttpServletRequest request = new MockSlingHttpServletRequest( "/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + new Random().nextInt() + "/foo", ""); final boolean result = servlet.accepts(request); assertFalse(result); }
@Test public void testAccepts_multipleTransforms() { final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest( "/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + NAMED_TRANSFORM_SMALL + "/image.png", ""); final boolean result = servlet.accepts(request); assertTrue(result); }