import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
+import java.awt.Font;
+import java.awt.FontMetrics;
+
+import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Sequence;
+import org.mockito.Mockito;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class AnnotationLabelsTest
AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
{ aa, aa2 }), "IUPredWS Long, IUPredWS Short");
}
+
+
+ @Test(groups = "Functional", dataProvider = "TestDrawLabelsData")
+ public void testDrawLabels(AlignmentAnnotation[] annotations, int expectedWidth) {
+
+ FontMetrics mockFontMetrics = Mockito.mock(FontMetrics.class);
+ Mockito.when(mockFontMetrics.getHeight()).thenReturn(10);
+ Mockito.when(mockFontMetrics.getDescent()).thenReturn(2);
+ Mockito.when(mockFontMetrics.stringWidth(Mockito.anyString())).thenAnswer(invocation -> {
+ String str = invocation.getArgument(0);
+ return str.length() * 7;
+ });
+
+ Font mockFont = new Font("Arial", Font.PLAIN, 12);
+ Mockito.when(mockFontMetrics.getFont()).thenReturn(mockFont);
+
+ boolean actuallyDraw = false;
+ boolean clip = false;
+ int width = 200;
+ boolean forGUI = true;
+ boolean includeHidden = true;
+
+ AlignViewport av = Mockito.mock(AlignViewport.class);
+ Alignment alignment = Mockito.mock(Alignment.class);
+ Mockito.when(alignment.getAlignmentAnnotation()).thenReturn(annotations);
+ Mockito.when(av.getAlignment()).thenReturn(alignment);
+ Mockito.when(av.getFont()).thenReturn(new Font("Arial", Font.PLAIN, 12)); // Mock font
+
+ AnnotationLabels annotationLabels = new AnnotationLabels(av);
+
+ int resultWidth = annotationLabels.drawLabels(null, clip, width, actuallyDraw, forGUI, mockFontMetrics, includeHidden);
+
+ assertEquals(resultWidth, expectedWidth);
+ Mockito.reset(mockFontMetrics, av, alignment);
+ }
+
+ @DataProvider(name = "TestDrawLabelsData")
+ public static Object[][] provideSecondaryStructureAnnotation() {
+
+
+ Sequence s1 = new Sequence("Seq1", "MLRIQST");
+ Sequence s2 = new Sequence("Sequence2", "MLRIQST");
+
+ String label1 = "Label1";
+ String label2 = "Label_2";
+ String label3 = "Label_three";
+ String description1 = "Desc1";
+ String description2 = "<html><h1>Desc_2</h1></html>";
+ String description3 = "Description_three";
+
+
+ AlignmentAnnotation a1 = new AlignmentAnnotation(label1, description1, null);
+ AlignmentAnnotation a2 = new AlignmentAnnotation(label2, description2, null);
+ AlignmentAnnotation a3 = new AlignmentAnnotation(label3, description3, null);
+ AlignmentAnnotation a4 = new AlignmentAnnotation(label3, description3, null);
+ AlignmentAnnotation a5 = new AlignmentAnnotation(label1, description2, null);
+ AlignmentAnnotation a6 = new AlignmentAnnotation(label1, description2, null);
+
+ a1.sequenceRef = s1;
+ a2.sequenceRef = s1;
+ a3.sequenceRef = s1;
+ a4.sequenceRef = s2;
+ a5.sequenceRef = s1;
+ a6.sequenceRef = s2;
+
+ a1.visible = true;
+ a2.visible = true;
+ a3.visible = true;
+ a4.visible = true;
+ a5.visible = true;
+ a6.visible = true;
+
+ return new Object[][]{
+
+ {new AlignmentAnnotation[]{a2, a2, a1}, 7 * ((s1.getName()+" ").length() + label2.length()) + 3},
+ {new AlignmentAnnotation[]{a1, a2, a3}, 7 * (label3.length()) + 3}, //Different labels and descriptions, same sequenceRef
+ {new AlignmentAnnotation[]{a1, a2, a4}, 7 * ((s2.getName()+" ").length() + label3.length()) + 3}, //Different labels, descriptions, sequenceRef
+ {new AlignmentAnnotation[]{a1, a1, a1}, 7 * ((s1.getName()+" ").length() + label1.length()) + 3}, //Same labels, descriptions, sequenceRef
+ {new AlignmentAnnotation[]{a1, a1, a2}, 7 * ((s1.getName()+" ").length() + label1.length()) + 3},
+ {new AlignmentAnnotation[]{a1, a5, a2}, 7 * ((s1.getName()+" ").length() + "Desc_2".length()) + 3}, //same labels and sequence, different description
+ {new AlignmentAnnotation[]{a1, a6, a2}, 7 * ((s2.getName()+" ").length() + "Desc_2".length()) + 3}, //same labels and sequence, different description
+
+ };
+ }
}