From 7617aa9f7410e779ecc74c5052f9eca5c6c2ffa2 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 18:18:49 +0100 Subject: [PATCH 01/16] Added the first few tests --- .../cdk/tools/StdErrLoggerTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java new file mode 100644 index 0000000000..b03caa85b9 --- /dev/null +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -0,0 +1,80 @@ +/* Copyright (C) 2025 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.tools; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class StdErrLoggerTest { + + private static PrintStream originalErr = System.err; + + @BeforeAll + public static void setUpStreams() { + originalErr = System.err; + } + + @AfterAll + public static void restoreStreams() { + System.setErr(originalErr); + } + + @Test + public void testSetLevel() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + Assertions.assertFalse(logger.isDebugEnabled()); + logger.setLevel(ILoggingTool.DEBUG); + Assertions.assertTrue(logger.isDebugEnabled()); + } + + @Test + public void testDumpSystemProperties() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.dumpSystemProperties(); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(logger.isDebugEnabled()); + Assertions.assertTrue(output.contains("os.arch")); + } + + @Test + public void testDumpClasspath() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.dumpClasspath(); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(logger.isDebugEnabled()); + Assertions.assertTrue(output.contains("java.class.path")); + } + +} From 1258f17fe681d0ea94d5e5982ff7bce8ebf580ad Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 18:19:15 +0100 Subject: [PATCH 02/16] Turn on the testing --- base/interfaces/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/base/interfaces/pom.xml b/base/interfaces/pom.xml index 4916707467..d345a46f49 100644 --- a/base/interfaces/pom.xml +++ b/base/interfaces/pom.xml @@ -35,9 +35,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.2.5 - - true - From d19bd59e81a0913875c9481fe3f6e56bcaac8c41 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 21:25:53 +0100 Subject: [PATCH 03/16] More tests --- .../cdk/tools/StdErrLoggerTest.java | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java index b03caa85b9..e96c27e754 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.openscience.cdk.exception.CDKException; public class StdErrLoggerTest { @@ -49,6 +50,7 @@ public void testSetLevel() throws IOException { Assertions.assertFalse(logger.isDebugEnabled()); logger.setLevel(ILoggingTool.DEBUG); Assertions.assertTrue(logger.isDebugEnabled()); + Assertions.assertEquals(ILoggingTool.DEBUG, logger.getLevel()); } @Test @@ -77,4 +79,136 @@ public void testDumpClasspath() throws IOException { Assertions.assertTrue(output.contains("java.class.path")); } + @Test + public void testDebug_Objects() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.debug("test", "foo", "bar"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("DEBUG: testfoobar")); + } + + @Test + public void testInfo() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.INFO); + logger.info("test"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("INFO: test")); + } + + @Test + public void testInfo_Objects() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.INFO); + logger.info("test", "foo", "bar"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("INFO: testfoobar")); + } + + @Test + public void testWarn() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.INFO); + logger.warn("test"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("WARN: test")); + } + + @Test + public void testWarn_Objects() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.INFO); + logger.warn("test", "foo", "bar"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("WARN: testfoobar")); + } + + @Test + public void testThrowable() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.debug(new CDKException("oh no")); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); + } + + @Test + public void testThrowables() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.debug(new CDKException("oh no", new CDKException("this is bad"))); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); + Assertions.assertTrue(output.contains("DEBUG: Caused by")); + Assertions.assertTrue(output.contains("DEBUG: Exception: this is bad")); + } + + @Test + public void testThrowables_Length() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.setStackLength(5); + try { + new Integer("no integer"); + } catch (Exception e) { + logger.debug(new CDKException("oh no", e)); + } + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); + Assertions.assertTrue(output.contains("DEBUG: Caused by")); + Assertions.assertTrue(output.contains("DEBUG: Exception: For input string: \"no integer\"")); + Assertions.assertTrue(output.contains("at java.lang.Integer.parseInt")); + } + + @Test + public void testThrowables_Length_Limited() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.DEBUG); + logger.setStackLength(1); + try { + new Integer("no integer"); + } catch (Exception e) { + logger.debug(new CDKException("oh no", e)); + } + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); + Assertions.assertTrue(output.contains("DEBUG: Caused by")); + Assertions.assertTrue(output.contains("DEBUG: Exception: For input string: \"no integer\"")); + Assertions.assertFalse(output.contains("at java.lang.Integer.parseInt")); + } + + @Test + public void testCreate() throws IOException { + ILoggingTool logger = StdErrLogger.create(this.getClass()); + Assertions.assertNotNull(logger); + } + } From 7b7e73a9426bd17f3704b84d6ed0a3a063644afd Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 21:30:17 +0100 Subject: [PATCH 04/16] Now also works in Java 21 --- .../test/java/org/openscience/cdk/tools/StdErrLoggerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java index e96c27e754..315b970284 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -182,7 +182,7 @@ public void testThrowables_Length() throws IOException { Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); Assertions.assertTrue(output.contains("DEBUG: Caused by")); Assertions.assertTrue(output.contains("DEBUG: Exception: For input string: \"no integer\"")); - Assertions.assertTrue(output.contains("at java.lang.Integer.parseInt")); + Assertions.assertTrue(output.contains("java.lang.Integer.parseInt")); } @Test @@ -202,7 +202,7 @@ public void testThrowables_Length_Limited() throws IOException { Assertions.assertTrue(output.contains("DEBUG: Exception: oh no")); Assertions.assertTrue(output.contains("DEBUG: Caused by")); Assertions.assertTrue(output.contains("DEBUG: Exception: For input string: \"no integer\"")); - Assertions.assertFalse(output.contains("at java.lang.Integer.parseInt")); + Assertions.assertFalse(output.contains("java.lang.Integer.parseInt")); } @Test From 0c5bb8db39b53ef0f2f1030b800f2c7889560ce6 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 21:44:10 +0100 Subject: [PATCH 05/16] Some more testing --- .../cdk/tools/StdErrLoggerTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java index 315b970284..3ac2dc8791 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -115,6 +115,18 @@ public void testInfo_Objects() throws IOException { Assertions.assertTrue(output.contains("INFO: testfoobar")); } + @Test + public void testFatal() throws IOException { + ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + ILoggingTool logger = new StdErrLogger(this.getClass()); + logger.setLevel(ILoggingTool.FATAL); + logger.fatal("test"); + errContent.flush(); + String output = new String(errContent.toByteArray()); + Assertions.assertTrue(output.contains("FATAL: test")); + } + @Test public void testWarn() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); @@ -211,4 +223,31 @@ public void testCreate() throws IOException { Assertions.assertNotNull(logger); } + @Test + public void testCreateWithSysenvLevels() throws IOException { + String originalLevel = System.getProperty("cdk.logging.level", "warn"); + + System.setProperty("cdk.logging.level", "trace"); + ILoggingTool logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.TRACE, logger.getLevel()); + System.setProperty("cdk.logging.level", "debug"); + logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.DEBUG, logger.getLevel()); + System.setProperty("cdk.logging.level", "info"); + logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.INFO, logger.getLevel()); + System.setProperty("cdk.logging.level", "warn"); + logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.WARN, logger.getLevel()); + System.setProperty("cdk.logging.level", "error"); + logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.ERROR, logger.getLevel()); + System.setProperty("cdk.logging.level", "fatal"); + logger = StdErrLogger.create(this.getClass()); + Assertions.assertEquals(ILoggingTool.FATAL, logger.getLevel()); + + // restore the original value + System.setProperty("cdk.logging.level", originalLevel); + } + } From 8a2264abcc22dae5619e201341eade549c94bbdb Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Mar 2025 21:53:00 +0100 Subject: [PATCH 06/16] Code cleanup --- .../cdk/tools/StdErrLoggerTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java index 3ac2dc8791..a467f48e5e 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -43,7 +43,7 @@ public static void restoreStreams() { } @Test - public void testSetLevel() throws IOException { + void testSetLevel() { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -54,7 +54,7 @@ public void testSetLevel() throws IOException { } @Test - public void testDumpSystemProperties() throws IOException { + void testDumpSystemProperties() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -67,7 +67,7 @@ public void testDumpSystemProperties() throws IOException { } @Test - public void testDumpClasspath() throws IOException { + void testDumpClasspath() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -80,7 +80,7 @@ public void testDumpClasspath() throws IOException { } @Test - public void testDebug_Objects() throws IOException { + void testDebug_Objects() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -92,7 +92,7 @@ public void testDebug_Objects() throws IOException { } @Test - public void testInfo() throws IOException { + void testInfo() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -104,7 +104,7 @@ public void testInfo() throws IOException { } @Test - public void testInfo_Objects() throws IOException { + void testInfo_Objects() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -116,7 +116,7 @@ public void testInfo_Objects() throws IOException { } @Test - public void testFatal() throws IOException { + void testFatal() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -128,7 +128,7 @@ public void testFatal() throws IOException { } @Test - public void testWarn() throws IOException { + void testWarn() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -140,7 +140,7 @@ public void testWarn() throws IOException { } @Test - public void testWarn_Objects() throws IOException { + void testWarn_Objects() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -152,7 +152,7 @@ public void testWarn_Objects() throws IOException { } @Test - public void testThrowable() throws IOException { + void testThrowable() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -164,7 +164,7 @@ public void testThrowable() throws IOException { } @Test - public void testThrowables() throws IOException { + void testThrowables() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); @@ -178,14 +178,14 @@ public void testThrowables() throws IOException { } @Test - public void testThrowables_Length() throws IOException { + void testThrowables_Length() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); logger.setLevel(ILoggingTool.DEBUG); logger.setStackLength(5); try { - new Integer("no integer"); + Integer.parseInt("no integer"); } catch (Exception e) { logger.debug(new CDKException("oh no", e)); } @@ -198,14 +198,14 @@ public void testThrowables_Length() throws IOException { } @Test - public void testThrowables_Length_Limited() throws IOException { + void testThrowables_Length_Limited() throws IOException { ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); ILoggingTool logger = new StdErrLogger(this.getClass()); logger.setLevel(ILoggingTool.DEBUG); logger.setStackLength(1); try { - new Integer("no integer"); + Integer.parseInt("no integer"); } catch (Exception e) { logger.debug(new CDKException("oh no", e)); } @@ -218,13 +218,13 @@ public void testThrowables_Length_Limited() throws IOException { } @Test - public void testCreate() throws IOException { + void testCreate() { ILoggingTool logger = StdErrLogger.create(this.getClass()); Assertions.assertNotNull(logger); } @Test - public void testCreateWithSysenvLevels() throws IOException { + void testCreateWithSysenvLevels() { String originalLevel = System.getProperty("cdk.logging.level", "warn"); System.setProperty("cdk.logging.level", "trace"); From 94c6d0871d69188a8094babad8528a1ad2a1e57d Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 07:23:54 +0100 Subject: [PATCH 07/16] Moved the class to the tested module, and use a logger from the tested module --- .../openscience/cdk/tools/LoggingToolFactoryTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename base/{test-core => interfaces}/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java (89%) diff --git a/base/test-core/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java similarity index 89% rename from base/test-core/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java index 0b60c27065..b29295c022 100644 --- a/base/test-core/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Egon Willighagen +/* Copyright (C) 2009,2025 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -27,9 +27,9 @@ class LoggingToolFactoryTest { @Test void testSetGetLoggingToolClass() { - Class logger = Log4jLoggingTool.class; + Class logger = StdErrLogger.class; LoggingToolFactory.setLoggingToolClass(logger); - Assertions.assertEquals(Log4jLoggingTool.class.getName(), LoggingToolFactory.getLoggingToolClass().getName()); + Assertions.assertEquals(StdErrLogger.class.getName(), LoggingToolFactory.getLoggingToolClass().getName()); } @Test @@ -40,10 +40,10 @@ void testCreateLoggingTool() { @Test void testCreateLog4jLoggingTool() { - Class logger = Log4jLoggingTool.class; + Class logger = StdErrLogger.class; LoggingToolFactory.setLoggingToolClass(logger); ILoggingTool instance = LoggingToolFactory.createLoggingTool(LoggingToolFactoryTest.class); - Assertions.assertTrue(instance instanceof Log4jLoggingTool); + Assertions.assertTrue(instance instanceof StdErrLogger); } @Test From b35bc6264f13b503f9c263ed6dabb34fce6eca5d Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 07:37:18 +0100 Subject: [PATCH 08/16] Moved a few more test classes, by removing an unneeded dependency --- base/interfaces/pom.xml | 5 +++++ .../java/org/openscience/cdk/exception/CDKExceptionTest.java | 4 ++-- .../java/org/openscience/cdk/exception/IntractableTest.java | 0 .../openscience/cdk/exception/NoSuchAtomExceptionTest.java | 4 ++-- .../cdk/exception/NoSuchAtomTypeExceptionTest.java | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) rename base/{test-core => interfaces}/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java (94%) rename base/{test-core => interfaces}/src/test/java/org/openscience/cdk/exception/IntractableTest.java (100%) rename base/{test-core => interfaces}/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java (92%) rename base/{test-core => interfaces}/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java (92%) diff --git a/base/interfaces/pom.xml b/base/interfaces/pom.xml index d345a46f49..0203283f4b 100644 --- a/base/interfaces/pom.xml +++ b/base/interfaces/pom.xml @@ -28,6 +28,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + diff --git a/base/test-core/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java similarity index 94% rename from base/test-core/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java index a97f70d842..c33fc0cb22 100644 --- a/base/test-core/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java @@ -1,4 +1,5 @@ /* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2025 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -21,7 +22,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openscience.cdk.test.CDKTestCase; /** * Checks the functionality of the CDKException class. @@ -29,7 +29,7 @@ * * @see org.openscience.cdk.exception.CDKException */ -class CDKExceptionTest extends CDKTestCase { +class CDKExceptionTest { @Test void testCDKException_String() { diff --git a/base/test-core/src/test/java/org/openscience/cdk/exception/IntractableTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java similarity index 100% rename from base/test-core/src/test/java/org/openscience/cdk/exception/IntractableTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java diff --git a/base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java similarity index 92% rename from base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java index 0b80b49cce..da23047478 100644 --- a/base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomExceptionTest.java @@ -1,4 +1,5 @@ /* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2025 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -21,7 +22,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openscience.cdk.test.CDKTestCase; /** * Checks the functionality of the NoSuchAtomException class. @@ -29,7 +29,7 @@ * * @see org.openscience.cdk.exception.NoSuchAtomException */ -class NoSuchAtomExceptionTest extends CDKTestCase { +class NoSuchAtomExceptionTest { @Test void testNoSuchAtomException_String() { diff --git a/base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java similarity index 92% rename from base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java index 002e0c06b8..896a35c4b8 100644 --- a/base/test-core/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchAtomTypeExceptionTest.java @@ -1,4 +1,5 @@ /* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project + * 2025 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -21,7 +22,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openscience.cdk.test.CDKTestCase; /** * Checks the functionality of the NoSuchAtomTypeException class. @@ -29,7 +29,7 @@ * * @see org.openscience.cdk.exception.NoSuchAtomTypeException */ -class NoSuchAtomTypeExceptionTest extends CDKTestCase { +class NoSuchAtomTypeExceptionTest { @Test void testNoSuchAtomTypeException_String() { From 08b7e56f9f910d6fcaa94c762234bb5d2d6e3f8e Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 07:46:07 +0100 Subject: [PATCH 09/16] Testing for the last two exceptions --- .../exception/NoSuchBondExceptionTest.java | 40 +++++++++++++++++++ .../UnsupportedChemObjectExceptionTest.java | 11 +---- 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchBondExceptionTest.java rename base/{test-standard => interfaces}/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java (84%) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchBondExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchBondExceptionTest.java new file mode 100644 index 0000000000..8eff4bf6a1 --- /dev/null +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/NoSuchBondExceptionTest.java @@ -0,0 +1,40 @@ +/* Copyright (C) 2025 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +package org.openscience.cdk.exception; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Checks the functionality of the NoSuchBondException class. + * + * + * @see org.openscience.cdk.exception.NoSuchBondException + */ +class NoSuchBondExceptionTest { + + @Test + void testNoSuchAtomException_String() { + final String EXPLANATION = "Buckybull is not an element!"; + NoSuchBondException exception = new NoSuchBondException(EXPLANATION); + Assertions.assertNotNull(exception); + Assertions.assertEquals(EXPLANATION, exception.getMessage()); + } +} diff --git a/base/test-standard/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java similarity index 84% rename from base/test-standard/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java rename to base/interfaces/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java index 905052dd8c..8a03d34044 100644 --- a/base/test-standard/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/UnsupportedChemObjectExceptionTest.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2007 Egon Willighagen +/* Copyright (C) 2007,2025 Egon Willighagen * * Contact: cdk-devel@lists.sourceforge.net * @@ -20,15 +20,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openscience.cdk.test.CDKTestCase; -/** - */ -class UnsupportedChemObjectExceptionTest extends CDKTestCase { - - UnsupportedChemObjectExceptionTest() { - super(); - } +class UnsupportedChemObjectExceptionTest { @Test void testUnsupportedChemObjectException_String() { From 161897343290d12badb05dc4e8d7f77358535853 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 08:43:53 +0100 Subject: [PATCH 10/16] Added two missing test classes --- base/core/pom.xml | 13 +++- .../cdk/io/setting/BooleanIOSettingTest.java | 67 +++++++++++++++++++ .../cdk/io/setting/IntegerIOSettingTest.java | 67 +++++++++++++++++++ 3 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java create mode 100644 base/core/src/test/java/org/openscience/cdk/io/setting/IntegerIOSettingTest.java diff --git a/base/core/pom.xml b/base/core/pom.xml index cc0c8244ea..4db2a71e70 100644 --- a/base/core/pom.xml +++ b/base/core/pom.xml @@ -23,6 +23,16 @@ cdk-interfaces ${project.parent.version} + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + @@ -47,9 +57,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.2.5 - - true - diff --git a/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java b/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java new file mode 100644 index 0000000000..c5df1135bd --- /dev/null +++ b/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java @@ -0,0 +1,67 @@ +/* Copyright (C) 2025 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.io.setting; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.io.setting.IOSetting.Importance; + +class BooleanIOSettingTest { + + @Test + void testConstructure() { + IOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); + Assertions.assertNotNull(setting); + Assertions.assertEquals("Glossy", setting.getName()); + Assertions.assertEquals(Importance.LOW, setting.getLevel()); + Assertions.assertEquals("Want glossy?", setting.getQuestion()); + Assertions.assertEquals("true", setting.getSetting()); + } + + @Test + void testIsSet() { + BooleanIOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); + Assertions.assertNotNull(setting); + Assertions.assertTrue(setting.isSet()); + } + + @Test + void testSetSetting() { + BooleanIOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); + Assertions.assertEquals("true", setting.getSetting()); + try { + setting.setSetting("false"); + } catch (CDKException e) { + Assertions.fail(e); // should not happen + } + Assertions.assertEquals("false", setting.getSetting()); + } + + @Test + void testSetSetting_InvalidValue() { + BooleanIOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); + try { + setting.setSetting("fake"); + Assertions.fail("Expected exception was not thrown"); // should not happen + } catch (CDKException e) { + // should happen + } + } +} diff --git a/base/core/src/test/java/org/openscience/cdk/io/setting/IntegerIOSettingTest.java b/base/core/src/test/java/org/openscience/cdk/io/setting/IntegerIOSettingTest.java new file mode 100644 index 0000000000..b7175a55cd --- /dev/null +++ b/base/core/src/test/java/org/openscience/cdk/io/setting/IntegerIOSettingTest.java @@ -0,0 +1,67 @@ +/* Copyright (C) 2025 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.io.setting; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.io.setting.IOSetting.Importance; + +class IntegerIOSettingTest { + + @Test + void testConstructure() { + IOSetting setting = new IntegerIOSetting("Number of files", Importance.LOW, "How many copies do you want?", "1"); + Assertions.assertNotNull(setting); + Assertions.assertEquals("Number of files", setting.getName()); + Assertions.assertEquals(Importance.LOW, setting.getLevel()); + Assertions.assertEquals("How many copies do you want?", setting.getQuestion()); + Assertions.assertEquals("1", setting.getSetting()); + } + + @Test + void testIsSet() { + IntegerIOSetting setting = new IntegerIOSetting("Number of files", Importance.LOW, "How many copies do you want?", "1"); + Assertions.assertNotNull(setting); + Assertions.assertEquals(1, setting.getSettingValue()); + } + + @Test + void testSetSetting() { + IOSetting setting = new IntegerIOSetting("Number of files", Importance.LOW, "How many copies do you want?", "1"); + Assertions.assertEquals("1", setting.getSetting()); + try { + setting.setSetting("2"); + } catch (CDKException e) { + Assertions.fail(e); // should not happen + } + Assertions.assertEquals("2", setting.getSetting()); + } + + @Test + void testSetSetting_InvalidValue() { + IOSetting setting = new IntegerIOSetting("Number of files", Importance.LOW, "How many copies do you want?", "1"); + try { + setting.setSetting("false"); + Assertions.fail("Expected exception was not thrown"); // should not happen + } catch (CDKException e) { + // should happen + } + } +} From 7f692433dbb4cc93415bd0c1fe2910e558000558 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 08:51:04 +0100 Subject: [PATCH 11/16] Added another missing test --- .../cdk/io/setting/OptionIOSettingTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java diff --git a/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java b/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java new file mode 100644 index 0000000000..71e10fafd9 --- /dev/null +++ b/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java @@ -0,0 +1,72 @@ +/* Copyright (C) 2025 Egon Willighagen + * + * Contact: cdk-devel@lists.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.io.setting; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.io.setting.IOSetting.Importance; + +class OptionIOSettingTest { + + @Test + void testConstructure() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + IOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + Assertions.assertNotNull(setting); + Assertions.assertEquals("Menu", setting.getName()); + Assertions.assertEquals(Importance.LOW, setting.getLevel()); + Assertions.assertEquals("What option do you want?", setting.getQuestion()); + Assertions.assertEquals("Option1", setting.getSetting()); + } + + @Test + void testSetSetting() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + IOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + Assertions.assertEquals("Option1", setting.getSetting()); + try { + setting.setSetting("Option2"); + } catch (CDKException e) { + Assertions.fail(e); // should not happen + } + Assertions.assertEquals("Option2", setting.getSetting()); + } + + @Test + void testSetSetting_InvalidValue() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + IOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + try { + setting.setSetting("Option3"); + Assertions.fail("Expected exception was not thrown"); // should not happen + } catch (CDKException e) { + // should happen + } + } +} From 85effb1bc94709650ca3e392a5a8cc059ded0eac Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 09:11:27 +0100 Subject: [PATCH 12/16] More situations tested --- .../cdk/io/setting/BooleanIOSettingTest.java | 9 ++++ .../cdk/io/setting/OptionIOSettingTest.java | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java b/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java index c5df1135bd..ce11de094a 100644 --- a/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java +++ b/base/core/src/test/java/org/openscience/cdk/io/setting/BooleanIOSettingTest.java @@ -54,6 +54,15 @@ void testSetSetting() { Assertions.assertEquals("false", setting.getSetting()); } + @Test + void testSetSetting_Variants() throws CDKException { + BooleanIOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); + setting.setSetting("yes"); Assertions.assertEquals("true", setting.getSetting()); + setting.setSetting("no"); Assertions.assertEquals("false", setting.getSetting()); + setting.setSetting("y"); Assertions.assertEquals("true", setting.getSetting()); + setting.setSetting("n"); Assertions.assertEquals("false", setting.getSetting()); + } + @Test void testSetSetting_InvalidValue() { BooleanIOSetting setting = new BooleanIOSetting("Glossy", Importance.LOW, "Want glossy?", "true"); diff --git a/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java b/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java index 71e10fafd9..2e61833a46 100644 --- a/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java +++ b/base/core/src/test/java/org/openscience/cdk/io/setting/OptionIOSettingTest.java @@ -69,4 +69,45 @@ void testSetSetting_InvalidValue() { // should happen } } + + @Test + void testSetSetting_Integer() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + OptionIOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + Assertions.assertEquals("Option1", setting.getSetting()); + try { + setting.setSetting(2); + } catch (CDKException e) { + Assertions.fail(e); // should not happen + } + Assertions.assertEquals("Option2", setting.getSetting()); + } + + @Test + void testSetSetting_InvalidValue_Integer() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + OptionIOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + try { + setting.setSetting(3); + Assertions.fail("Expected exception was not thrown"); // should not happen + } catch (CDKException e) { + // should happen + } + } + + @Test + void testGetSetting() { + List options = new ArrayList<>(); + options.add("Option1"); + options.add("Option2"); + OptionIOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1"); + List options2 = setting.getOptions(); + Assertions.assertEquals(2, options2.size()); + Assertions.assertTrue(options2.contains("Option1")); + Assertions.assertTrue(options2.contains("Option2")); + } } From cfaea46082433e0e7f2f6d7752d8a4050e5b54c3 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 09:13:48 +0100 Subject: [PATCH 13/16] Added comments, to make the quality checks okay --- .../cdk/tools/LoggingToolFactoryTest.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java index b29295c022..6d7eb23b4a 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java @@ -69,31 +69,40 @@ public static ILoggingTool create(Class sourceClass) { } @Override - public void debug(Object object) {} + public void debug(Object object) { // no implemented because not used in the testing + } @Override - public void debug(Object object, Object... objects) {} + public void debug(Object object, Object... objects) { // no implemented because not used in the testing + } @Override - public void dumpClasspath() {} + public void dumpClasspath() { // no implemented because not used in the testing + } @Override - public void dumpSystemProperties() {} + public void dumpSystemProperties() { // no implemented because not used in the testing + } @Override - public void error(Object object) {} + public void error(Object object) { // no implemented because not used in the testing + } @Override - public void error(Object object, Object... objects) {} + public void error(Object object, Object... objects) { // no implemented because not used in the testing + } @Override - public void fatal(Object object) {} + public void fatal(Object object) { // no implemented because not used in the testing + } @Override - public void info(Object object) {} + public void info(Object object) { // no implemented because not used in the testing + } @Override - public void info(Object object, Object... objects) {} + public void info(Object object, Object... objects) { // no implemented because not used in the testing + } @Override public boolean isDebugEnabled() { @@ -101,13 +110,16 @@ public boolean isDebugEnabled() { } @Override - public void setStackLength(int length) {} + public void setStackLength(int length) { // no implemented because not used in the testing + } @Override - public void warn(Object object) {} + public void warn(Object object) { // no implemented because not used in the testing + } @Override - public void warn(Object object, Object... objects) {} + public void warn(Object object, Object... objects) { // no implemented because not used in the testing + } @Override public void setLevel(int level) { From dcd2436bcfa9ec8edbd8c8585f1ce4b465c5fac4 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 09:27:13 +0100 Subject: [PATCH 14/16] Changed the exception throwing code, to have the code checker not complain about the dummy assignment --- .../java/org/openscience/cdk/exception/CDKExceptionTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java index c33fc0cb22..68ea7f1f90 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/CDKExceptionTest.java @@ -43,9 +43,7 @@ void testCDKException_String() { void testCDKException_String_Throwable() { final String EXPLANATION = "No, CDK cannot compute the multidollar ligand you search for target X."; try { - int[] array = new int[0]; - int dummy = array[50]; - dummy = dummy + 1; + Integer.parseInt("multidollar ligand"); Assertions.fail("Should not have reached this place. The test *requires* the error to occur!"); } catch (Exception exception) { CDKException cdkException = new CDKException(EXPLANATION, exception); From cbfb54affcb01f7aff4cdacdd55155f928f2340f Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 09:27:21 +0100 Subject: [PATCH 15/16] More code cleanup --- .../org/openscience/cdk/exception/IntractableTest.java | 7 +++---- .../java/org/openscience/cdk/tools/StdErrLoggerTest.java | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java b/base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java index c439ede688..9440105295 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/exception/IntractableTest.java @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) +/* Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) * John May * * Contact: cdk-devel@lists.sourceforge.net @@ -35,13 +34,13 @@ class IntractableTest { @Test - void timeout() throws Exception { + void timeout() { Intractable e = Intractable.timeout(12); assertThat(e.getMessage(), is("Operation did not finish after 12 ms.")); } @Test - void timeoutWithDesc() throws Exception { + void timeoutWithDesc() { Intractable e = Intractable.timeout("MCS", 200); assertThat(e.getMessage(), is("MCS did not finish after 200 ms.")); } diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java index a467f48e5e..119bbc35ec 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/StdErrLoggerTest.java @@ -28,17 +28,17 @@ import org.junit.jupiter.api.Test; import org.openscience.cdk.exception.CDKException; -public class StdErrLoggerTest { +class StdErrLoggerTest { private static PrintStream originalErr = System.err; @BeforeAll - public static void setUpStreams() { + static void setUpStreams() { originalErr = System.err; } @AfterAll - public static void restoreStreams() { + static void restoreStreams() { System.setErr(originalErr); } From 1c4f0f3fd88206c59559b7453a8bb921b01329f6 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sun, 23 Mar 2025 09:40:34 +0100 Subject: [PATCH 16/16] One last code smell update --- .../java/org/openscience/cdk/tools/LoggingToolFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java index 6d7eb23b4a..04a68ab948 100644 --- a/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java +++ b/base/interfaces/src/test/java/org/openscience/cdk/tools/LoggingToolFactoryTest.java @@ -123,7 +123,7 @@ public void warn(Object object, Object... objects) { // no implemented because n @Override public void setLevel(int level) { - + // no implemented because not used in the testing } @Override