-1

I have function

public void foo(final String s) {
  if(StringUtils.isBlank(s) {//throw error}
  //rest of the logic
}

and unit test

@Test(//expected exception)
public void testFooWithBlankString() {
   ClassOfFoo.foo(StringUtils.EMPTY);
}

Is this correct? Should I create a blank variable like

BLANK = "   "

and use that in unit test?

Rishabh Singhal
  • 1,173
  • 10
  • 22
  • I think isBlank checks for whitespace, length 0 and null whereas empty checks for string of length 0 or null. So it depends on the purpose of your check. – nbz Jun 25 '14 at 14:29

1 Answers1

1

StringUtils.isBlank() checks for three things:

  • length = 0
  • null
  • whitespace (" ")

StringUtils.EMPTY = "". So if you want to check for empty String then go for this but if you consider whitespace (" ") to be checked as well then use isBlank().

nbz
  • 3,806
  • 3
  • 28
  • 56
  • 1
    good answer. OP should consider using Theories to pass in all values that should cause the exception – John B Jun 25 '14 at 16:25