Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File FileIOTester.java

 

Code metrics

0
23
10
1
140
90
10
0.43
2.3
10
1

Classes

Class Line # Actions
FileIOTester 37 23 10 0
1.0100%
 

Contributing tests

This file is covered by 6 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 jalview.gui.JvOptionPane;
24   
25    import java.io.File;
26    import java.io.IOException;
27   
28    import org.testng.AssertJUnit;
29    import org.testng.annotations.AfterClass;
30    import org.testng.annotations.BeforeClass;
31    import org.testng.annotations.Test;
32   
33    /**
34    * @author jimp
35    *
36    */
 
37    public class FileIOTester
38    {
39   
 
40  1 toggle @BeforeClass(alwaysRun = true)
41    public void setUpJvOptionPane()
42    {
43  1 JvOptionPane.setInteractiveMode(false);
44  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45    }
46   
47    /**
48    * @throws java.lang.Exception
49    */
 
50  1 toggle @BeforeClass(alwaysRun = true)
51    public static void setUpBeforeClass() throws Exception
52    {
53    }
54   
55    /**
56    * @throws java.lang.Exception
57    */
 
58  1 toggle @AfterClass(alwaysRun = true)
59    public static void tearDownAfterClass() throws Exception
60    {
61    }
62   
63    // TODO: make a better/more comprehensive test harness for identify/io
64   
65    final static File ALIGN_FILE = new File(
66    "test/jalview/io/test_gz_fasta.gz");
67   
68    final static File NOTGZALIGN_FILE = new File(
69    "test/jalview/io/test_gz_fasta_notgz.gz");
70   
71    final static File STARS_FA_FILE1 = new File(
72    "test/jalview/io/test_fasta_stars.fa");
73   
74    final static File STARS_FA_FILE2 = new File(
75    "test/jalview/io/test_fasta_stars2.fa");
76   
 
77  6 toggle private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)
78    throws FileFormatException
79    {
80  6 AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
81    fp.isValid());
82  6 FileFormatI type = new IdentifyFile().identify(fp);
83  6 AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt
84    + "' identified as '" + type + "'", type, fmt);
85    }
86   
 
87  1 toggle @Test(groups = { "Functional" })
88    public void testStarsInFasta1() throws IOException
89    {
90  1 String uri;
91  1 FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile()
92    .toString(), DataSourceType.FILE);
93  1 assertValidFormat(FileFormat.Fasta, uri, fp);
94    }
95   
 
96  1 toggle @Test(groups = { "Functional" })
97    public void testStarsInFasta2() throws IOException
98    {
99  1 String uri;
100  1 FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile()
101    .toString(), DataSourceType.FILE);
102  1 assertValidFormat(FileFormat.Fasta, uri, fp);
103    }
104   
 
105  1 toggle @Test(groups = { "Functional" })
106    public void testGzipIo() throws IOException
107    {
108  1 String uri;
109  1 FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI()
110    .toString(), DataSourceType.URL);
111  1 assertValidFormat(FileFormat.Fasta, uri, fp);
112    }
113   
 
114  1 toggle @Test(groups = { "Functional" })
115    public void testGziplocalFileIO() throws IOException
116    {
117  1 String filepath;
118  1 FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile()
119    .toString(), DataSourceType.FILE);
120  1 assertValidFormat(FileFormat.Fasta, filepath, fp);
121    }
122   
 
123  1 toggle @Test(groups = { "Functional" })
124    public void testNonGzipURLIO() throws IOException
125    {
126  1 String uri;
127  1 FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile()
128    .toURI().toString(), DataSourceType.URL);
129  1 assertValidFormat(FileFormat.Fasta, uri, fp);
130    }
131   
 
132  1 toggle @Test(groups = { "Functional" })
133    public void testNonGziplocalFileIO() throws IOException
134    {
135  1 String filepath;
136  1 FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE
137    .getAbsoluteFile().toString(), DataSourceType.FILE);
138  1 assertValidFormat(FileFormat.Fasta, filepath, fp);
139    }
140    }