Sam Adams avatar Sam Adams committed 61eaeaa

Refactoring ATs

Comments (0)

Files changed (8)

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

  */
 public class CollectionMatchers {
     
-    public static Matcher<CollectionPage> hasTitle(final String title) {
-        return new TypeSafeMatcher<CollectionPage>() {
-
-            @Override
-            protected boolean matchesSafely(final CollectionPage collection) {
-                return collection.matchesTitle(title);
-            }
-
-            @Override
-            public void describeTo(final Description description) {
-                description.appendText("title matches '" + title + "'");
-            }
-        };
+    public static Matcher<CollectionView> hasTitle(final String title) {
+        return new CollectionTitleMatcher(title);
     }
     
-    public static Matcher<CollectionPage> containsItem(final Collection child) {
-        return new TypeSafeMatcher<CollectionPage>() {
-            @Override
-            protected boolean matchesSafely(final CollectionPage collection) {
-                return collection.containsChild(child);
-            }
-
-            @Override
-            public void describeTo(final Description description) {
-                description.appendText("collection contains '" + child.getUri() + "'");
-            }
-        };
+    public static Matcher<CollectionView> containsItem(final Collection child) {
+        return new CollectionContainsMatcher(child);
     }
 
-    public static Matcher<CollectionPage> hasSlug(final String slug) {
-        return new TypeSafeMatcher<CollectionPage>() {
-            @Override
-            protected boolean matchesSafely(final CollectionPage collection) {
-                return collection.hasSlug(slug);
-            }
+    public static Matcher<CollectionView> hasSlug(final String slug) {
+        return new CollectionSlugMatcher(slug);
+    }
 
-            @Override
-            public void describeTo(final Description description) {
-                description.appendText("slug matches '" + slug + "'");
-            }
-        };
+
+    private static class CollectionTitleMatcher extends TypeSafeMatcher<CollectionView> {
+        private final String title;
+
+        public CollectionTitleMatcher(final String title) {
+            this.title = title;
+        }
+
+        @Override
+        protected boolean matchesSafely(final CollectionView collection) {
+            return collection.matchesTitle(title);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("title matches '" + title + "'");
+        }
+    }
+
+    private static class CollectionContainsMatcher extends TypeSafeMatcher<CollectionView> {
+        private final Collection child;
+
+        public CollectionContainsMatcher(final Collection child) {
+            this.child = child;
+        }
+
+        @Override
+        protected boolean matchesSafely(final CollectionView collection) {
+            return collection.containsChild(child);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("collection contains '" + child.getUri() + "'");
+        }
+    }
+
+    private static class CollectionSlugMatcher extends TypeSafeMatcher<CollectionView> {
+        private final String slug;
+
+        public CollectionSlugMatcher(final String slug) {
+            this.slug = slug;
+        }
+
+        @Override
+        protected boolean matchesSafely(final CollectionView collection) {
+            return collection.hasSlug(slug);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("slug matches '" + slug + "'");
+        }
     }
 }

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

 /**
  * @author Sam Adams
  */
-public class CollectionPage {
+public class CollectionPage implements CollectionView {
     
     private final WebDriver webDriver;
     private final TestContext context;
         this.context = context;
     }
 
+    @Override
     public boolean matchesTitle(final String title) {
         final WebElement element = webDriver.findElement(By.cssSelector(".collection h1.title"));
         return context.actual(title).equals(element.getText());
     }
 
+    @Override
     public boolean hasSlug(final String slug) {
         return webDriver.getCurrentUrl().contains('/' + context.actual(slug) + '/');
     }
 
+    @Override
     public boolean containsChild(final Collection child) {
         final List<WebElement> elements = webDriver.findElements(By.cssSelector(".collection .result"));
         for (final WebElement element : elements) {

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

+package net.chempound.acceptance.dsl.driver;
+
+/**
+ * @author Sam Adams
+ */
+public interface CollectionView {
+
+    boolean matchesTitle(String title);
+
+    boolean hasSlug(String slug);
+
+    boolean containsChild(Collection child);
+
+}

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

  */
 public class ItemMatchers {
 
-    public static Matcher<ItemPage> hasTitle(final String title) {
-        return new TypeSafeMatcher<ItemPage>() {
-
-            @Override
-            protected boolean matchesSafely(final ItemPage item) {
-                return item.matchesTitle(title);
-            }
-
-            @Override
-            public void describeTo(final Description description) {
-                description.appendText("title matches '" + title + "'");
-            }
-        };
+    public static Matcher<ItemView> hasTitle(final String title) {
+        return new ItemTitleMatcher(title);
     }
 
-    public static Matcher<ItemPage> hasFileLink(final String file) {
-        return new TypeSafeMatcher<ItemPage>() {
-
-            @Override
-            protected boolean matchesSafely(final ItemPage item) {
-                return item.matchesFileLink(file);
-            }
-
-            @Override
-            public void describeTo(final Description description) {
-                description.appendText("contains file '" + file + "'");
-            }
-        };
+    public static Matcher<ItemView> hasFileLink(final String file) {
+        return new ItemFileLinkMatcher(file);
     }
 
+    private static class ItemTitleMatcher extends TypeSafeMatcher<ItemView> {
+
+        private final String title;
+
+        public ItemTitleMatcher(final String title) {
+            this.title = title;
+        }
+
+        @Override
+        protected boolean matchesSafely(final ItemView item) {
+            return item.matchesTitle(title);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("title matches '" + title + "'");
+        }
+    }
+
+    private static class ItemFileLinkMatcher extends TypeSafeMatcher<ItemView> {
+
+        private final String file;
+
+        public ItemFileLinkMatcher(final String file) {
+            this.file = file;
+        }
+
+        @Override
+        protected boolean matchesSafely(final ItemView item) {
+            return item.matchesFileLink(file);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("contains file '" + file + "'");
+        }
+    }
 }

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

 /**
  * @author Sam Adams
  */
-public class ItemPage {
+public class ItemPage implements ItemView {
 
     private final WebDriver webDriver;
     private final TestContext context;
         this.context = context;
     }
 
+    @Override
     public boolean matchesTitle(final String title) {
         final WebElement element = webDriver.findElement(By.cssSelector(".item h1.title"));
         return context.actual(title).equals(element.getText());
     }
 
+    @Override
     public boolean matchesFileLink(final String file) {
         final URI uri = URI.create(webDriver.getCurrentUrl()).resolve(file);
         final WebElement element = webDriver.findElement(By.xpath("//a[@href='" + uri + "']"));

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

+package net.chempound.acceptance.dsl.driver;
+
+/**
+ * @author Sam Adams
+ */
+public interface ItemView {
+
+    boolean matchesTitle(String title);
+
+    boolean matchesFileLink(String file);
+
+}

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

         webDriver.navigate().to(uri.toString());
     }
 
-    public void check(final Collection collection, final Matcher<CollectionPage>... matchers) {
+    public void check(final Collection collection, final Matcher<CollectionView>... matchers) {
         loadPage(collection.getUri());
         
         webDriver.findElement(By.cssSelector(".collection"));
         
-        final CollectionPage collectionPage = new CollectionPage(webDriver, context);
-        for (final Matcher<CollectionPage> matcher : matchers) {
-            assertThat(collectionPage, matcher);
+        final CollectionView collectionView = new CollectionPage(webDriver, context);
+        for (final Matcher<CollectionView> matcher : matchers) {
+            assertThat(collectionView, matcher);
         }
     }
 
-    public void check(final Item item, final Matcher<ItemPage>... matchers) {
+    public void check(final Item item, final Matcher<ItemView>... matchers) {
         loadPage(item.getUri());
 
         webDriver.findElement(By.cssSelector(".item"));
 
-        final ItemPage itemPage = new ItemPage(webDriver, context);
-        for (final Matcher<ItemPage> matcher : matchers) {
-            assertThat(itemPage, matcher);
+        final ItemView itemView = new ItemPage(webDriver, context);
+        for (final Matcher<ItemView> matcher : matchers) {
+            assertThat(itemView, matcher);
         }
     }
 

acceptance-tests/src/test/java/net/chempound/acceptance/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();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.