JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / io / JalviewFileViewTest.java
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.assertEquals;
24 import static org.testng.Assert.assertNotNull;
25 import static org.testng.Assert.assertNotSame;
26 import static org.testng.Assert.assertNull;
27 import static org.testng.Assert.assertSame;
28
29 import java.io.File;
30
31 import javax.swing.ImageIcon;
32
33 import org.testng.annotations.Test;
34
35 public class JalviewFileViewTest
36 {
37   @Test(groups = "Functional")
38   public void testGetImageIcon()
39   {
40     JalviewFileView jfv = new JalviewFileView();
41     ImageIcon icon1 = jfv.getImageIcon("/images/file.png");
42     ImageIcon icon2 = jfv.getImageIcon("/images/file.png");
43     ImageIcon icon3 = jfv.getImageIcon("/images/dna.png");
44     ImageIcon icon4 = jfv.getImageIcon("/images/dna.png");
45
46     /*
47      * verify a single image object is served per file path
48      */
49     assertNotNull(icon1);
50     assertSame(icon1, icon2);
51     assertNotNull(icon3);
52     assertSame(icon3, icon4);
53     assertNotSame(icon1, icon3);
54
55     assertNull(jfv.getImageIcon("/images/nosuchfile.png"));
56     assertNull(jfv.getImageIcon("images/file.png"));
57   }
58
59   @Test(groups = "Functional")
60   public void testGetExtension()
61   {
62     assertEquals(JalviewFileView.getExtension(new File("text.txt")), "txt");
63     assertEquals(JalviewFileView.getExtension(
64             new File("/a/longer/file/path/text.png.TXT")), "txt");
65     assertNull(JalviewFileView
66             .getExtension(new File("/a/longer/file/path/text.")));
67     assertNull(JalviewFileView
68             .getExtension(new File("/a/longer/file/path/text")));
69   }
70
71   @Test(groups = "Functional")
72   public void testGetTypeDescription()
73   {
74     JalviewFileView jfw = new JalviewFileView();
75     assertEquals(jfw.getTypeDescription(new File("uniref50.fa")),
76             "Fasta file");
77     assertEquals(jfw.getTypeDescription(new File("uniref50.fasta")),
78             "Fasta file");
79     assertEquals(jfw.getTypeDescription(new File("uniref50.MFA")),
80             "Fasta file");
81     assertEquals(jfw.getTypeDescription(new File("uniref50.fastQ")),
82             "Fasta file");
83     assertEquals(jfw.getTypeDescription(new File("uniref50.pfam")),
84             "PFAM file");
85     assertEquals(jfw.getTypeDescription(new File("uniref50.stk")),
86             "Stockholm file");
87     assertEquals(jfw.getTypeDescription(new File("uniref50.sto")),
88             "Stockholm file");
89     assertEquals(jfw.getTypeDescription(new File("uniref50.pir")),
90             "PIR file");
91     assertEquals(jfw.getTypeDescription(new File("uniref50.blc")),
92             "BLC file");
93     assertEquals(jfw.getTypeDescription(new File("uniref50.amsa")),
94             "AMSA file");
95     assertEquals(jfw.getTypeDescription(new File("uniref50.html")),
96             "HTML file");
97     assertNull(jfw.getTypeDescription(new File("uniref50.htm")));
98     assertEquals(jfw.getTypeDescription(new File("uniref50.xml")),
99             "RNAML file");
100     assertEquals(jfw.getTypeDescription(new File("uniref50.rnaml")),
101             "RNAML file");
102     assertEquals(jfw.getTypeDescription(new File("uniref50.json")),
103             "JSON file");
104     assertEquals(jfw.getTypeDescription(new File("uniref50.pileup")),
105             "PileUp file");
106     assertEquals(jfw.getTypeDescription(new File("uniref50.msf")),
107             "MSF file");
108     assertEquals(jfw.getTypeDescription(new File("uniref50.aln")),
109             "Clustal file");
110     assertEquals(jfw.getTypeDescription(new File("uniref50.phy")),
111             "PHYLIP file");
112     assertEquals(jfw.getTypeDescription(new File("uniref50.gff2")),
113             "GFF or Jalview features file");
114     assertEquals(jfw.getTypeDescription(new File("uniref50.gff3")),
115             "GFF or Jalview features file");
116     assertEquals(jfw.getTypeDescription(new File("uniref50.pdb")),
117             "PDB file");
118     assertEquals(jfw.getTypeDescription(new File("uniref50.ent")),
119             "PDB file");
120     assertEquals(jfw.getTypeDescription(new File("uniref50.cif")),
121             "mmCIF file");
122     assertEquals(jfw.getTypeDescription(new File("uniref50.jvp")),
123             "Jalview file");
124     assertEquals(jfw.getTypeDescription(new File("uniref50.jar")),
125             "Jalview file (old)");
126   }
127 }