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


Java Matcher類代碼示例

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


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

示例1: clickNoConstraints

import org.hamcrest.Matcher; //導入依賴的package包/類
static ViewAction clickNoConstraints() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isEnabled(); // No constraints, isEnabled and isClickable are checked
        }

        @Override
        public String getDescription() {
            return "Click a view with no constraints.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            view.performClick();
        }
    };
}
 
開發者ID:dev-labs-bg,項目名稱:fullscreen-video-view,代碼行數:19,代碼來源:CustomChecks.java

示例2: testInvokingAddConsumerCreatesAValidJsonArray

import org.hamcrest.Matcher; //導入依賴的package包/類
@Test
public void testInvokingAddConsumerCreatesAValidJsonArray() {
	_jsonObjectBuilder.field(
		"array"
	).arrayValue(
	).add(
		jsonObjectBuilder -> jsonObjectBuilder.field(
			"solution"
		).numberValue(
			42
		)
	);

	@SuppressWarnings("unchecked")
	Matcher<JsonElement> isAJsonArrayWithElements = is(
		aJsonArrayThat(contains(_aJsonObjectWithTheSolution)));

	Matcher<JsonElement> isAJsonObjectWithAnArray = is(
		aJsonObjectWhere("array", isAJsonArrayWithElements));

	assertThat(getJsonObject(), isAJsonObjectWithAnArray);
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:23,代碼來源:JSONObjectBuilderTest.java

示例3: withIndex

import org.hamcrest.Matcher; //導入依賴的package包/類
private static Matcher<View> withIndex(final Matcher<View> matcher, final int index) {
    return new TypeSafeMatcher<View>() {
        int currentIndex = 0;

        @Override
        public void describeTo(Description description) {
            description.appendText("with index: ");
            description.appendValue(index);
            matcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            return matcher.matches(view) && currentIndex++ == index;
        }
    };
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:18,代碼來源:SimpleEspressoTest.java

示例4: showControls

import org.hamcrest.Matcher; //導入依賴的package包/類
private static ViewAction showControls() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(MovieView.class);
        }

        @Override
        public String getDescription() {
            return "Show controls of MovieView";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ((MovieView) view).showControls();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
 
開發者ID:googlesamples,項目名稱:android-PictureInPicture,代碼行數:21,代碼來源:MainActivityTest.java

示例5: hasContent

import org.hamcrest.Matcher; //導入依賴的package包/類
public static Matcher<? super HttpResponse> hasContent(final String content, final String charset) {
    return new BaseMatcher<HttpResponse>() {
        public boolean matches(Object o) {
            try {
                HttpResponse response = (HttpResponse) o;
                Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);

                int intValueOfChar;
                String targetString = "";
                while ((intValueOfChar = reader.read()) != -1) {
                    targetString += (char) intValueOfChar;
                }
                reader.close();

                return targetString.equals(content);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        public void describeTo(Description description) {
            description.appendText(content);
        }
    };
}
 
開發者ID:PawelAdamski,項目名稱:HttpClientMock,代碼行數:27,代碼來源:HttpResponseMatchers.java

示例6: childAtPosition

import org.hamcrest.Matcher; //導入依賴的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:charafau,項目名稱:TurboChat,代碼行數:19,代碼來源:MainActivityMessageViewNavigationTest.java

示例7: withBackgroundColor

import org.hamcrest.Matcher; //導入依賴的package包/類
/**
 * A customized {@link Matcher} for testing that
 * if one color match the background color of current view.
 * @param backgroundColor A color int value.
 *
 * @return Match or not.
 */
public static Matcher<View> withBackgroundColor(final int backgroundColor) {
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            int color = ((ColorDrawable) view.getBackground().getCurrent()).getColor();
            return color == backgroundColor;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with background color value: " + backgroundColor);
        }
    };
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:23,代碼來源:AppNavigationTest.java

示例8: testGoToManual

import org.hamcrest.Matcher; //導入依賴的package包/類
/**
 * Test if the manual input activity opens.
 */
@Test
public void testGoToManual() {
    onView(withId(R.id.manual_input_button)).check(matches(allOf( isEnabled(), isClickable()))).perform(
            new ViewAction() {
                @Override
                public Matcher<View> getConstraints() {
                    return isEnabled(); // no constraints, they are checked above
                }

                @Override
                public String getDescription() {
                    return "click manual input button";
                }

                @Override
                public void perform(UiController uiController, View view) {
                    view.performClick();
                }
            }
    );
    intended(hasComponent(ManualInputActivity.class.getName()));
}
 
開發者ID:digital-voting-pass,項目名稱:polling-station-app,代碼行數:26,代碼來源:TestMainActivity.java

示例9: hasBackgroundSpanOn

import org.hamcrest.Matcher; //導入依賴的package包/類
public static Matcher<View> hasBackgroundSpanOn(final String text, @ColorRes final int colorResource) {
  return new CustomTypeSafeMatcher<View>("") {
    @Override
    protected boolean matchesSafely(View view) {
      if (view == null || !(view instanceof TextView))
        return false;
      SpannableString spannableString = (SpannableString) ((TextView) view).getText();
      BackgroundColorSpan[] spans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
      for (BackgroundColorSpan span : spans) {
        int start = spannableString.getSpanStart(span);
        int end = spannableString.getSpanEnd(span);
        CharSequence highlightedString = spannableString.subSequence(start, end);
        if (text.equals(highlightedString.toString())) {
          return span.getBackgroundColor() == view.getContext().getResources().getColor(colorResource);
        }
      }
      return false;
    }
  };
}
 
開發者ID:jainsahab,項目名稱:AndroidSnooper,代碼行數:21,代碼來源:EspressoViewMatchers.java

示例10: withinSecondsAfter

import org.hamcrest.Matcher; //導入依賴的package包/類
public static Matcher<String> withinSecondsAfter(Seconds seconds, DateTime after) {
    return new TypeSafeMatcher<String>() {
      @Override
      public void describeTo(Description description) {
        description.appendText(String.format(
          "a date time within %s seconds after %s",
          seconds.getSeconds(), after.toString()));
      }

      @Override
      protected boolean matchesSafely(String textRepresentation) {
        //response representation might vary from request representation
        DateTime actual = DateTime.parse(textRepresentation);

        return actual.isAfter(after) &&
          Seconds.secondsBetween(after, actual).isLessThan(seconds);
      }
    };
}
 
開發者ID:folio-org,項目名稱:mod-circulation-storage,代碼行數:20,代碼來源:TextDateTimeMatcher.java

示例11: childAtPosition

import org.hamcrest.Matcher; //導入依賴的package包/類
public 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:cuplv,項目名稱:ChimpCheck,代碼行數:19,代碼來源:ViewID.java

示例12: used

import org.hamcrest.Matcher; //導入依賴的package包/類
private static Matcher<UsedJourneys> used(Journey journey) {
	return new TypeSafeMatcher<UsedJourneys>() {

		@Override
		public void describeTo(Description description) {
			description.appendText("used");
			description.appendValue(journey);
		}

		@Override
		protected boolean matchesSafely(UsedJourneys journeys) {
			return journeys.used(journey);
		}

		@Override
		protected void describeMismatchSafely(UsedJourneys item, Description mismatchDescription) {
			mismatchDescription.appendText("not used");
			mismatchDescription.appendValue(journey);
		}
	};
}
 
開發者ID:mobitopp,項目名稱:connection-scan,代碼行數:22,代碼來源:DefaultUsedJourneysTest.java

示例13: atPosition

import org.hamcrest.Matcher; //導入依賴的package包/類
public static Matcher<View> atPosition(final int position, final Matcher<View> itemMatcher) {
	return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
		@Override
		public void describeTo(Description description) {
			description.appendText("has item at position " + position + ": ");
			itemMatcher.describeTo(description);
		}

		@Override
		protected boolean matchesSafely(final RecyclerView view) {
			RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
			if (viewHolder == null) {
				return false;
			}
			return itemMatcher.matches(viewHolder.itemView);
		}
	};
}
 
開發者ID:leocabral,項目名稱:lacomida,代碼行數:19,代碼來源:EspressoCustomActions.java

示例14: isSameAs

import org.hamcrest.Matcher; //導入依賴的package包/類
public static Matcher<List<AuditLogEntry>> isSameAs(
        final List<AuditLog> auditLogs) {
    return new BaseMatcher<List<AuditLogEntry>>() {
        private int errorPosition;

        @Override
        public boolean matches(Object object) {
            List<AuditLogEntry> auditLogEntries = (List<AuditLogEntry>) object;

            assertEquals(auditLogEntries.size(), auditLogs.size());
            for (int i = 0; i < auditLogEntries.size(); i++) {
                errorPosition = i;
                compareAuditLogEntry(auditLogEntries.get(i),
                        auditLogs.get(i));
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description
                    .appendText("AuditLogEntry is not equal with AuditLog at position "
                            + errorPosition);
        }
    };
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:27,代碼來源:AuditLogMatchers.java

示例15: view_withCondition_thenAnd_thenNot_doesNotImplementMatcher_implementsMatching

import org.hamcrest.Matcher; //導入依賴的package包/類
@Order(5)
@Test
public void view_withCondition_thenAnd_thenNot_doesNotImplementMatcher_implementsMatching() {
    final Negated.Unfinished.And.Matcher matcher = Cortado.view().withText("test").and().not();
    assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);
    assertThat(matcher).isInstanceOf(Matching.class);
}
 
開發者ID:blipinsk,項目名稱:cortado,代碼行數:8,代碼來源:Cortado_Tests.java


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