Clover icon

Coverage Report

  1. Project Clover database Fri Jun 19 2026 11:35:32 BST
  2. Package jalview.io

File FileIOTester.java

 

Code metrics

0
29
11
1
180
116
11
0.38
2.64
11
1

Classes

Class Line # Actions
FileIOTester 47 29 11
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import static org.testng.Assert.assertFalse;
24    import static org.testng.Assert.assertTrue;
25   
26    import java.io.BufferedInputStream;
27    import java.io.ByteArrayInputStream;
28    import java.io.File;
29    import java.io.FileInputStream;
30    import java.io.IOException;
31    import java.io.InputStream;
32    import java.io.StringBufferInputStream;
33   
34    import org.testng.AssertJUnit;
35    import org.testng.annotations.AfterClass;
36    import org.testng.annotations.BeforeClass;
37    import org.testng.annotations.Test;
38   
39    import jalview.bin.Console;
40    import jalview.gui.JvOptionPane;
41    import jalview.util.Platform;
42   
43    /**
44    * @author jimp
45    *
46    */
 
47    public class FileIOTester
48    {
49   
 
50  1 toggle @BeforeClass(alwaysRun = true)
51    public void setUpJvOptionPane()
52    {
53  1 JvOptionPane.setInteractiveMode(false);
54  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55    }
56   
57    /**
58    * @throws java.lang.Exception
59    */
 
60  1 toggle @BeforeClass(alwaysRun = true)
61    public static void setUpBeforeClass() throws Exception
62    {
63  1 Console.initLogger();
64    }
65   
66    /**
67    * @throws java.lang.Exception
68    */
 
69  1 toggle @AfterClass(alwaysRun = true)
70    public static void tearDownAfterClass() throws Exception
71    {
72    }
73   
74    // TODO: make a better/more comprehensive test harness for identify/io
75   
76    final static File ALIGN_FILE = new File(
77    "test/jalview/io/test_gz_fasta.gz");
78   
79    final static File NOTGZALIGN_FILE = new File(
80    "test/jalview/io/test_gz_fasta_notgz.gz");
81   
82    final static File STARS_FA_FILE1 = new File(
83    "test/jalview/io/test_fasta_stars.fa");
84   
85    final static File STARS_FA_FILE2 = new File(
86    "test/jalview/io/test_fasta_stars2.fa");
87   
 
88  6 toggle private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)
89    throws FileFormatException
90    {
91  6 AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
92    fp.isValid());
93  6 FileFormatI type = new IdentifyFile().identify(fp);
94  6 AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt
95    + "' identified as '" + type + "'", type, fmt);
96    }
97   
 
98  1 toggle @Test(groups = { "Functional" })
99    public void testStarsInFasta1() throws IOException
100    {
101  1 String uri;
102  1 FileParse fp = new FileParse(
103    uri = STARS_FA_FILE1.getAbsoluteFile().toString(),
104    DataSourceType.FILE);
105  1 assertValidFormat(FileFormat.Fasta, uri, fp);
106    }
107   
 
108  1 toggle @Test(groups = { "Functional" })
109    public void testStarsInFasta2() throws IOException
110    {
111  1 String uri;
112  1 FileParse fp = new FileParse(
113    uri = STARS_FA_FILE2.getAbsoluteFile().toString(),
114    DataSourceType.FILE);
115  1 assertValidFormat(FileFormat.Fasta, uri, fp);
116    }
117   
 
118  1 toggle @Test(groups = { "Functional" })
119    public void testGzipIo() throws IOException
120    {
121  1 String uri;
122  1 FileParse fp = new FileParse(
123    uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(),
124    DataSourceType.URL);
125  1 assertValidFormat(FileFormat.Fasta, uri, fp);
126    }
127   
 
128  1 toggle @Test(groups = { "Functional" })
129    public void testGziplocalFileIO() throws IOException
130    {
131  1 String filepath;
132  1 FileParse fp = new FileParse(
133    filepath = ALIGN_FILE.getAbsoluteFile().toString(),
134    DataSourceType.FILE);
135  1 assertValidFormat(FileFormat.Fasta, filepath, fp);
136    }
137   
 
138  1 toggle @Test(groups = { "Functional" })
139    public void testIsGzipInputStream() throws IOException
140    {
141  1 InputStream is = new FileInputStream(ALIGN_FILE);
142   
143    /*
144    * first try fails - FileInputStream does not support mark/reset
145    */
146  1 assertFalse(Platform.isGzipStream(is));
147   
148    /*
149    * wrap in a BufferedInputStream and try again
150    */
151  1 is = new BufferedInputStream(is, 16);
152  1 assertTrue(Platform.isGzipStream(is));
153   
154    /*
155    * check recognition of non-gzipped input
156    */
157  1 assertFalse(Platform.isGzipStream(new BufferedInputStream(
158    new ByteArrayInputStream("NOT A GZIP".getBytes()))));
159    }
160   
 
161  1 toggle @Test(groups = { "Functional" })
162    public void testNonGzipURLIO() throws IOException
163    {
164  1 String uri;
165  1 FileParse fp = new FileParse(
166    uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(),
167    DataSourceType.URL);
168  1 assertValidFormat(FileFormat.Fasta, uri, fp);
169    }
170   
 
171  1 toggle @Test(groups = { "Functional" })
172    public void testNonGziplocalFileIO() throws IOException
173    {
174  1 String filepath;
175  1 FileParse fp = new FileParse(
176    filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(),
177    DataSourceType.FILE);
178  1 assertValidFormat(FileFormat.Fasta, filepath, fp);
179    }
180    }