-
Notifications
You must be signed in to change notification settings - Fork 399
Fix ArrayIndexOutOfBoundsException and file validation in CathInstallation #1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+113
−11
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72b5ed1
Fix ArrayIndexOutOfBoundsException and file validation in CathInstall…
josemduarte 4b4e91f
Merge branch 'master' into jd/cath-fixes
josemduarte 83fe61a
Safeguard for case of nothing parseable in file
josemduarte 27bb418
Logging
josemduarte 26c03d1
Demoting
josemduarte 954d75a
Test fix suggested by AI: test was failing when download was too slow
josemduarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
biojava-structure/src/test/java/org/biojava/nbio/structure/cath/CathInstallationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * BioJava development code | ||
| * | ||
| * This code may be freely distributed and modified under the | ||
| * terms of the GNU Lesser General Public Licence. This should | ||
| * be distributed with the code. If you do not have a copy, | ||
| * see: | ||
| * | ||
| * http://www.gnu.org/copyleft/lesser.html | ||
| * | ||
| * Copyright for this code is held jointly by the individual | ||
| * authors. These should be listed in @author doc comments. | ||
| * | ||
| * For more information on the BioJava project and its aims, | ||
| * or to join the biojava-l mailing list, visit the home page | ||
| * at: | ||
| * | ||
| * http://www.biojava.org/ | ||
| */ | ||
| package org.biojava.nbio.structure.cath; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.StringReader; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class CathInstallationTest { | ||
|
|
||
| @Test | ||
| public void testParseCathDomainListSuccess() throws IOException { | ||
| String data = "# CATH domain list\n" | ||
| + "\n" | ||
| + "1oaiA00 1 10 490 10 1 1 1 1 1 124 1.80\n" | ||
| + "1oaiA01 1 10 490 10 1 1 1 1 2 150 1.80\n"; | ||
|
|
||
| CathInstallation installation = new CathInstallation(""); | ||
| BufferedReader reader = new BufferedReader(new StringReader(data)); | ||
| installation.parseCathDomainList(reader); | ||
| installation.setInstalledDomainList(new AtomicBoolean(true)); //1 | ||
| installation.setInstalledDomall(new AtomicBoolean(true)); //2 | ||
|
|
||
| CathDomain domain = installation.getDomainByCathId("1oaiA00"); | ||
|
aalhossary marked this conversation as resolved.
|
||
| assertNotNull(domain); | ||
| assertEquals("1oaiA00", domain.getDomainName()); | ||
| assertEquals(1, domain.getClassId()); | ||
| assertEquals(10, domain.getArchitectureId()); | ||
| assertEquals(490, domain.getTopologyId()); | ||
| assertEquals(10, domain.getHomologyId()); | ||
| assertEquals(124, domain.getLength()); | ||
| assertEquals(1.80, domain.getResolution(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseCathDomainListEmptyThrowsException() { | ||
| CathInstallation installation = new CathInstallation(""); | ||
| BufferedReader reader = new BufferedReader(new StringReader("")); | ||
| assertThrows(IOException.class, () -> installation.parseCathDomainList(reader)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseCathDomainListOnlyCommentsAndWhitespaceThrowsException() { | ||
| String data = "# comment 1\n" | ||
| + "# comment 2\n" | ||
| + " \n" | ||
| + "\t\n"; | ||
| CathInstallation installation = new CathInstallation(""); | ||
| BufferedReader reader = new BufferedReader(new StringReader(data)); | ||
| assertThrows(IOException.class, () -> installation.parseCathDomainList(reader)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseCathDomainListNoParsableLinesThrowsException() { | ||
| String data = "# comment\n" | ||
| + "invalid line with too few tokens\n" | ||
| + "another bad line\n"; | ||
| CathInstallation installation = new CathInstallation(""); | ||
| BufferedReader reader = new BufferedReader(new StringReader(data)); | ||
| IOException exception = assertThrows(IOException.class, () -> installation.parseCathDomainList(reader)); | ||
| assertNotNull(exception.getMessage()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.