### Question:
JCaptchaInternalScriptService implements ScriptService { public String getURL(String type, String engine, Map<String, Object> params) { if (StringUtils.isEmpty(type) || StringUtils.isEmpty(engine)) { return null; } JCaptchaResourceReference resourceReference = new JCaptchaResourceReference(type, engine); if (params != null) { for (Map.Entry<String, Object> parameterEntry : params.entrySet()) { resourceReference.addParameter(parameterEntry.getKey(), parameterEntry.getValue()); } } ExtendedURL extendedURL; try { extendedURL = this.defaultResourceReferenceSerializer.serialize(resourceReference); } catch (SerializeResourceReferenceException | UnsupportedResourceReferenceException e) { this.logger.warn("Error while serializing JCaptcha URL for type [{}], engine = [{}]. Root cause = [{}]", type, engine, ExceptionUtils.getRootCauseMessage(e)); return null; } return extendedURL.serialize(); }  String getURL(String type, String engine, Map<String, Object> params);  }### Answer:
@Test public void getURL() throws UnsupportedResourceReferenceException, SerializeResourceReferenceException { ExtendedURL extendedURL = mock(ExtendedURL.class); when(serializer.serialize(any())).thenReturn(extendedURL); this.scriptService.getURL("myType", "myEngine", Collections.singletonMap("customParam", "customValue")); JCaptchaResourceReference jCaptchaResourceReference = new JCaptchaResourceReference("myType", "myEngine"); jCaptchaResourceReference.addParameter("customParam", "customValue"); verify(serializer, times(1)).serialize(jCaptchaResourceReference); verify(extendedURL, times(1)).serialize(); }
@Test public void getURLSerializerError() throws UnsupportedResourceReferenceException, SerializeResourceReferenceException { when(serializer.serialize(any())).thenThrow(new UnsupportedResourceReferenceException("customMessage")); assertNull(this.scriptService.getURL("myType", "myEngine", null)); JCaptchaResourceReference jCaptchaResourceReference = new JCaptchaResourceReference("myType", "myEngine"); verify(serializer, times(1)).serialize(jCaptchaResourceReference); assertEquals("Error while serializing JCaptcha URL for type [myType], engine = [myEngine]." + " Root cause = [UnsupportedResourceReferenceException: customMessage]", logCapture.getMessage(0)); }
@Test public void getURLNullParams() { assertNull(this.scriptService.getURL(null, "foo", null)); assertNull(this.scriptService.getURL("foo", null, null)); }