Skip to content

Instantly share code, notes, and snippets.

@up1
Created September 22, 2015 10:13
Show Gist options
  • Save up1/4dd22f33ce7597917481 to your computer and use it in GitHub Desktop.
Save up1/4dd22f33ce7597917481 to your computer and use it in GitHub Desktop.
Add invalid test
public class InvalidTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void input_is_null_should_thrown_numberformat_exception() {
thrown.expect(NumberFormatException.class);
thrown.expectMessage("ข้อมูลเป็นค่า null (Null Value)");
BahtText.getBath(null);
}
@Test
public void input_is_empty_after_filter_out_input_should_thrown_numberformat_exception() {
thrown.expect(NumberFormatException.class);
thrown.expectMessage("ข้อมูลเป็นค่าว่าง (Blank Value)");
BahtText.getBath(", ");
}
@Test
public void input_is_not_valid_after_filter_out_input_should_thrown_numberformat_exception() {
thrown.expect(NumberFormatException.class);
thrown.expectMessage("ข้อมูลมีตัวอักขระ (Alphabet Value)");
BahtText.getBath("ABC");
}
@Test
public void have_multiple_dot_should_thrown_numberformat_exception() {
thrown.expect(NumberFormatException.class);
thrown.expectMessage("ทศนิยมมากกว่า 1 ตัว");
BahtText.getBath("1.1.1.1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment