Clover icon

Coverage Report

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

File AlignCalcManagerTest.java

 

Code metrics

0
34
7
1
170
101
8
0.24
4.86
7
1.14

Classes

Class Line # Actions
AlignCalcManagerTest 46 34 8
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.workers;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.api.AlignCalcManagerI2;
28    import jalview.api.AlignCalcWorkerI;
29    import jalview.api.FeatureRenderer;
30    import jalview.datamodel.Alignment;
31    import jalview.datamodel.AlignmentAnnotation;
32    import jalview.datamodel.AlignmentI;
33    import jalview.datamodel.Annotation;
34    import jalview.datamodel.Sequence;
35    import jalview.datamodel.SequenceI;
36    import jalview.gui.AlignFrame;
37    import jalview.gui.JvOptionPane;
38   
39    import java.util.Collections;
40    import java.util.List;
41   
42    import org.testng.annotations.BeforeClass;
43    import org.testng.annotations.BeforeMethod;
44    import org.testng.annotations.Test;
45   
 
46    public class AlignCalcManagerTest
47    {
48   
 
49  1 toggle @BeforeClass(alwaysRun = true)
50    public void setUpJvOptionPane()
51    {
52  1 JvOptionPane.setInteractiveMode(false);
53  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54    }
55   
56    private AlignFrame alignFrame;
57   
58    /**
59    * Test the method that removes a worker associated with an annotation,
60    * provided the worker is marked as 'deletable' (some workers should continue
61    * to run even when their results are no longer displayed)
62    */
 
63  1 toggle @Test(groups = "Functional")
64    public void testRemoveWorkerForAnnotation()
65    {
66  1 AlignCalcManagerI2 acm = alignFrame.getViewport().getCalcManager();
67  1 final AlignmentAnnotation ann1 = new AlignmentAnnotation("Ann1",
68    "desc", new Annotation[] {});
69  1 final AlignmentAnnotation ann2 = new AlignmentAnnotation("Ann2",
70    "desc", new Annotation[] {});
71   
72    /*
73    * make two workers for ann1, one deletable, one not
74    * and no worker for ann2
75    */
76  1 AlignCalcWorkerI worker1 = makeWorker(ann1, true);
77  1 AlignCalcWorkerI worker2 = makeWorker(ann1, false);
78   
79    /*
80    * The new workers will get run each in their own thread.
81    * We can't tell here whether they have finished, or not yet started.
82    * They have to finish to be 'seen' by getRegisteredWorkersOfClass()
83    * registerWorker adds to the 'restartable' list but
84    * getRegisteredWorkers reads from the 'canUpdate' list
85    * (which is only updated after a worker has run) - why?
86    * So just give workers time to start and finish
87    */
88  1 synchronized (this)
89    {
90  1 try
91    {
92  1 wait(100);
93    } catch (InterruptedException e)
94    {
95    //
96    }
97    }
98   
99  1 List<AlignCalcWorkerI> workers = acm.getWorkersOfClass(worker1.getClass());
100  1 assertEquals(2, workers.size());
101  1 assertTrue(workers.contains(worker1));
102  1 assertTrue(workers.contains(worker2));
103  1 assertFalse(acm.isDisabled(worker1));
104  1 assertFalse(acm.isDisabled(worker2));
105   
106    /*
107    * remove workers for ann2 (there aren't any)
108    */
109  1 acm.removeWorkerForAnnotation(ann2);
110  1 assertTrue(acm.getWorkersOfClass(worker1.getClass()).contains(worker1));
111  1 assertTrue(acm.getWorkersOfClass(worker1.getClass()).contains(worker2));
112  1 assertFalse(acm.isDisabled(worker1));
113  1 assertFalse(acm.isDisabled(worker2));
114   
115    /*
116    * remove worker2 for ann1
117    * - should delete worker1 but not worker2
118    */
119  1 acm.removeWorkerForAnnotation(ann1);
120  1 assertEquals(1, acm.getWorkersOfClass(worker1.getClass()).size());
121  1 assertTrue(acm.getWorkersOfClass(worker1.getClass()).contains(worker2));
122  1 assertFalse(acm.isDisabled(worker1));
123  1 assertFalse(acm.isDisabled(worker2));
124    }
125   
126    /**
127    * Make a worker linked to the given annotation
128    *
129    * @param ann
130    * @param deletable
131    * @return
132    */
 
133  2 toggle AnnotationWorker makeWorker(final AlignmentAnnotation ann,
134    final boolean deletable)
135    {
136  2 AnnotationProviderI annotationProvider = new AnnotationProviderI()
137    {
 
138  2 toggle @Override
139    public List<AlignmentAnnotation> calculateAnnotation(AlignmentI al,
140    FeatureRenderer fr)
141    {
142  2 return Collections.singletonList(ann);
143    }
144    };
145  2 return new AnnotationWorker(alignFrame.getViewport(),
146    alignFrame.alignPanel, annotationProvider)
147    {
 
148  2 toggle @Override
149    public boolean isDeletable()
150    {
151  2 return deletable;
152    }
153   
 
154  4 toggle @Override
155    public boolean involves(AlignmentAnnotation ann1)
156    {
157  4 return ann == ann1;
158    }
159    };
160    }
161   
 
162  1 toggle @BeforeMethod(alwaysRun = true)
163    public void setUp()
164    {
165  1 AlignmentI al = new Alignment(new SequenceI[] { new Sequence("Seq1",
166    "ABC") });
167  1 al.setDataset(null);
168  1 alignFrame = new AlignFrame(al, 3, 1);
169    }
170    }