當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeSafeMatcher類代碼示例

本文整理匯總了Java中org.hamcrest.TypeSafeMatcher的典型用法代碼示例。如果您正苦於以下問題:Java TypeSafeMatcher類的具體用法?Java TypeSafeMatcher怎麽用?Java TypeSafeMatcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeSafeMatcher類屬於org.hamcrest包,在下文中一共展示了TypeSafeMatcher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: childAtPosition

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher, final int position) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent)
                    && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
開發者ID:privacyidea,項目名稱:privacyidea-authenticator,代碼行數:19,代碼來源:MainActivityTest.java

示例2: withUsageHintOnClick

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static Matcher<? super View> withUsageHintOnClick(final Matcher<? extends CharSequence> charSequenceMatcher) {
    return new TypeSafeMatcher<View>() {
        @Override
        protected boolean matchesSafely(View view) {
            if (!view.isClickable()) {
                return false;
            }
            AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_CLICK);
            return charSequenceMatcher.matches(clickAction.getLabel());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is clickable and has custom usage hint for ACTION_CLICK: ");
            charSequenceMatcher.describeTo(description);
        }
    };
}
 
開發者ID:novoda,項目名稱:espresso-support,代碼行數:20,代碼來源:AccessibilityViewMatchers.java

示例3: withItemText

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
/**
 * A custom {@link Matcher} which matches an item in a {@link ListView} by its text.
 * <p>
 * View constraints:
 * <ul>
 * <li>View must be a child of a {@link ListView}
 * <ul>
 *
 * @param itemText the text to match
 * @return Matcher that matches text in the given view
 */
