1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertNotNull; |
25 |
|
import static org.testng.AssertJUnit.fail; |
26 |
|
|
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.gui.JvOptionPane; |
30 |
|
|
31 |
|
import java.io.IOException; |
32 |
|
import java.util.ArrayList; |
33 |
|
import java.util.List; |
34 |
|
|
35 |
|
import org.testng.annotations.BeforeClass; |
36 |
|
import org.testng.annotations.DataProvider; |
37 |
|
import org.testng.annotations.Test; |
38 |
|
|
|
|
| 92.7% |
Uncovered Elements: 3 (41) |
Complexity: 10 |
Complexity Density: 0.31 |
|
39 |
|
public class FormatAdapterTest |
40 |
|
{ |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
42 |
1 |
@BeforeClass(alwaysRun = true)... |
43 |
|
public void setUpJvOptionPane() |
44 |
|
{ |
45 |
1 |
JvOptionPane.setInteractiveMode(false); |
46 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@throws |
53 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
1PASS
|
|
54 |
11 |
@Test(groups = { "Functional" }, dataProvider = "formats")... |
55 |
|
public void testRoundTrip(FileFormatI format) throws IOException |
56 |
|
{ |
57 |
11 |
try |
58 |
|
{ |
59 |
11 |
AlignmentI al = new FormatAdapter().readFile("examples/uniref50.fa", |
60 |
|
DataSourceType.FILE, FileFormat.Fasta); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
11 |
char gap = al.getGapCharacter(); |
67 |
11 |
assertNotNull(al); |
68 |
|
|
69 |
11 |
SequenceI[] seqs = al.getSequencesArray(); |
70 |
11 |
String formatted = new FormatAdapter().formatSequences(format, al, |
71 |
|
false); |
72 |
|
|
73 |
11 |
AlignmentI reloaded = new FormatAdapter().readFile(formatted, |
74 |
|
DataSourceType.PASTE, format); |
75 |
11 |
List<SequenceI> reread = reloaded.getSequences(); |
76 |
11 |
assertEquals("Wrong number of reloaded sequences", seqs.length, |
77 |
|
reread.size()); |
78 |
|
|
79 |
11 |
int i = 0; |
80 |
11 |
for (SequenceI seq : reread) |
81 |
|
{ |
82 |
165 |
String sequenceString = seq.getSequenceAsString(); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
165 |
sequenceString = adjustForGapTreatment(sequenceString, gap, format); |
88 |
165 |
assertEquals(String.format("Sequence %d: %s", i, seqs[i].getName()), |
89 |
|
seqs[i].getSequenceAsString(), sequenceString); |
90 |
165 |
i++; |
91 |
|
} |
92 |
|
} catch (IOException e) |
93 |
|
{ |
94 |
0 |
fail(String.format("Format %s failed with %s", format, |
95 |
|
e.getMessage())); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
@param |
106 |
|
|
107 |
|
@param |
108 |
|
@return |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
110 |
165 |
String adjustForGapTreatment(String sequenceString, char gap,... |
111 |
|
FileFormatI format) |
112 |
|
{ |
113 |
165 |
if (FileFormat.MSF.equals(format)) |
114 |
|
{ |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
15 |
sequenceString = sequenceString.replace('.', gap); |
120 |
|
} |
121 |
165 |
return sequenceString; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@return |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.4 |
|
130 |
1 |
@DataProvider(name = "formats")... |
131 |
|
static Object[][] getFormats() |
132 |
|
{ |
133 |
1 |
List<FileFormatI> both = new ArrayList<FileFormatI>(); |
134 |
1 |
for (FileFormatI format : FileFormats.getInstance().getFormats()) |
135 |
|
{ |
136 |
22 |
if (format.isReadable() && format.isWritable() |
137 |
|
&& format.isTextFormat()) |
138 |
|
{ |
139 |
11 |
both.add(format); |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
1 |
Object[][] formats = new Object[both.size()][]; |
144 |
1 |
int i = 0; |
145 |
1 |
for (FileFormatI format : both) |
146 |
|
{ |
147 |
11 |
formats[i] = new Object[] { format }; |
148 |
11 |
i++; |
149 |
|
} |
150 |
1 |
return formats; |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
@throws |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
158 |
0 |
@Test(groups = { "Functional" }, enabled = false)... |
159 |
|
public void testOneFormatRoundTrip() throws IOException |
160 |
|
{ |
161 |
0 |
testRoundTrip(FileFormat.Json); |
162 |
|
} |
163 |
|
} |