From c5f2ce41fae8f62b69134743b4d244e969bf284e Mon Sep 17 00:00:00 2001 From: haerong22 Date: Sun, 1 May 2022 17:53:31 +0900 Subject: [PATCH] closed #7 jdbc: checked exception --- .../jdbc/exception/basic/CheckedAppTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 jdbc/src/test/java/com/example/jdbc/exception/basic/CheckedAppTest.java diff --git a/jdbc/src/test/java/com/example/jdbc/exception/basic/CheckedAppTest.java b/jdbc/src/test/java/com/example/jdbc/exception/basic/CheckedAppTest.java new file mode 100644 index 00000000..b82cf8f6 --- /dev/null +++ b/jdbc/src/test/java/com/example/jdbc/exception/basic/CheckedAppTest.java @@ -0,0 +1,48 @@ +package com.example.jdbc.exception.basic; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.net.ConnectException; +import java.sql.SQLException; + +public class CheckedAppTest { + + @Test + void checked() { + Controller controller = new Controller(); + + Assertions.assertThatThrownBy(controller::request) + .isInstanceOf(Exception.class); + } + + static class Controller { + Service service = new Service(); + + public void request() throws SQLException, ConnectException { + service.logic(); + } + } + + static class Service { + Repository repository = new Repository(); + NetworkClient networkClient = new NetworkClient(); + + public void logic() throws SQLException, ConnectException { + repository.call(); + networkClient.call(); + } + } + + static class NetworkClient { + public void call() throws ConnectException { + throw new ConnectException("연결 실패"); + } + } + + static class Repository { + public void call() throws SQLException { + throw new SQLException("ex"); + } + } +}