Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions base/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
<artifactId>cdk-interfaces</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -47,9 +57,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Copyright (C) 2025 Egon Willighagen <[email protected]>
*
* Contact: [email protected]
*
* 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_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");
try {
setting.setSetting("fake");
Assertions.fail("Expected exception was not thrown"); // should not happen
} catch (CDKException e) {
// should happen
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* Copyright (C) 2025 Egon Willighagen <[email protected]>
*
* Contact: [email protected]
*
* 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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* Copyright (C) 2025 Egon Willighagen <[email protected]>
*
* Contact: [email protected]
*
* 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<String> 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<String> 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<String> 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
}
}

@Test
void testSetSetting_Integer() {
List<String> 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<String> 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<String> options = new ArrayList<>();
options.add("Option1");
options.add("Option2");
OptionIOSetting setting = new OptionIOSetting("Menu", Importance.LOW, "What option do you want?", options, "Option1");
List<String> options2 = setting.getOptions();
Assertions.assertEquals(2, options2.size());
Assertions.assertTrue(options2.contains("Option1"));
Assertions.assertTrue(options2.contains("Option2"));
}
}
8 changes: 5 additions & 3 deletions base/interfaces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project
* 2025 Egon Willighagen <[email protected]>
*
* Contact: [email protected]
*
Expand All @@ -21,15 +22,14 @@

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.
*
*
* @see org.openscience.cdk.exception.CDKException
*/
class CDKExceptionTest extends CDKTestCase {
class CDKExceptionTest {

@Test
void testCDKException_String() {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI)
/* Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI)
* John May <[email protected]>
*
* Contact: [email protected]
Expand Down Expand Up @@ -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."));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project
* 2025 Egon Willighagen <[email protected]>
*
* Contact: [email protected]
*
Expand All @@ -21,15 +22,14 @@

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.
*
*
* @see org.openscience.cdk.exception.NoSuchAtomException
*/
class NoSuchAtomExceptionTest extends CDKTestCase {
class NoSuchAtomExceptionTest {

@Test
void testNoSuchAtomException_String() {
Expand Down
Loading