У меня тест который должен проверять выброс Exception, но не смотря на то что в StackTrace он попадает, выражение @Test(expected = PSQLException.class) на него не реагирует:
@Test(expected = PSQLException.class)
public void whenAdditionInProposalWhereAuthorNotExistThen() {
final Proposal proposal = new Proposal();
proposal.setUrlRecruiter("url_recruiter");
proposal.setUlrPropose("url_propose");
proposal.setHeader("header");
proposal.setAuthor("author_which_not_exist_in_recruiter_table");
proposal.setCreate(new Timestamp(System.currentTimeMillis()));
final InjectorInProposal injector = new InjectorInProposal(properties, connection);
//Testing ingection.
injector.injectInProposal(proposal);
}
Вылетает ожидаемый мной Exception:
org.postgresql.util.PSQLException: ERROR: insert or update on table "proposal" violates foreign key constraint "proposal_nickname_fkey"
Подробности: Key (nickname)=(author_which_not_exist_in_recruiter_table) is not present in table "recruiter".
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
at ru.pravvich.jdbc.action.InjectorInProposal.injectInProposal(InjectorInProposal.java:48)
at ru.pravvich.jdbc.action.InjectorInProposalTest.whenAdditionInProposalWhereAuthorNotExistThen(InjectorInProposalTest.java:115)
Причем AuthorNotExistThen(InjectorInProposalTest.java:115) (в самом конце) это как раз и есть последняя строка теста : injector.injectInProposal(proposal); (стр 115)
Подскажите пожалуйста почему так получается, и как мне все таки поймать этот PSQLException?
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости