src/test/java/org/embulk/input/kintone/TestKintoneClient.java in embulk-input-kintone-0.1.1 vs src/test/java/org/embulk/input/kintone/TestKintoneClient.java in embulk-input-kintone-0.1.2

- old
+ new

@@ -5,17 +5,18 @@ import org.embulk.spi.InputPlugin; import org.embulk.test.TestingEmbulk; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import static org.junit.Assert.*; public class TestKintoneClient { private ConfigSource config; + private KintoneClient client = new KintoneClient(); private static final String BASIC_RESOURCE_PATH = "org/embulk/input/kintone/"; + private static final String SUCCESS_MSG = "Exception should be thrown by this"; private static ConfigSource loadYamlResource(TestingEmbulk embulk, String fileName) { return embulk.loadYamlResource(BASIC_RESOURCE_PATH + fileName); } @@ -26,50 +27,54 @@ @Test public void checkClientWithUsernameAndPassword() { config = loadYamlResource(embulk, "base.yml"); PluginTask task = config.loadConfig(PluginTask.class); - KintoneClient client = new KintoneClient(task); - assertNotNull(client); + Exception e = assertThrows(Exception.class, ()-> { + client.validateAuth(task); + throw new Exception(SUCCESS_MSG); + }); + assertEquals(SUCCESS_MSG, e.getMessage()); } @Test public void checkThrowErrorWithoutAuthInfo() { config = loadYamlResource(embulk, "base.yml"); config.remove("username") .remove("password"); PluginTask task = config.loadConfig(PluginTask.class); - ConfigException e = assertThrows(ConfigException.class, () -> new KintoneClient(task)); + ConfigException e = assertThrows(ConfigException.class, () -> client.validateAuth(task)); assertEquals("Username and password or token must be provided", e.getMessage()); } @Test public void checkClientErrorLackingPassword() { config = loadYamlResource(embulk, "base.yml"); config.remove("password"); PluginTask task = config.loadConfig(PluginTask.class); - ConfigException e = assertThrows(ConfigException.class, () -> new KintoneClient(task)); + ConfigException e = assertThrows(ConfigException.class, () -> client.validateAuth(task)); assertEquals("Username and password or token must be provided", e.getMessage()); } @Test public void checkClientErrorLackingUsername() { config = loadYamlResource(embulk, "base.yml"); config.remove("username"); PluginTask task = config.loadConfig(PluginTask.class); - ConfigException e = assertThrows(ConfigException.class, () -> { - new KintoneClient(task); - }); + ConfigException e = assertThrows(ConfigException.class, () -> client.validateAuth(task)); assertEquals("Username and password or token must be provided", e.getMessage()); } @Test public void checkClientWithToken() { config = loadYamlResource(embulk, "base.yml"); config.remove("username") .remove("password") .set("token", "token"); PluginTask task = config.loadConfig(PluginTask.class); - KintoneClient client = new KintoneClient(task); - assertNotNull(client); + Exception e = assertThrows(Exception.class, ()-> { + client.validateAuth(task); + throw new Exception(SUCCESS_MSG); + }); + assertEquals(SUCCESS_MSG, e.getMessage()); } }