Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package jalview.io

File JalviewFileChooserTest.java

 

Code metrics

4
10
3
1
121
95
5
0.5
3.33
3
1.67

Classes

Class Line # Actions
JalviewFileChooserTest 10 10 5
1.0100%
 

Contributing tests

This file is covered by 26 tests. .

Source view

1    package jalview.io;
2   
3    import org.testng.Assert;
4    import org.testng.annotations.DataProvider;
5    import org.testng.annotations.Test;
6   
7    import jalview.bin.Cache;
8    import jalview.gui.AlignFrame;
9   
 
10    public class JalviewFileChooserTest
11    {
 
12  28 toggle @Test(groups = { "Functional" }, dataProvider = "propertiesAndFormats")
13    public void checkDefaultSaveFormat(String DEFAULT_SAVE_FILE_FORMAT,
14    String ALWAYS_USE_DEFAULT_SAVE_FORMAT,
15    FileFormat alignmentCurrentFormat,
16    FileFormat alignFrameLastSavedFormat,
17    String expectedDefaultFormatName)
18    {
19  28 String alignmentCurrentFormatName = alignmentCurrentFormat == null
20    ? null
21    : alignmentCurrentFormat.getName();
22   
23  28 AlignFrame.setLastAlignmentSavedFormat(alignFrameLastSavedFormat);
24   
25  28 setOrRemoveProperty(JalviewFileChooser.DEFAULT_SAVE_FORMAT_PROPERTY,
26    DEFAULT_SAVE_FILE_FORMAT);
27  28 setOrRemoveProperty(
28    JalviewFileChooser.ALWAYS_USE_DEFAULT_SAVED_FORMAT_PROPERTY,
29    ALWAYS_USE_DEFAULT_SAVE_FORMAT);
30   
31  28 String defaultFormat = JalviewFileChooser
32    .defaultSaveFileFormat(alignmentCurrentFormatName);
33   
34  28 Assert.assertEquals(defaultFormat, expectedDefaultFormatName,
35    "The calculated default format did not match the expected default format.");
36    }
37   
 
38  1 toggle @DataProvider(name = "propertiesAndFormats")
39    public Object[][] propertiesAndFormats()
40    {
41    /**
42    * String DEFAULT_SAVE_FILE_FORMAT, boolean/String
43    * ALWAYS_USE_DEFAULT_SAVE_FORMAT, FileFormat alignmentCurrentFormat,
44    * FileFormat alignFrameLastSavedFormat, String expectedDefaultFormat
45    */
46  1 return new Object[][] {
47    // no properties
48   
49    { null, null, null, null, FileFormat.Fasta.getName() },
50    { null, null, FileFormat.BLC, null, FileFormat.BLC.getName() },
51    { null, null, FileFormat.BLC, FileFormat.PIR,
52    FileFormat.BLC.getName() },
53    { null, null, null, FileFormat.PIR, FileFormat.Fasta.getName() },
54    // definite format property
55    { "Stockholm", null, null, null, FileFormat.Stockholm.getName() },
56    { "Stockholm", null, FileFormat.BLC, null,
57    FileFormat.BLC.getName() },
58    { "Stockholm", null, FileFormat.BLC, FileFormat.PIR,
59    FileFormat.BLC.getName() },
60    { "Stockholm", null, null, FileFormat.PIR,
61    FileFormat.Stockholm.getName() },
62    // always use definite format property
63    { "Stockholm", "true", null, null, FileFormat.Stockholm.getName() },
64    { "Stockholm", "true", FileFormat.BLC, null,
65    FileFormat.Stockholm.getName() },
66    { "Stockholm", "true", FileFormat.BLC, FileFormat.PIR,
67    FileFormat.Stockholm.getName() },
68    { "Stockholm", "true", null, FileFormat.PIR,
69    FileFormat.Stockholm.getName() },
70    // use last saved
71    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, null, null, null,
72    FileFormat.Fasta.getName() },
73    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, null,
74    FileFormat.BLC, null, FileFormat.BLC.getName() },
75    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, null,
76    FileFormat.BLC, FileFormat.PIR, FileFormat.BLC.getName() },
77    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, null, null,
78    FileFormat.PIR, FileFormat.PIR.getName() },
79    // always use last saved
80    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, "true", null,
81    null, FileFormat.Fasta.getName() },
82    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, "true",
83    FileFormat.BLC, null, FileFormat.BLC.getName() },
84    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, "true",
85    FileFormat.BLC, FileFormat.PIR, FileFormat.PIR.getName() },
86    { JalviewFileChooser.USE_LAST_SAVED_FORMAT_VALUE, "true", null,
87    FileFormat.PIR, FileFormat.PIR.getName() },
88   
89    // by extension
90    { "ALL_EXTENSIONS", null, null, null, "ALL_EXTENSIONS" },
91    { "ALL_EXTENSIONS", null, FileFormat.BLC, null,
92    FileFormat.BLC.getName() },
93    { "ALL_EXTENSIONS", null, FileFormat.BLC, FileFormat.PIR,
94    FileFormat.BLC.getName() },
95    { "ALL_EXTENSIONS", null, null, FileFormat.PIR, "ALL_EXTENSIONS" },
96    // always by extension
97    { "ALL_EXTENSIONS", "true", null, null, "ALL_EXTENSIONS" },
98    { "ALL_EXTENSIONS", "true", FileFormat.BLC, null,
99    "ALL_EXTENSIONS" },
100    { "ALL_EXTENSIONS", "true", FileFormat.BLC, FileFormat.PIR,
101    "ALL_EXTENSIONS" },
102    { "ALL_EXTENSIONS", "true", null, FileFormat.PIR,
103    "ALL_EXTENSIONS" },
104   
105    //
106    };
107    }
108   
 
109  56 toggle private static void setOrRemoveProperty(String key, String value)
110    {
111  56 if (value == null)
112    {
113  20 Cache.removeProperty(key);
114    }
115    else
116    {
117  36 Cache.setProperty(key, value);
118    }
119    }
120   
121    }