private Matcher<View> withItemText(final String itemText) {
    checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
    return new TypeSafeMatcher<View>() {
        @Override
        public boolean matchesSafely(View item) {
            return allOf(
                    isDescendantOfA(isAssignableFrom(ListView.class)),
                    withText(itemText)).matches(item);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is isDescendantOfA LV with text " + itemText);
        }
    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:TasksScreenTest.java

示例4: causalChainContains

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
    return new TypeSafeMatcher<Throwable>() {
        @Override
        protected boolean matchesSafely(Throwable item) {
            final List<Throwable> causalChain = Throwables.getCausalChain(item);
            for (Throwable throwable : causalChain) {
                if(cls.isAssignableFrom(throwable.getClass())){
                    return true;
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("exception with causal chain containing " + cls.getSimpleName());
        }
    };
}
 
開發者ID:bibryam,項目名稱:rotabuilder,代碼行數:20,代碼來源:EmployeeMenu_IntegTest.java

示例5: typeName

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
public static Matcher<TypeName> typeName(final Matcher<? super ClassName> matcher) {

        final Matcher<? super ClassName> subMatcher = matcher;
        return new TypeSafeMatcher<TypeName>() {
            @Override
            protected boolean matchesSafely(TypeName item) {
                return subMatcher.matches(item);
            }

            @Override
            public void describeTo(Description description) {

                description.appendText("typename ").appendDescriptionOf(subMatcher);
            }
        };
    }
 
開發者ID:mulesoft-labs,項目名稱:raml-java-tools,代碼行數:17,代碼來源:TypeNameMatcher.java

示例6: hasMember

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
public static Matcher<AnnotationSpec> hasMember(final String member) {

    return new TypeSafeMatcher<AnnotationSpec>() {

      @Override
      protected boolean matchesSafely(AnnotationSpec item) {
        return item.members.containsKey(member);
      }

      @Override
      public void describeTo(Description description) {

        description.appendText("has member " + member);
      }
    };
  }
 
開發者ID:mulesoft-labs,項目名稱:raml-java-tools,代碼行數:17,代碼來源:AnnotationSpecMatchers.java

示例7: nthChildOf

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
public static Matcher<View> nthChildOf(final Matcher<View> parentMatcher, final int childPosition) {
	return new TypeSafeMatcher<View>() {
		@Override
		public void describeTo(Description description) {
			description.appendText("with "+childPosition+" child view of type parentMatcher");
		}

		@Override
		public boolean matchesSafely(View view) {
			if (!(view.getParent() instanceof ViewGroup)) {
				return parentMatcher.matches(view.getParent());
			}

			ViewGroup group = (ViewGroup) view.getParent();
			return parentMatcher.matches(view.getParent()) && group.getChildAt(childPosition).equals(view);
		}
	};
}
 
開發者ID:acristescu,項目名稱:GreenfieldTemplate,代碼行數:19,代碼來源:PlaylistActivityTest.java

示例8: subfieldOfNthItemWithId

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
/**
 * Matches a view that is a descendant of the nth item in a recyclerview
 * @param listMatcher
 * @param childPosition
 * @param subviewMatcher
 * @return
 */
public static Matcher<View> subfieldOfNthItemWithId(final Matcher<View> listMatcher, final int childPosition, final Matcher<View> subviewMatcher) {
	return new TypeSafeMatcher<View>() {
		@Override
		public void describeTo(Description description) {
			description.appendText("Sub-view of an item from a list");
		}

		@Override
		public boolean matchesSafely(View view) {
			//
			// Clearly "espresso + recyclerview != love"
			//
			return allOf(
					isDescendantOfA(nthChildOf(listMatcher, childPosition)),
					subviewMatcher
			).matches(view);
		}
	};
}
 
開發者ID:acristescu,項目名稱:GreenfieldTemplate,代碼行數:27,代碼來源:PlaylistActivityTest.java

示例9: childAtPosition

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher,
        final int position) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(
                    ((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:19,代碼來源:MainActivityTest.java

示例10: equalTo

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
public static Matcher<CharSequence> equalTo(final CharSequence expected) {
  return new TypeSafeMatcher<CharSequence>() {

    final Matcher<String> stringMatcher = org.hamcrest.Matchers.equalTo(expected.toString());

    @Override
    public void describeTo(final Description description) {
      stringMatcher.describeTo(description);
    }

    @Override
    protected boolean matchesSafely(final CharSequence actual) {
      return stringMatcher.matches(actual.toString());
    }
  };
}
 
開發者ID:SAP,項目名稱:java-memory-assistant,代碼行數:17,代碼來源:Matchers.java

示例11: childAtPosition

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher,
        final int position) {

    return new TypeSafeMatcher<View>() {
        @Override public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(
                    ((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:17,代碼來源:LoginActivityTest.java

示例12: isDate

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<Long> isDate(final long expected, DateTimeZone tz) {
    return new TypeSafeMatcher<Long>() {
        @Override
        public boolean matchesSafely(final Long item) {
            return expected == item.longValue();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Expected: " + new DateTime(expected, tz) + " [" + expected + "] ");
        }

        @Override
        protected void describeMismatchSafely(final Long actual, final Description mismatchDescription) {
            mismatchDescription.appendText(" was ").appendValue(new DateTime(actual, tz) + " [" + actual + "]");
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:TimeZoneRoundingTests.java

示例13: eqToRequest

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private static Matcher<SagaRequest> eqToRequest(SagaRequest expected) {
  return new TypeSafeMatcher<SagaRequest>() {
    @Override
    protected boolean matchesSafely(SagaRequest request) {
      return expected.id().equals(request.id())
          && request.serviceName().equals(expected.serviceName())
          && request.task().equals(expected.task())
          && request.type().equals(expected.type())
          && ((RestOperation) request.transaction()).path().equals(((RestOperation) expected.transaction()).path())
          && ((RestOperation) request.transaction()).method().equals(((RestOperation) expected.transaction()).method())
          && ((RestOperation) request.compensation()).path().equals(((RestOperation) expected.compensation()).path())
          && ((RestOperation) request.compensation()).method().equals(((RestOperation) expected.compensation()).method());
    }

    @Override
    public void describeTo(Description description) {
      description.appendText(expected.toString());
    }
  };

}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:22,代碼來源:SagaEventFormatTest.java

示例14: eventWith

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private Matcher<SagaEventEntity> eventWith(
    long eventId,
    String type) {

  return new TypeSafeMatcher<SagaEventEntity>() {
    @Override
    protected boolean matchesSafely(SagaEventEntity event) {
      return eventId == event.id() && event.type().equals(type);
    }

    @Override
    protected void describeMismatchSafely(SagaEventEntity item, Description mismatchDescription) {
      mismatchDescription.appendText(item.toString());
    }

    @Override
    public void describeTo(Description description) {
      description.appendText(
          "SagaEventEntity {"
              + "id=" + eventId
              + ", type=" + type);
    }
  };
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:25,代碼來源:SagaSpringApplicationTestBase.java

示例15: withReleaseUpdate

import org.hamcrest.TypeSafeMatcher; //導入依賴的package包/類
private TypeSafeMatcher<List<ReleaseUpdate>> withReleaseUpdate(final String version,
		final String refDocUrl, final String releaseStatus) {
	return new TypeSafeMatcher<List<ReleaseUpdate>>() {
		@Override protected boolean matchesSafely(List<ReleaseUpdate> items) {
			ReleaseUpdate item = items.get(0);
			return "foo".equals(item.artifactId) &&
					releaseStatus.equals(item.releaseStatus) &&
					version.equals(item.version) &&
					refDocUrl.equals(item.apiDocUrl) &&
					refDocUrl.equals(item.refDocUrl);
		}

		@Override public void describeTo(Description description) {

		}
	};
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-release-tools,代碼行數:18,代碼來源:SaganUpdaterTest.java


注:本文中的org.hamcrest.TypeSafeMatcher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。