### Question:
LoggingRequestValidator implements ConstraintValidator<ValidLoggingRequest, LoggingRequest> { @Override public boolean isValid(LoggingRequest value, ConstraintValidatorContext context) { if (value != null) { if (StringUtils.isEmpty(value.getStorageLocation())) { String msg = "Storage location parameter is empty in logging request"; context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } if (value.getS3() != null && !isValidPath(value.getStorageLocation())) { String msg = "Storage location parameter is invalid (s3) in logging request"; context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } if (value.getS3() == null && value.getAdlsGen2() == null && value.getGcs() == null) { String msg = "Provide at least 1 cloud storage detail in logging request"; context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } } return true; }  @Override void initialize(ValidLoggingRequest constraintAnnotation); @Override boolean isValid(LoggingRequest value, ConstraintValidatorContext context);  }### Answer:
@Test public void testValidateIfBothFieldsAreEmpty() { LoggingRequest loggingRequest = new LoggingRequest(); boolean result = underTest.isValid(loggingRequest, context); assertFalse(result); }
@Test public void testValidateInvalidLocation() { LoggingRequest loggingRequest = new LoggingRequest(); loggingRequest.setS3(new S3CloudStorageV1Parameters()); loggingRequest.setStorageLocation("?ds: da"); boolean result = underTest.isValid(loggingRequest, context); assertFalse(result); }
@Test public void testValidateValidBucket() { LoggingRequest loggingRequest = new LoggingRequest(); loggingRequest.setS3(new S3CloudStorageV1Parameters()); loggingRequest.setStorageLocation("mybucket"); boolean result = underTest.isValid(loggingRequest, context); assertTrue(result); }
@Test public void testValidateValidBucketUri() { LoggingRequest loggingRequest = new LoggingRequest(); loggingRequest.setS3(new S3CloudStorageV1Parameters()); loggingRequest.setStorageLocation("s3: boolean result = underTest.isValid(loggingRequest, context); assertTrue(result); }
@Test public void testValidateValidBasePath() { LoggingRequest loggingRequest = new LoggingRequest(); loggingRequest.setS3(new S3CloudStorageV1Parameters()); loggingRequest.setStorageLocation("basePath/custom"); boolean result = underTest.isValid(loggingRequest, context); assertTrue(result); }
@Test public void testValidateValidBasePathUri() { LoggingRequest loggingRequest = new LoggingRequest(); loggingRequest.setS3(new S3CloudStorageV1Parameters()); loggingRequest.setStorageLocation("s3: boolean result = underTest.isValid(loggingRequest, context); assertTrue(result); }