### Question:
BbCodeAwareSizeValidator implements ConstraintValidator<BbCodeAwareSize, String>, ApplicationContextAware { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value != null) { String emptyListRemoved = removeEmptyListBb(value); String trimed = removeBBCodes(emptyListRemoved).trim(); int plainTextLength = getDisplayedLength(trimed); return plainTextLength >= min && value.length() <= max; } return false; } @Autowired  BbCodeAwareSizeValidator(PluginBbCodeService bbCodeService); @Override void initialize(BbCodeAwareSize constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); @Override void setApplicationContext(ApplicationContext ac); static final String NEW_LINE_HTML; static final String QUOTE_HTML; static final String EMPTY_LIST_BB_REGEXP; }### Answer:
@Test public void testValidationPassed() { String source = "1234567"; when(bbCodeService.stripBBCodes(source)).thenReturn(source); assertTrue(validator.isValid(source, null)); }
@Test public void testNullValue() { assertFalse(validator.isValid(null, null)); }
@Test public void testValueTooLong() { String source = "12345678901234567890123456"; when(bbCodeService.stripBBCodes(source)).thenReturn(source); assertFalse(validator.isValid(source, null)); }
@Test public void testValueTooShort() { String source = "12"; when(bbCodeService.stripBBCodes(source)).thenReturn(source); assertFalse(validator.isValid(source, null)); }
@Test public void testSpaces() { String source = " "; when(bbCodeService.stripBBCodes(source)).thenReturn(source); assertFalse(validator.isValid(source, null)); }
@Test public void testMaxLengthWithBbCodes() { String source = "[b]123456789012345678[/b]"; when(bbCodeService.stripBBCodes(source)).thenReturn("123456789012345678"); assertTrue(validator.isValid(source, null)); }
@Test public void testTooLongWithBbCodes() { String source = "[b][b]1234567890123[/b][/b]"; when(bbCodeService.stripBBCodes(source)).thenReturn("1234567890123"); assertFalse(validator.isValid(source, null)); }
@Test public void testTooShortWithBbCodes() { String source = "[b][b]12[/b][/b]"; when(bbCodeService.stripBBCodes(source)).thenReturn("12"); assertFalse(validator.isValid(source, null)); }
@Test public void testBBCodesOnly() { String source = "[b][b][/b][/b]"; when(bbCodeService.stripBBCodes(source)).thenReturn(""); assertFalse(validator.isValid(source, null)); }
@Test public void testBBCodesListOnly() { String source = "[list]\n" + "[*]\n" + "[*]\n" + "[/list]"; when(bbCodeService.stripBBCodes("")).thenReturn(""); assertFalse(validator.isValid(source, null)); }