Clover icon

jalviewX

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

File FileFormatsTest.java

 

Code metrics

0
62
9
1
167
127
9
0.15
6.89
9
1

Classes

Class Line # Actions
FileFormatsTest 16 62 9 0
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

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