Created
August 18, 2014 03:30
-
-
Save up1/343f4ce81b9aabc0c02d to your computer and use it in GitHub Desktop.
Demo for test exception with JUnit 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Person getPerson(int id) { | |
try { | |
String sql = "select * from person where id=?"; | |
JdbcTemplate<Person> jdbcTemplate = new JdbcTemplate<Person>(this.dataSource); | |
return jdbcTemplate.executeQueryObject(sql, new Object[] {id}, new PersonRowMapper()); | |
} catch (Exception e) { | |
throw new RetriveDataException("Cat not get all person"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Rule | |
public ExpectedException thrown = ExpectedException.none(); | |
@Test | |
public void findAndReadExistingPersonByUserID2() { | |
PersonDAO personDAO = new PersonDAO(getDataSource()); | |
personDAO.getPerson(5); | |
thrown.expect(RetriveDataException.class); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetriveDataException extends RuntimeException { | |
public RetriveDataException() { | |
super(); | |
} | |
public RetriveDataException(String message) { | |
super(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment