当前位置: 首页>>代码示例>>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;未经允许,请勿转载。