Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.io

File FileFormatsTest.java

 

Code metrics

0
63
9
1
191
131
9
0.14
7
9
1

Classes

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