From d426daf5ade18ed5d267eff82db0ce93fa9a9583 Mon Sep 17 00:00:00 2001 From: Jiyang Date: Thu, 14 Mar 2024 11:54:42 -0500 Subject: [PATCH 1/2] Add exceptional behavior tests --- .../opencb/commons/utils/FileUtilsTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/commons-lib/src/test/java/org/opencb/commons/utils/FileUtilsTest.java b/commons-lib/src/test/java/org/opencb/commons/utils/FileUtilsTest.java index 8cae2f90e..e0983cb26 100644 --- a/commons-lib/src/test/java/org/opencb/commons/utils/FileUtilsTest.java +++ b/commons-lib/src/test/java/org/opencb/commons/utils/FileUtilsTest.java @@ -50,4 +50,23 @@ public void getUserAndGroupNumeric() throws IOException { Assert.assertEquals("0", user[0]); Assert.assertEquals("0", user[1]); } -} \ No newline at end of file + + @Test(expected = IOException.class) + public void checkPathNull() throws IOException { + FileUtils.checkPath(null, false); + } + + @Test(expected = IOException.class) + public void checkPathNonExist() throws IOException { + FileUtils.checkPath(path, true); + FileUtils.checkPath(Paths.get("/tmp/nonExistentPath"), true); + } + + @Test(expected = IOException.class) + public void checkFileIsDir() throws IOException { + FileUtils.checkFile(path, true); + FileUtils.checkFile(Paths.get("/tmp/test.txt"), true); + FileUtils.checkFile(Paths.get("/tmp/test.txt"), false); + FileUtils.checkFile(Paths.get("/tmp/test.txt/"), true); + } +} From 578ac2cb1f4eb38d3fc15d1ec79abf8036c48d68 Mon Sep 17 00:00:00 2001 From: Jiyang Date: Thu, 14 Mar 2024 11:55:32 -0500 Subject: [PATCH 2/2] Add exceptional behavior tests --- .../java/org/opencb/commons/datastore/core/QueryTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commons-datastore/commons-datastore-core/src/test/java/org/opencb/commons/datastore/core/QueryTest.java b/commons-datastore/commons-datastore-core/src/test/java/org/opencb/commons/datastore/core/QueryTest.java index 206aa702f..5ab45e43f 100644 --- a/commons-datastore/commons-datastore-core/src/test/java/org/opencb/commons/datastore/core/QueryTest.java +++ b/commons-datastore/commons-datastore-core/src/test/java/org/opencb/commons/datastore/core/QueryTest.java @@ -62,4 +62,10 @@ public void testValidateError2() throws Exception { thrown.expect(EnumConstantNotPresentException.class); query.validate(TestQueryParam.class); } -} \ No newline at end of file + + @Test(expected = EnumConstantNotPresentException.class) + public void testValidateWrongParam() throws Exception { + Query query = new Query(TestQueryParam.TEST_PARAM_BOOLEAN.key(), true).append("wrongParam", "1"); + query.validate(TestQueryParam.class); + } +}