Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.io

File FileFormatsTest.java

 

Code metrics

0
62
9
1
191
129
9
0.15
6.89
9
1

Classes

Class Line # Actions
FileFormatsTest 38 62 9
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 java.util.Locale;
24   
25    import static org.testng.Assert.assertEquals;
26    import static org.testng.Assert.assertFalse;
27    import static org.testng.Assert.assertNotEquals;
28    import static org.testng.Assert.assertNull;
29    import static org.testng.Assert.assertSame;
30    import static org.testng.Assert.assertTrue;
31   
32    import java.util.Iterator;
33   
34    import org.testng.annotations.AfterMethod;
35    import org.testng.annotations.BeforeMethod;
36    import org.testng.annotations.Test;
37   
 
38    public class FileFormatsTest
39    {
 
40  0 toggle @AfterMethod(alwaysRun = true)
41    public void tearDown()
42    {
43  0 FileFormats.getInstance().reset();
44    }
45   
 
46  0 toggle @BeforeMethod(alwaysRun = true)
47    public void setUp()
48    {
49  0 FileFormats.getInstance().reset();
50    }
51   
 
52  0 toggle @Test(groups = "Functional")
53    public void testIsIdentifiable()
54    {
55  0 FileFormats formats = FileFormats.getInstance();
56  0 assertTrue(formats
57    .isIdentifiable(formats.forName(FileFormat.Fasta.getName())));
58  0 assertTrue(formats
59    .isIdentifiable(formats.forName(FileFormat.MMCif.getName())));
60  0 assertTrue(formats
61    .isIdentifiable(formats.forName(FileFormat.Jnet.getName())));
62  0 assertTrue(formats
63    .isIdentifiable(formats.forName(FileFormat.Jalview.getName())));
64    // GenBank/ENA
65  0 assertFalse(formats.isIdentifiable(null));
66   
67    /*
68    * remove and re-add a format: it is still 'identifiable'
69    */
70  0 formats.deregisterFileFormat(FileFormat.Fasta.getName());
71  0 assertNull(formats.forName(FileFormat.Fasta.getName()));
72  0 formats.registerFileFormat(FileFormat.Fasta);
73  0 assertSame(FileFormat.Fasta,
74    formats.forName(FileFormat.Fasta.getName()));
75  0 assertTrue(formats.isIdentifiable(FileFormat.Fasta));
76    }
77   
 
78  0 toggle @Test(groups = "Functional")
79    public void testGetReadableFormats()
80    {
81  0 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview]";
82  0 FileFormats formats = FileFormats.getInstance();
83  0 assertEquals(formats.getReadableFormats().toString(), expected);
84    }
85   
 
86  0 toggle @Test(groups = "Functional")
87    public void testGetWritableFormats()
88    {
89  0 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
90  0 FileFormats formats = FileFormats.getInstance();
91  0 assertEquals(formats.getWritableFormats(true).toString(), expected);
92  0 expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Jalview]";
93  0 assertEquals(formats.getWritableFormats(false).toString(), expected);
94    }
95   
 
96  0 toggle @Test(groups = "Functional")
97    public void testDeregisterFileFormat()
98    {
99  0 String writable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
100  0 String readable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview]";
101  0 FileFormats formats = FileFormats.getInstance();
102  0 assertEquals(formats.getWritableFormats(true).toString(), writable);
103  0 assertEquals(formats.getReadableFormats().toString(), readable);
104   
105  0 formats.deregisterFileFormat(FileFormat.Fasta.getName());
106  0 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
107  0 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview]";
108  0 assertEquals(formats.getWritableFormats(true).toString(), writable);
109  0 assertEquals(formats.getReadableFormats().toString(), readable);
110   
111    /*
112    * re-register the format: it gets added to the end of the list
113    */
114  0 formats.registerFileFormat(FileFormat.Fasta);
115  0 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Fasta]";
116  0 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview, Fasta]";
117  0 assertEquals(formats.getWritableFormats(true).toString(), writable);
118  0 assertEquals(formats.getReadableFormats().toString(), readable);
119    }
120   
 
121  0 toggle @Test(groups = "Functional")
122    public void testForName()
123    {
124  0 FileFormats formats = FileFormats.getInstance();
125  0 for (FileFormatI ff : FileFormat.values())
126    {
127  0 assertSame(ff, formats.forName(ff.getName()));
128  0 assertSame(ff,
129    formats.forName(ff.getName().toUpperCase(Locale.ROOT)));
130  0 assertSame(ff,
131    formats.forName(ff.getName().toLowerCase(Locale.ROOT)));
132    }
133  0 assertNull(formats.forName(null));
134  0 assertNull(formats.forName("rubbish"));
135    }
136   
 
137  0 toggle @Test(groups = "Functional")
138    public void testRegisterFileFormat()
139    {
140  0 FileFormats formats = FileFormats.getInstance();
141  0 assertSame(FileFormat.MMCif,
142    formats.forName(FileFormat.MMCif.getName()));
143  0 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
144   
145    /*
146    * deregister mmCIF format
147    */
148  0 formats.deregisterFileFormat(FileFormat.MMCif.getName());
149  0 assertNull(formats.forName(FileFormat.MMCif.getName()));
150   
151    /*
152    * re-register mmCIF format
153    * it is reinstated (still 'identifiable')
154    */
155  0 formats.registerFileFormat(FileFormat.MMCif);
156  0 assertSame(FileFormat.MMCif,
157    formats.forName(FileFormat.MMCif.getName()));
158  0 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
159    // repeating does nothing
160  0 formats.registerFileFormat(FileFormat.MMCif);
161  0 assertSame(FileFormat.MMCif,
162    formats.forName(FileFormat.MMCif.getName()));
163    }
164   
 
165  0 toggle @Test(groups = "Functional")
166    public void testGetFormats()
167    {
168    /*
169    * verify the list of file formats registered matches the enum values
170    */
171  0 FileFormats instance = FileFormats.getInstance();
172  0 Iterator<FileFormatI> formats = instance.getFormats().iterator();
173  0 FileFormatI[] builtIn = FileFormat.values();
174   
175  0 for (FileFormatI ff : builtIn)
176    {
177  0 assertSame(ff, formats.next());
178    }
179  0 assertFalse(formats.hasNext());
180   
181    /*
182    * remove the first format, check it is no longer in
183    * the list of formats
184    */
185  0 String firstFormatName = instance.getFormats().iterator().next()
186    .getName();
187  0 instance.deregisterFileFormat(firstFormatName);
188  0 assertNotEquals(instance.getFormats().iterator().next().getName(),
189    firstFormatName);
190    }
191    }