Skip to content

Commit 1fb1a62

Browse files
johnmayegonw
authored andcommitted
Duplicate the expectReader test from the FormatFactory.
1 parent 95a8bda commit 1fb1a62

File tree

12 files changed

+80
-46
lines changed

12 files changed

+80
-46
lines changed

misc/extra/pom.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</parent>
1212

1313
<artifactId>cdk-extra</artifactId>
14+
<name>cdk-extra</name>
1415

1516
<dependencies>
1617
<dependency>
@@ -82,8 +83,4 @@
8283
<version>${project.parent.version}</version>
8384
</dependency>
8485
</dependencies>
85-
86-
87-
<name>cdk-extra</name>
88-
8986
</project>

misc/test-extra/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@
8787
<version>${project.parent.version}</version>
8888
<scope>test</scope>
8989
</dependency>
90-
<dependency>
91-
<groupId>${project.groupId}</groupId>
92-
<artifactId>cdk-io</artifactId>
93-
<version>${project.parent.version}</version>
94-
<type>test-jar</type>
95-
<scope>test</scope>
96-
</dependency>
9790
<dependency>
9891
<groupId>${project.groupId}</groupId>
9992
<artifactId>cdk-ioformats</artifactId>

misc/test-extra/src/test/java/org/openscience/cdk/io/ExtraReaderFactoryTest.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,76 @@
2222
* */
2323
package org.openscience.cdk.io;
2424

25+
import org.junit.Assert;
2526
import org.junit.Test;
27+
import org.openscience.cdk.AtomContainer;
28+
import org.openscience.cdk.ChemFile;
29+
import org.openscience.cdk.ChemModel;
30+
import org.openscience.cdk.Reaction;
31+
import org.openscience.cdk.interfaces.IChemObject;
2632
import org.openscience.cdk.io.formats.GamessFormat;
33+
import org.openscience.cdk.io.formats.IChemFormat;
34+
import org.openscience.cdk.io.formats.IChemFormatMatcher;
2735
import org.openscience.cdk.io.formats.INChIFormat;
2836
import org.openscience.cdk.io.formats.INChIPlainTextFormat;
37+
import org.openscience.cdk.io.formats.IResourceFormat;
2938
import org.openscience.cdk.io.formats.VASPFormat;
3039

40+
import java.io.InputStream;
41+
3142
/**
3243
* TestCase for the instantiation and functionality of the {@link ReaderFactory} for
3344
* io classes currently in 'cdk-extra'.
3445
*
3546
* @cdk.module test-extra
3647
*/
37-
public class ExtraReaderFactoryTest extends AbstractReaderFactoryTest {
48+
public class ExtraReaderFactoryTest {
3849

3950
private ReaderFactory factory = new ReaderFactory();
4051

52+
void expectReader(String filename,
53+
IResourceFormat expectedFormat)
54+
throws Exception {
55+
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
56+
Assert.assertNotNull("Cannot find file: " + filename, ins);
57+
if (expectedFormat instanceof IChemFormatMatcher) {
58+
factory.registerFormat((IChemFormatMatcher) expectedFormat);
59+
}
60+
ISimpleChemObjectReader reader = factory.createReader(ins);
61+
Assert.assertNotNull(reader);
62+
Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName());
63+
// now try reading something from it
64+
IChemObject[] objects = {new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction()};
65+
boolean read = false;
66+
for (int i = 0; (i < objects.length && !read); i++) {
67+
if (reader.accepts(objects[i].getClass())) {
68+
IChemObject chemObject = reader.read(objects[i]);
69+
Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it",
70+
chemObject);
71+
read = true;
72+
}
73+
}
74+
Assert.assertTrue("Reading an IChemObject from the Reader did not work properly.", read);
75+
}
76+
4177
@Test
4278
public void testINChI() throws Exception {
43-
expectReader("data/inchi/guanine.inchi.xml", INChIFormat.getInstance(), -1, -1);
79+
expectReader("data/inchi/guanine.inchi.xml", INChIFormat.getInstance());
4480
}
4581

4682
@Test
4783
public void testINChIPlainText() throws Exception {
48-
expectReader("data/inchi/guanine.inchi", INChIPlainTextFormat.getInstance(), -1, -1);
84+
expectReader("data/inchi/guanine.inchi", INChIPlainTextFormat.getInstance());
4985
}
5086

5187
@Test
5288
public void testVASP() throws Exception {
53-
expectReader("data/vasp/LiMoS2_optimisation_ISIF3.vasp", VASPFormat.getInstance(), -1, -1);
89+
expectReader("data/vasp/LiMoS2_optimisation_ISIF3.vasp", VASPFormat.getInstance());
5490
}
5591

5692
@Test
5793
public void testGamess() throws Exception {
58-
expectReader("data/gamess/ch3oh_gam.out", GamessFormat.getInstance(), -1, -1);
94+
expectReader("data/gamess/ch3oh_gam.out", GamessFormat.getInstance());
5995
}
6096

6197
}

storage/iordf/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@
100100
<version>${project.parent.version}</version>
101101
<scope>test</scope>
102102
</dependency>
103-
<dependency>
104-
<groupId>${project.groupId}</groupId>
105-
<artifactId>cdk-io</artifactId>
106-
<version>${project.parent.version}</version>
107-
<type>test-jar</type>
108-
<scope>test</scope>
109-
</dependency>
110103
<dependency>
111104
<groupId>${project.groupId}</groupId>
112105
<artifactId>cdk-test</artifactId>

storage/libiocml/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@
9999
<version>${project.parent.version}</version>
100100
<scope>test</scope>
101101
</dependency>
102-
<dependency>
103-
<groupId>${project.groupId}</groupId>
104-
<artifactId>cdk-io</artifactId>
105-
<version>${project.parent.version}</version>
106-
<type>test-jar</type>
107-
<scope>test</scope>
108-
</dependency>
109102
<dependency>
110103
<groupId>${project.groupId}</groupId>
111104
<artifactId>cdk-test</artifactId>

storage/pdb/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@
7777
<type>test-jar</type>
7878
<scope>test</scope>
7979
</dependency>
80-
<dependency>
81-
<groupId>${project.groupId}</groupId>
82-
<artifactId>cdk-io</artifactId>
83-
<version>${project.parent.version}</version>
84-
<type>test-jar</type>
85-
<scope>test</scope>
86-
</dependency>
8780
<dependency>
8881
<groupId>${project.groupId}</groupId>
8982
<artifactId>cdk-testdata</artifactId>

0 commit comments

Comments
 (0)