### Question:
ConfigureSocialAuthN extends Task { String getValidatedField(String type, Map<String, ?> params, Map<String, Set<String>> attrs, String field, String errorKey) throws WorkflowException { if ("other".equals(type)) { return getNonEmptyString(params, field, errorKey); } else { String value = CollectionHelper.getMapAttr(attrs, field); if (StringUtils.isEmpty(value)) { throw new WorkflowException(errorKey, null); } return value; } }  @Override String execute(Locale locale, Map params);  }### Answer:
@Test public void testGetValidatedFieldPresentOther() throws Exception { Map<String, Set<String>> params = new HashMap<String, Set<String>>(); params.put("field", asSet("fred")); assertEquals(task.getValidatedField("other", params, null, "field", null), "fred"); }
@Test public void testGetValidatedFieldMissingOther() throws Exception { Map<String, Set<String>> params = new HashMap<String, Set<String>>(); try { task.getValidatedField("other", params, null, "field", "missing-image-url"); fail("Expect exception"); } catch (WorkflowException e) { assertEquals(e.getErrorCode(), "missing-image-url"); } }
@Test public void testGetValidatedFieldPresent() throws Exception { Map<String, Set<String>> attrs = new HashMap<String, Set<String>>(); attrs.put("field", asSet("fred")); assertEquals(task.getValidatedField("google", null, attrs, "field", null), "fred"); }
@Test public void testGetValidatedFieldMissing() throws Exception { Map<String, Set<String>> attrs = new HashMap<String, Set<String>>(); try { task.getValidatedField("google", null, attrs, "field", "missing-image-url"); fail("Expect exception"); } catch (WorkflowException e) { assertEquals(e.getErrorCode(), "missing-image-url"); } }