### Question:
ServiceNameValidator implements ParameterValidator { @Override public Object attemptToCorrect(Object serviceName, final Map<String, Object> relatedParameters) { if (!(serviceName instanceof String)) { throw new ContentException(Messages.COULD_NOT_CREATE_VALID_SERVICE_NAME_FROM_0, serviceName); } boolean applyNamespaceLocal = MapUtil.parseBooleanFlag(relatedParameters, SupportedParameters.APPLY_NAMESPACE, true); boolean applyNamespace = applyNamespaceGlobal && applyNamespaceLocal; return NameUtil.computeValidServiceName((String) serviceName, namespace, applyNamespace); } ServiceNameValidator(String namespace, boolean applyNamespace); @Override Class<?> getContainerType(); @Override String getParameterName(); @Override boolean isValid(Object serviceName, final Map<String, Object> context); @Override boolean canCorrect(); @Override Object attemptToCorrect(Object serviceName, final Map<String, Object> relatedParameters); @Override Set<String> getRelatedParameterNames();  }### Answer:
@Test void testCorrectionWithNoNamespaces() { ServiceNameValidator serviceNameValidator = new ServiceNameValidator(null, false); String result = (String) serviceNameValidator.attemptToCorrect(SERVICE_NAME, CONTEXT_DO_NOT_APPLY_NAMESPACE); assertEquals(SERVICE_NAME, result); }
@Test void testCorrectionWithNamespaces() { ServiceNameValidator serviceNameValidator = new ServiceNameValidator(NAMESPACE, true); String result = (String) serviceNameValidator.attemptToCorrect(SERVICE_NAME, CONTEXT_APPLY_NAMESPACE); assertEquals(String.format("%s" + Constants.NAMESPACE_SEPARATOR + "%s", NAMESPACE, SERVICE_NAME), result); }
@Test void testCorrectionWithInvalidServiceName() { ServiceNameValidator serviceNameValidator = new ServiceNameValidator(NAMESPACE, false); assertThrows(ContentException.class, () -> serviceNameValidator.attemptToCorrect(Collections.emptyList(), CONTEXT_DO_NOT_APPLY_NAMESPACE)); }