Examples of BaseMatcher


Examples of org.hamcrest.BaseMatcher

    }
   
    @Test
    public void shouldUseMatchersSafely() {
        //given
        List<Matcher> matchers = (List) Arrays.asList(new BaseMatcher() {
            public boolean matches(Object item) {
                throw new ClassCastException("nasty matcher");
            }

            public void describeTo(Description description) {
View Full Code Here

Examples of org.hamcrest.BaseMatcher

    // Shouldn't throw
    new OperaSettings().merge(caps);
  }

  private Matcher matchesProfile(final OperaProfile expected) {
    return new BaseMatcher() {
      public boolean matches(Object o) {
        OperaProfile actual = (OperaProfile) o;

        try {
          if ((expected.toJson().toString().equals(actual.toJson().toString())) &&
View Full Code Here

Examples of org.hamcrest.BaseMatcher

public final class Classes {

    @SuppressWarnings("unchecked")
    public static Matcher isSubclassOf(final Class superClass) {
        return new BaseMatcher() {
            @Override
            public boolean matches(final Object item) {
                final Class cls = (Class) item;
                return superClass.isAssignableFrom(cls);
            }
View Full Code Here

Examples of org.hamcrest.BaseMatcher

        ctx.init( project, getDefaultDotnetCompilerConfig() );

        Set<Artifact> libraries = ctx.getLibraryDependenciesFor( ArtifactScope.COMPILE );
        assertThat( libraries.size(), equalTo( 1 ) );
        assertThat( ( (Artifact) libraries.toArray()[0] ).getFile().getAbsolutePath(),
                    CoreMatchers.allOf( new BaseMatcher()
                    {
                        private String containsString = "assembly" + File.separator + "GAC_MSIL" + File.separator +
                            "artifactId" + File.separator + "1.0__dsfajkdsfajdfs" + File.separator + "artifactId.dll";

                        public boolean matches( Object object )
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

   protected abstract Object createPerson() throws Exception;

   protected abstract BaseMatcher createMatcher();

   protected boolean match(String queryString, Object obj) throws Exception {
      BaseMatcher matcher = createMatcher();

      final int[] matchCount = new int[1];

      matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount[0]++;
            }
         }
      });

      matcher.match(obj);
      return matchCount[0] == 1;
   }
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

      matcher.match(obj);
      return matchCount[0] == 1;
   }

   protected boolean match(Query query, Object obj) throws Exception {
      BaseMatcher matcher = createMatcher();

      final int[] matchCount = new int[1];

      matcher.registerFilter(query, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount[0]++;
            }
         }
      });

      matcher.match(obj);
      return matchCount[0] == 1;
   }
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

   @Test
   public void test9() throws Exception {
      String queryString1 = "from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";
      String queryString2 = "from org.infinispan.objectfilter.test.model.Person p where p.phoneNumbers.number = '004012345'";

      BaseMatcher matcher = createMatcher();

      final int[] matchCount1 = new int[1];
      matcher.registerFilter(queryString1, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount1[0]++;
            }
         }
      });

      final int[] matchCount2 = new int[1];
      matcher.registerFilter(queryString2, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount2[0]++;
            }
         }
      });

      matcher.match(createPerson());

      assertEquals(1, matchCount1[0]);
      assertEquals(1, matchCount2[0]);
   }
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

      assertEquals(1, matchCount2[0]);
   }

   @Test
   public void test10() throws Exception {
      BaseMatcher matcher = createMatcher();
      QueryFactory qf = matcher.getQueryFactory();
      Query q = qf.from(Person.class)
            .having("phoneNumbers.number")
            .eq("004012345").toBuilder().build();
      assertTrue(match(q, createPerson()));
   }
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

   @Test
   public void test11() throws Exception {
      String queryString = "from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";

      BaseMatcher matcher = createMatcher();
      Object person = createPerson();

      final int[] matchCount = new int[1];
      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount[0]++;
            }
         }
      });

      // create a sub-matcher with a single filter
      final int[] matchCount2 = new int[1];
      Matcher subMatcher = matcher.getSingleFilterMatcher(filterSubscription, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount2[0]++;
            }
         }
      });

      matcher.match(person);
      assertEquals(1, matchCount[0]);
      assertEquals(0, matchCount2[0]);

      subMatcher.match(person);
      assertEquals(1, matchCount[0]);
View Full Code Here

Examples of org.infinispan.objectfilter.BaseMatcher

   @Test
   public void test12() throws Exception {
      String queryString = "from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";   //todo should we be able to use short names too?

      BaseMatcher matcher = createMatcher();
      Object person = createPerson();

      final int matchCount[] = new int[1];
      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount[0]++;
            }
         }
      });

      matcher.match(person);

      assertEquals(1, matchCount[0]);

      matcher.unregisterFilter(filterSubscription);
      matcher.match(person);

      // check that unregistration really took effect
      assertEquals(1, matchCount[0]);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.