Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.util

File ParseHtmlBodyAndLinksTest.java

 

Code metrics

0
24
5
1
105
72
5
0.21
4.8
5
1

Classes

Class Line # Actions
ParseHtmlBodyAndLinksTest 30 24 5 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

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.util;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24   
25    import jalview.gui.JvOptionPane;
26   
27    import org.testng.annotations.BeforeClass;
28    import org.testng.annotations.Test;
29   
 
30    public class ParseHtmlBodyAndLinksTest
31    {
32   
 
33  1 toggle @BeforeClass(alwaysRun = true)
34    public void setUpJvOptionPane()
35    {
36  1 JvOptionPane.setInteractiveMode(false);
37  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
38    }
39   
 
40  1 toggle @Test(groups = { "Functional" })
41    public void testParseHtml_noLinks()
42    {
43  1 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
44    "<html>something here</html>", false, "\n");
45  1 assertEquals("something here", testee.getContent());
46  1 assertEquals("something here", testee.getNonHtmlContent());
47   
48    // second argument makes no difference??
49  1 testee = new ParseHtmlBodyAndLinks("<html>something here</html>", true,
50    "\n");
51  1 assertEquals("something here", testee.getContent());
52  1 assertEquals("something here", testee.getNonHtmlContent());
53    }
54   
 
55  1 toggle @Test(groups = { "Functional" })
56    public void testParseHtml_withLinks()
57    {
58  1 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
59    "<html>Please click <a href=\"http://www.nowhere.com\">on this</a> to learn more about <a href=\"http://www.somewhere.com/here\">this</a></html>",
60    false, "\n");
61  1 assertEquals(
62    "Please click on this%LINK% to learn more about this%LINK%",
63    testee.getContent());
64  1 assertEquals(
65    "Please click on this%LINK% to learn more about this%LINK%",
66    testee.getNonHtmlContent());
67  1 assertEquals(2, testee.getLinks().size());
68  1 assertEquals("on this|http://www.nowhere.com", testee.getLinks().get(0));
69  1 assertEquals("this|http://www.somewhere.com/here", testee.getLinks()
70    .get(1));
71    }
72   
 
73  1 toggle @Test(groups = { "Functional" })
74    public void testParseHtml_withLinksWithParameters()
75    {
76  1 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
77    "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human\">on this</a> to learn more</html>",
78    false, "\n");
79  1 assertEquals("Please click on this%LINK% to learn more",
80    testee.getContent());
81  1 assertEquals("Please click on this%LINK% to learn more",
82    testee.getNonHtmlContent());
83  1 assertEquals(1, testee.getLinks().size());
84  1 assertEquals("on this|http://www.nowhere.com?id=234&taxon=human",
85    testee.getLinks().get(0));
86    }
87   
 
88  1 toggle @Test(groups = { "Functional" })
89    public void testParseHtml_withLinksWithEncoding()
90    {
91  1 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
92    "<html>Please click <a href=\"http://www.nowhere.com?id=234&amp;taxon=human&amp;id&gt;3&amp;id&lt;10\">on this</a> to learn &amp;&lt;&gt;more</html>",
93    false, "\n");
94    // html encoding in the text body is translated
95  1 assertEquals("Please click on this%LINK% to learn &<>more",
96    testee.getContent());
97  1 assertEquals("Please click on this%LINK% to learn &<>more",
98    testee.getNonHtmlContent());
99  1 assertEquals(1, testee.getLinks().size());
100    // html encoding in the url links is not translated
101  1 assertEquals(
102    "on this|http://www.nowhere.com?id=234&amp;taxon=human&amp;id&gt;3&amp;id&lt;10",
103    testee.getLinks().get(0));
104    }
105    }