Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.io

File WindowsFileLoadAndSaveTest.java

 

Code metrics

0
12
3
1
93
45
3
0.25
4
3
1

Classes

Class Line # Actions
WindowsFileLoadAndSaveTest 48 12 3
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.io.File;
24    import java.io.IOException;
25    import java.nio.file.Files;
26    import java.nio.file.StandardCopyOption;
27   
28    import org.testng.Assert;
29    import org.testng.annotations.AfterClass;
30    import org.testng.annotations.BeforeClass;
31    import org.testng.annotations.Test;
32   
33    import jalview.datamodel.AlignmentI;
34    import jalview.gui.AlignFrame;
35    import jalview.gui.JvOptionPane;
36   
37    /**
38    * WindowsFileSaveTest simply opens an alignment file and then tries to save it.
39    * This failed in Windows from 2.11.0 to 2.11.1.6 due to a combination of the
40    * opening file handle being left open ad infinitum, causing the BackupFiles
41    * operation of moving the saved (temp) file onto the original filename to fail,
42    * but only in Windows. See: https://issues.jalview.org/browse/JAL-3628
43    * https://issues.jalview.org/browse/JAL-3703
44    * https://issues.jalview.org/browse/JAL-3935 These issues are really all fixed
45    * by JAL-3703 This test is to ensure it doesn't start again, but note that this
46    * test will only fail in Windows.
47    */
 
48    public class WindowsFileLoadAndSaveTest
49    {
50   
51    private final static String fileName = "examples" + File.separator
52    + "uniref50.fa";
53   
54    private final static String testFileName = fileName + "-TEST";
55   
 
56  1 toggle @BeforeClass(alwaysRun = true)
57    public void setUpJvOptionPane()
58    {
59  1 JvOptionPane.setInteractiveMode(false);
60  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61    }
62   
63    /**
64    * Test saving and re-reading in a specified format
65    *
66    * @throws IOException
67    */
 
68  1 toggle @Test(groups = { "Functional" })
69    public void loadAndSaveAlignment() throws IOException
70    {
71  1 File file = new File(fileName);
72  1 File testFile = new File(testFileName);
73  1 Files.copy(file.toPath(), testFile.toPath(),
74    StandardCopyOption.REPLACE_EXISTING);
75  1 FormatAdapter fa = new FormatAdapter();
76  1 AlignmentI a = fa.readFile(testFile, DataSourceType.FILE,
77    FileFormat.Fasta);
78   
79  1 AlignFrame af = new AlignFrame(a, 500, 500);
80  1 af.saveAlignment(testFileName, FileFormat.Fasta);
81   
82  1 Assert.assertTrue(af.isSaveAlignmentSuccessful());
83    }
84   
 
85  1 toggle @AfterClass(alwaysRun = true)
86    private void cleanupTmpFiles()
87    {
88  1 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
89    .getSavedBackupEntry();
90  1 BackupFilesTest.cleanupTmpFiles(testFileName, bfpe.suffix, bfpe.digits);
91    }
92   
93    }