Commits

Sam Adams committed 5979d79

Imporoved acceptance type safety

Comments (0)

Files changed (6)

acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/AbstractAcceptanceTest.java

 import org.junit.BeforeClass;
 
 import java.net.URI;
+import java.util.Collection;
 import java.util.Random;
 
+import static java.util.Arrays.asList;
 import static org.junit.Assert.assertThat;
 
 /**
         return new Resource(testContext.actual(path), "mime/type", generateContent());
     }
 
-    protected static <T, U extends T> void check(final U target, final Matcher<T>... matchers) {
+    @SuppressWarnings("unchecked")
+    protected static <T, U extends T> void check(final U target, final Matcher<T> matcher) {
+        check(target, asList(matcher));
+    }
+
+    @SuppressWarnings("unchecked")
+    protected static <T, U extends T> void check(final U target, final Matcher<T> matcher1, final Matcher<T> matcher2) {
+        check(target, asList(matcher1, matcher2));
+    }
+
+    protected static <T, U extends T> void check(final U target, final Iterable<Matcher<T>> matchers) {
         for (final Matcher<T> matcher : matchers) {
             assertThat(target, matcher);
         }

acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/WebUIDriver.java

 
 import java.net.URI;
 
+import static java.util.Arrays.asList;
 import static org.junit.Assert.assertThat;
 
 /**
         webDriver.navigate().to(uri.toString());
     }
 
-    public void check(final Collection collection, final Matcher<CollectionView>... matchers) {
+    @SuppressWarnings("unchecked")
+    public void check(final Collection collection, final Matcher<CollectionView> matcher) {
+        check(collection, asList(matcher));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void check(final Collection collection, final Matcher<CollectionView> matcher1, final Matcher<CollectionView> matcher2) {
+        check(collection, asList(matcher1, matcher2));
+    }
+
+    public void check(final Collection collection, final Iterable<Matcher<CollectionView>> matchers) {
         loadPage(collection.getUri());
         
         webDriver.findElement(By.cssSelector(".collection"));
         }
     }
 
-    public void check(final DepositReceipt item, final Matcher<ItemView>... matchers) {
+    @SuppressWarnings("unchecked")
+    public void check(final DepositReceipt item, final Matcher<ItemView> matcher) {
+        check(item, asList(matcher));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void check(final DepositReceipt item, final Matcher<ItemView> matcher1, final Matcher<ItemView> matcher2) {
+        check(item, asList(matcher1, matcher2));
+    }
+
+    public void check(final DepositReceipt item, final Iterable<Matcher<ItemView>> matchers) {
         loadPage(item.getUri());
 
         webDriver.findElement(By.cssSelector(".item"));

acceptance-tests/src/test/java/net/chempound/acceptance/PingbackAcceptanceTest.java

 import java.net.URI;
 
 import static net.chempound.acceptance.dsl.driver.ItemMatchers.hasPingbacks;
+import static net.chempound.webapp.pingback.PingbackFault.*;
 
 /**
  * @author Sam Adams
 
         pingbackDriver.pingback(item.getUri(), blog);
 
-        pingbackDriver.pingback(item.getUri(), blog, PingbackFault.ALREADY_REGISTERED);
+        pingbackDriver.pingback(item.getUri(), blog, ALREADY_REGISTERED);
     }
 
     @Test
 
         URI blog = blogServer.addPost(itemUri);
 
-        pingbackDriver.doPingback(itemUri, blog, PingbackFault.TARGET_URI_INVALID, testContext.getPingbackUrl());
+        pingbackDriver.doPingback(itemUri, blog, TARGET_URI_INVALID, testContext.getPingbackUrl());
     }
 
     @Test
     public void shouldRejectPingbackWithBadSourceUrl() throws Exception {
         URI blog = blogServer.addPost(item.getUri());
 
-        pingbackDriver.pingback(item.getUri(), blog.resolve("--does-not-exist"), PingbackFault.SOURCE_URI_DOES_NOT_EXIST);
+        pingbackDriver.pingback(item.getUri(), blog.resolve("--does-not-exist"), SOURCE_URI_DOES_NOT_EXIST);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
+    public void shouldRejectPingbackThatDoesNotLinkToTargetPage() throws Exception {
+        URI blog = blogServer.addPost(URI.create("http://www.example.com/other-target"));
+
+        pingbackDriver.pingback(item.getUri(), blog, SOURCE_URI_DOES_NOT_LINK_TO_TARGET);
+    }
+
+    @Test
     public void shouldDisplayPingbackOnItemPage() throws Exception {
         URI blog = blogServer.addPost(item.getUri());
 
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldUpdatePingbacksOnItemPageWhenNewPingbackReceived() throws Exception {
         URI blog1 = blogServer.addPost(item.getUri());
         URI blog2 = blogServer.addPost(item.getUri());

acceptance-tests/src/test/java/net/chempound/acceptance/sword/DepositAcceptanceTest.java

     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMetadataOnlDeposit() {
         DepositReceipt item = apiDriver.depositItem()
             .withSlug("slug")
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnBinaryDeposit() {
         Resource file = newResource("file");
         
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnBinaryDepositWithMultipleFiles() {
         Resource file1 = newResource("file1");
         Resource file2 = newResource("file2");
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMultipartDeposit() {
         Resource file = newResource("file");
 
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMultipartDepositWithMultipleFiles() {
         Resource file1 = newResource("file1");
         Resource file2 = newResource("file2");

acceptance-tests/src/test/java/net/chempound/acceptance/ui/CollectionAcceptanceTest.java

     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateCollectionWithTitle() throws Exception {
         Collection collection = apiDriver.createCollection()
             .withTitle("title")
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateCollectionWithSlug() throws Exception {
         Collection collection = apiDriver.createCollection()
             .withSlug("slug")
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldLinkFromParentToChildCollection() throws Exception {
         Collection parent = apiDriver.createCollection()
             .execute();

acceptance-tests/src/test/java/net/chempound/acceptance/ui/WebUIAcceptanceTest.java

     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMetadataDeposit() {
         DepositReceipt item = apiDriver.depositItem()
             .withSlug("slug")
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnBinaryDeposit() {
         Resource file = newResource();
         
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMultipartDeposit() {
         Resource file = newResource();