Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.testng.Assert;
- import org.testng.annotations.Test;
- public class HtmlShortenerTest {
- private static Logger log = LoggerFactory.getLogger(HtmlShortenerTest.class);
- @Test(groups = { "enabled" })
- public void test(){
- final List<TestCase> testCases = getTestCases();
- for (TestCase test : testCases){
- log.debug("Doing test for test case: {}", test);
- HtmlShortener htmlShortener = new HtmlShortener(test.getTestString(), test.getCutPoint());
- final String cutString = htmlShortener.cut();
- Assert.assertEquals(cutString, test.getExpectedString());
- }
- }
- private List<TestCase> getTestCases() {
- List<TestCase> testCases = new LinkedList<TestCase>();
- testCases.add(new TestCase(
- "<html><head></head><body>123456789</body></html>",
- "<html><head></head><body>123456</body></html>",
- 6
- ));
- testCases.add(new TestCase(
- "<h2><a href=\"http://www.repubblica.it/spettacoli-e-cultura/2012/05/01/news/concertone_primo_maggio-34286609/\" target=\"_self\" title=\"\">\"Speranza, passione e futuro\"<br>Primo maggio in musica</a><a href=\"javascript:window.open('http://www.repubblica.it/static/popup/2012/primo-maggio.html','','width=645,height=570,scrollbars=no');void(0);\"><span style=\"color: rgb(153, 0, 0);\"><br></span></a><a href=\"http://www.repubblica.it/spettacoli-e-cultura/2012/05/01/news/concertone_primo_maggio-34286609/\" target=\"_self\" title=\"\"> </a></h2>\"",
- "<h2><a href=\"http://www.repubblica.it/spettacoli-e-cultura/2012/05/01/news/concertone_primo_maggio-34286609/\" target=\"_self\" title=\"\">\"Speranza, passione </a></h2>",
- 20
- ));
- testCases.add(new TestCase(
- "<div class=\"s9OtherItems\" style=\"float: left; width: 100%\"><div class=\"fluid asin s9a0\" style=\"float: left; width: 33.1%\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B007IZ1Q5S/ref=s9_pop_gw_g351_ir01?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Hunger Games (Italian edition) (Chrysalide)\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/51fVBD%2Bkm4L._SL135_.jpg\" alt=\"\" width=\"88\" height=\"135\"></div><span class=\"s9TitleText\">Hunger Games</span></a><div class=\"t11\">Suzanne Collins, F. Paracchini, S...</div><div class=\"gry t11 nt\">Formato Kindle</div><span class=\"s9Price red t14\">EUR 6,99</span></div></div></div><div class=\"fluid asin s9a1\" style=\"float: left; width: 33.1%\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B004445JHM/ref=s9_pop_gw_g23_ir02?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Western Digital WDBACY5000ABL MY Passport Essential HardDisk\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/31oyxKno2CL._SL135_.jpg\" alt=\"\" width=\"135\" height=\"77\" style=\"margin-top: 29px; margin-bottom:29px;\"></div><span class=\"s9TitleText\">Western Digital WDBACY5000ABL MY...</span></a><br clear=\"none\"><span class=\"listprice gry t11\">EUR 103,27</span> <span class=\"s9Price red t14\">EUR 81,65</span></div></div></div><div class=\"fluid asin s9a2\" style=\"float: left; width: 33.1%\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B005890FUI/ref=s9_pop_gw_g349_ir03?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Kindle Touch: dispositivo di lettura Wi-Fi, schermo touch da 6" a inchiostro elettronico\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/41JpsttW8CL._SL135_.jpg\" alt=\"\" width=\"135\" height=\"135\"></div><span class=\"s9TitleText\">Kindle Touch: dispositivo di lettura...</span></a><br clear=\"none\"><div class=\"t11\">Amazon</div><span class=\"s9Price red t14\">EUR 129,00</span></div></div></div><div class=\"fluid asin s9a3\" style=\"float: left; width: 33.1%; display: none\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/8804614870/ref=s9_pop_gw_g14_ir04?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"I fuochi di Valyria. Le cronache del ghiaccio e del fuoco: 11 (Omnibus)\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/41WLxQ8kYrL._SL135_.jpg\" url=\"\" alt=\"\" width=\"85\" height=\"135\"></div><span class=\"s9TitleText\">I fuochi di Valyria. Le cronache del...</span></a><div class=\"t11\">George R. Martin, S. Altieri, G. L...</div><div class=\"gry t11 nt\">Rilegato</div><span class=\"s9Price red t14\">EUR 16,15</span></div></div></div><div class=\"fluid asin s9a4\" style=\"float: left; width: 33.1%; display: none\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B005890FOO/ref=s9_pop_gw_g349_ir05?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Kindle Touch 3G: dispositivo di lettura Wi-Fi + 3G gratuito, schermo touch da 6" a inchiostro elettronico, il 3G funziona in tutto il mondo\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/41JpsttW8CL._SL135_.jpg\" url=\"\" alt=\"\" width=\"135\" height=\"135\"></div><span class=\"s9TitleText\">Kindle Touch 3G: dispositivo di...</span></a><br clear=\"none\"><div class=\"t11\">Amazon</div><span class=\"s9Price red t14\">EUR 189,00</span></div></div></div><div class=\"fluid asin s9a5\" style=\"float: left; width: 33.1%; display: none\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B002LSHOK8/ref=s9_pop_gw_g23_ir06?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Western Digital WDBAAU0015HBK Elements Desktop HardDisk\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/31Jf8batzwL._SL135_.jpg\" url=\"\" alt=\"\" width=\"135\" height=\"135\"></div><span class=\"s9TitleText\">Western Digital WDBAAU0015HBK...</span></a><br clear=\"none\"><span class=\"listprice gry t11\">EUR 156,51</span> <span class=\"s9Price red t14\">EUR 109,00</span></div></div></div><div class=\"fluid asin s9a6\" style=\"float: left; width: 33.1%; display: none\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B0037FLUYU/ref=s9_pop_gw_g23_ir07?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Sandisk Extreme Secure Digital Scheda Memoria 16GB\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/51XFd5pMm%2BL._SL135_.jpg\" url=\"\" alt=\"\" width=\"109\" height=\"135\"></div><span class=\"s9TitleText\">Sandisk Extreme Secure Digital Scheda...</span></a><br clear=\"none\"><span class=\"listprice gry t11\">EUR 30,56</span> <span class=\"s9Price red t14\">EUR 13,85</span></div></div></div></div>",
- "<div class=\"s9OtherItems\" style=\"float: left; width: 100%\"><div class=\"fluid asin s9a0\" style=\"float: left; width: 33.1%\"><div class=\"inner\"><div class=\"s9hl\" style=\"position: relative\"><a href=\"/gp/product/B007IZ1Q5S/ref=s9_pop_gw_g351_ir01?pf_rd_m=A11IL2PNWYJU7H&pf_rd_s=center-3&pf_rd_r=1BTC5JHXMDN02TNNHPS5&pf_rd_t=101&pf_rd_p=216204067&pf_rd_i=426865031\" class=\"title ntTitle noLinkDecoration\" title=\"Hunger Games (Italian edition) (Chrysalide)\"><div class=\"imageContainer\"><img src=\"http://ecx.images-amazon.com/images/I/51fVBD%2Bkm4L._SL135_.jpg\" alt=\"\" width=\"88\" height=\"135\"></div><span class=\"s9TitleText\">Hunger Games</span></a><div class=\"t11\">Suzanne Collins, F. Paracchini, S...</div></div></div></div></div>",
- 48
- ));
- return testCases;
- }
- private class TestCase {
- private int cutPoint;
- private String testString;
- private String expectedString;
- public TestCase(String testString, String expectedString, int cutPoint){
- this.testString = testString;
- this.expectedString = expectedString;
- this.cutPoint = cutPoint;
- }
- public int getCutPoint() {
- return cutPoint;
- }
- public void setCutPoint(int cutPoint) {
- this.cutPoint = cutPoint;
- }
- public String getTestString() {
- return testString;
- }
- public void setTestString(String testString) {
- this.testString = testString;
- }
- public String getExpectedString() {
- return expectedString;
- }
- public void setExpectedString(String expectedString) {
- this.expectedString = expectedString;
- }
- @Override
- public String toString() {
- return "TestCase [cutPoint=" + cutPoint + ", expectedString="
- + expectedString + ", testString=" + testString + "]";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement