UPD: use more advanced hamcrest matchers where possible.
authorFelix Dörre <felix@dogcraft.de>
Sun, 31 Aug 2014 14:17:01 +0000 (16:17 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sun, 31 Aug 2014 15:29:00 +0000 (17:29 +0200)
tests/org/cacert/gigi/pages/account/TestContactInformation.java
tests/org/cacert/gigi/pages/main/RegisterPageTest.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index 65fd0779991007555a97fed64392827a4acd7546..6360578b42da418202fd4273fafa6e50b66dcaf4 100644 (file)
@@ -1,5 +1,6 @@
 package org.cacert.gigi.pages.account;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
@@ -22,7 +23,7 @@ public class TestContactInformation extends ManagedTest {
         url.setRequestProperty("Cookie", cookie);
         String res = IOUtils.readURL(url);
         res = res.split(java.util.regex.Pattern.quote("</table>"))[1];
-        assertTrue(res.contains("value=\"1\" selected"));
+        assertThat(res, containsString("value=\"1\" selected"));
         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=0&contactinfo=&processContact", 1));
         url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
         url.setRequestProperty("Cookie", cookie);
@@ -42,6 +43,6 @@ public class TestContactInformation extends ManagedTest {
         url.setRequestProperty("Cookie", cookie);
         String res = IOUtils.readURL(url);
         res = res.split(java.util.regex.Pattern.quote("</table>"))[1];
-        assertTrue(res.contains(text));
+        assertThat(res, containsString(text));
     }
 }
index c21d7a263c84eaa29d87d4babb48ac9de781f272..28ced07cde2c9532bee32a2f0e85eedfdc158646 100644 (file)
@@ -1,5 +1,6 @@
 package org.cacert.gigi.pages.main;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
@@ -124,26 +125,26 @@ public class RegisterPageTest extends ManagedTest {
     public void testDataStays() throws IOException {
         long uniq = System.currentTimeMillis();
         String run = runRegister("fname=fn" + uniq + "&lname=ln" + uniq + "&email=ma" + uniq + "@cacert.org&pword1=pas" + uniq + "&pword2=pas2" + uniq + "&day=1&month=1&year=0");
-        assertTrue(run.contains("fn" + uniq));
-        assertTrue(run.contains("ln" + uniq));
-        assertTrue(run.contains("ma" + uniq + "@cacert.org"));
-        assertTrue( !run.contains("pas" + uniq));
-        assertTrue( !run.contains("pas2" + uniq));
+        assertThat(run, containsString("fn" + uniq));
+        assertThat(run, containsString("ln" + uniq));
+        assertThat(run, containsString("ma" + uniq + "@cacert.org"));
+        assertThat(run, not(containsString("pas" + uniq)));
+        assertThat(run, not(containsString("pas2" + uniq)));
 
     }
 
     @Test
     public void testCheckboxesStay() throws IOException {
         String run2 = runRegister("general=1&country=a&regional=1&radius=0");
-        assertTrue(run2.contains("name=\"general\" value=\"1\" checked=\"checked\">"));
-        assertTrue(run2.contains("name=\"country\" value=\"1\">"));
-        assertTrue(run2.contains("name=\"regional\" value=\"1\" checked=\"checked\">"));
-        assertTrue(run2.contains("name=\"radius\" value=\"1\">"));
+        assertThat(run2, containsString("name=\"general\" value=\"1\" checked=\"checked\">"));
+        assertThat(run2, containsString("name=\"country\" value=\"1\">"));
+        assertThat(run2, containsString("name=\"regional\" value=\"1\" checked=\"checked\">"));
+        assertThat(run2, containsString("name=\"radius\" value=\"1\">"));
         run2 = runRegister("general=0&country=1&radius=1");
-        assertTrue(run2.contains("name=\"general\" value=\"1\">"));
-        assertTrue(run2.contains("name=\"country\" value=\"1\" checked=\"checked\">"));
-        assertTrue(run2.contains("name=\"regional\" value=\"1\">"));
-        assertTrue(run2.contains("name=\"radius\" value=\"1\" checked=\"checked\">"));
+        assertThat(run2, containsString("name=\"general\" value=\"1\">"));
+        assertThat(run2, containsString("name=\"country\" value=\"1\" checked=\"checked\">"));
+        assertThat(run2, containsString("name=\"regional\" value=\"1\">"));
+        assertThat(run2, containsString("name=\"radius\" value=\"1\" checked=\"checked\">"));
     }
 
     @Test
index 3db48d65e65abdcfefdb4d1a28464b7cb3ad300a..03e499df6143e903ca0707897b6c295994758338 100644 (file)
@@ -1,5 +1,6 @@
 package org.cacert.gigi.pages.wot;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
@@ -158,7 +159,7 @@ public class TestAssurance extends ManagedTest {
         url.setRequestProperty("Cookie", cookie);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[0];
-        assertTrue(resp.contains(uniqueLoc));
+        assertThat(resp, containsString(uniqueLoc));
     }
 
     @Test
@@ -171,7 +172,7 @@ public class TestAssurance extends ManagedTest {
         url.setRequestProperty("Cookie", cookie);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[1];
-        assertTrue(resp.contains(uniqueLoc));
+        assertThat(resp, containsString(uniqueLoc));
     }
 
     private String getError(String query) throws MalformedURLException, IOException {
index ae62beb565b2e300b92e4a3f4df691b375c8a5bc..df19e0cff3680139f8060a2421abf743bda2ffb4 100644 (file)
@@ -509,7 +509,7 @@ public class ManagedTest {
         EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
         adrr.insert(Language.getInstance(Locale.ENGLISH));
         TestMail testMail = getMailReciever().recieve();
-        assertTrue(adrr.getAddress().equals(testMail.getTo()));
+        assertEquals(adrr.getAddress(), testMail.getTo());
         String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
         adrr.verify(hash);
         getMailReciever().clearMails();