@Test
public void shouldInitializeCrashView() throws Exception {
SherlockDatabaseHelper database = mock(SherlockDatabaseHelper.class);
Crash crash = mock(Crash.class);
when(crash.getId()).thenReturn(1);
AppInfo appInfo = mock(AppInfo.class);
when(crash.getAppInfo()).thenReturn(appInfo);
when(database.getCrashById(1)).thenReturn(crash);
CrashActions actions = mock(CrashActions.class);
CrashPresenter presenter = new CrashPresenter(database, actions);
presenter.render(1);
verify(actions).render(argThat(new CustomTypeSafeMatcher<CrashViewModel>("") {
@Override
protected boolean matchesSafely(CrashViewModel crashViewModel) {
return crashViewModel.getIdentifier() == 1;
}
}));
verify(actions).renderAppInfo(any(AppInfoViewModel.class));
}
java类org.hamcrest.CustomTypeSafeMatcher的实例源码
CrashPresenterTest.java 文件源码
项目:Sherlock
阅读 28
收藏 0
点赞 0
评论 0
EspressoViewMatchers.java 文件源码
项目:AndroidSnooper
阅读 35
收藏 0
点赞 0
评论 0
public static Matcher<View> withTableLayout(final int tableLayoutId, final int row, final int column) {
return new CustomTypeSafeMatcher<View>(format("Table layout with id: {0} at row: {1} and column: {2}",
tableLayoutId, row, column)) {
@Override
protected boolean matchesSafely(View item) {
View view = item.getRootView().findViewById(tableLayoutId);
if (view == null || !(view instanceof TableLayout))
return false;
TableLayout tableLayout = (TableLayout) view;
TableRow tableRow = (TableRow) tableLayout.getChildAt(row);
View childView = tableRow.getChildAt(column);
return childView == item;
}
};
}
EspressoViewMatchers.java 文件源码
项目:AndroidSnooper
阅读 49
收藏 0
点赞 0
评论 0
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;
}
};
}
SnooperRepoTest.java 文件源码
项目:AndroidSnooper
阅读 32
收藏 0
点赞 0
评论 0
@NonNull
private CustomTypeSafeMatcher<List<HttpCallRecord>> areSortedAccordingToDate() {
return new CustomTypeSafeMatcher<List<HttpCallRecord>>("are sorted") {
@Override
protected boolean matchesSafely(List<HttpCallRecord> list) {
for (int index = 0 ; index < list.size() - 1 ; index++) {
long firstRecordTime = list.get(index).getDate().getTime();
long secondRecordTime = list.get(index + 1).getDate().getTime();
if (firstRecordTime < secondRecordTime) {
return false;
}
}
return true;
}
};
}
HttpCallFragmentPresenterTest.java 文件源码
项目:AndroidSnooper
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void shouldReturnBoundsToHighlight() throws Exception {
when(responseFormatter.format(anyString())).thenReturn("ABC0124abc");
HttpHeader httpHeader = getJsonContentTypeHeader();
when(httpCallRecord.getRequestHeader("Content-Type")).thenReturn(httpHeader);
resolveBackgroundTask();
presenter.init(viewModel, REQUEST_MODE);
presenter.searchInBody("abc");
verify(httpCallBodyView).removeOldHighlightedSpans();
verify(httpCallBodyView).highlightBounds(argThat(new CustomTypeSafeMatcher<List<Bound>>("") {
@Override
protected boolean matchesSafely(List<Bound> item) {
Bound firstBound = item.get(0);
assertThat(firstBound.getLeft(), is(0));
assertThat(firstBound.getRight(), is(3));
Bound secondBound = item.get(1);
assertThat(secondBound.getLeft(), is(7));
assertThat(secondBound.getRight(), is(10));
return true;
}
}));
}
UnhandledExceptionHandlerBaseTest.java 文件源码
项目:backstopper
阅读 30
收藏 0
点赞 0
评论 0
private Matcher<DefaultErrorContractDTO> errorResponseViewMatches(final DefaultErrorContractDTO expectedErrorContract) {
return new CustomTypeSafeMatcher<DefaultErrorContractDTO>("a matching ErrorResponseView"){
@Override
protected boolean matchesSafely(DefaultErrorContractDTO item) {
if (!(item.errors.size() == expectedErrorContract.errors.size()))
return false;
for (int i = 0; i < item.errors.size(); i++) {
DefaultErrorDTO itemError = item.errors.get(i);
DefaultErrorDTO expectedError = item.errors.get(i);
if (!itemError.code.equals(expectedError.code))
return false;
if (!itemError.message.equals(expectedError.message))
return false;
}
return item.error_id.equals(expectedErrorContract.error_id);
}
};
}
ModelParameterTypeListenerTest.java 文件源码
项目:greyfish
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testInjection() throws Exception {
// given
final int newFieldValue = 1;
final String newFiledValueStr = String.valueOf(newFieldValue);
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
final ModelParameterTypeListener modelParameterTypeListener =
new ModelParameterTypeListener(ImmutableMap.of("field", newFiledValueStr));
bindListener(Matchers.any(), modelParameterTypeListener);
}
});
// when
final TypeParameterOwner instance = injector.getInstance(TypeParameterOwner.class);
// then
assertThat(instance, new CustomTypeSafeMatcher<TypeParameterOwner>("got it's fields injected") {
@Override
protected boolean matchesSafely(TypeParameterOwner item) {
return item.field == newFieldValue;
}
});
}
ProductsTest.java 文件源码
项目:greyfish
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void testZip3() throws Exception {
// given
final Tuple3<ImmutableList<String>, ImmutableList<String>, ImmutableList<String>> zipped =
Tuple3.of(ImmutableList.of("a"), ImmutableList.of("b"), ImmutableList.of("c"));
// when
final Iterable<Product3<String, String, String>> zip = Products.zip(zipped);
// then
assertThat(zip, contains(new CustomTypeSafeMatcher<Product3<String, String, String>>("") {
@Override
protected boolean matchesSafely(final Product3<String, String, String> item) {
return item.first().equals("a") && item.second().equals("b") && item.third().equals("c");
}
}));
}
NullabilityTest.java 文件源码
项目:typed-github
阅读 35
收藏 0
点赞 0
评论 0
/**
* Test for nullability.
* Checks that all public methods in clases in package
* {@code com.jcabi.github }have {@code @NotNull} annotation for return
* value and for input arguments(if they are not scalar).
*
* @throws Exception If some problem inside
*/
@Test
public void checkNullability() throws Exception {
MatcherAssert.assertThat(
this.classpath.allPublicMethods(),
Matchers.everyItem(
// @checkstyle LineLength (1 line)
new CustomTypeSafeMatcher<Method>("parameter and return value is annotated with @NonNull") {
@Override
protected boolean matchesSafely(final Method item) {
return item.getReturnType().isPrimitive()
|| "toString".equals(item.getName())
|| item.isAnnotationPresent(NotNull.class)
&& NullabilityTest.allParamsAnnotated(item);
}
}
)
);
}
ImmutabilityTest.java 文件源码
项目:typed-github
阅读 29
收藏 0
点赞 0
评论 0
/**
* Test for immutability.
* Checks that all classes in package {@code com.jcabi.github }
* have {@code @Immutable} annotation.
*
* @throws Exception If some problem inside
*/
@Test
public void checkImmutability() throws Exception {
MatcherAssert.assertThat(
Iterables.filter(
this.classpath.allTypes(),
new Predicate<Class<?>>() {
@Override
public boolean apply(final Class<?> input) {
return !ImmutabilityTest.skip().contains(
input.getName()
);
}
}
),
Matchers.everyItem(
new CustomTypeSafeMatcher<Class<?>>("annotated type") {
@Override
protected boolean matchesSafely(final Class<?> item) {
return item.isAnnotationPresent(Immutable.class);
}
}
)
);
}
S3StreamFactoryTest.java 文件源码
项目:s3-stream-uploader
阅读 25
收藏 0
点赞 0
评论 0
private Matcher<UploadPartRequest> matchUploadPart(final char c) {
return new CustomTypeSafeMatcher<UploadPartRequest>("") {
@Override
protected boolean matchesSafely(UploadPartRequest subject) {
try {
String read = CharStreams.toString(new InputStreamReader(subject.getInputStream(), Charsets.UTF_8));
for (int i = 0, n = read.length(); i < n; i++) {
checkState(read.charAt(i) == c);
}
return true;
} catch (IOException e) {
throw new AssertionError(e);
}
}
};
}
ImmutabilityTest.java 文件源码
项目:jcabi-github
阅读 35
收藏 0
点赞 0
评论 0
/**
* Test for immutability.
* Checks that all classes in package {@code com.jcabi.github }
* have {@code @Immutable} annotation.
*
* @throws Exception If some problem inside
*/
@Test
public void checkImmutability() throws Exception {
MatcherAssert.assertThat(
Iterables.filter(
this.classpath.allTypes(),
new Predicate<Class<?>>() {
@Override
public boolean apply(final Class<?> input) {
return !ImmutabilityTest.skip().contains(
input.getName()
);
}
}
),
Matchers.everyItem(
new CustomTypeSafeMatcher<Class<?>>("annotated type") {
@Override
protected boolean matchesSafely(final Class<?> item) {
return item.isAnnotationPresent(Immutable.class);
}
}
)
);
}
FluentMatcher.java 文件源码
项目:simulacron
阅读 27
收藏 0
点赞 0
评论 0
/**
* Convenience method for wrapping a {@link Predicate} into a matcher.
*
* @param function the predicate to wrap.
* @param <T> The expected input type.
* @return a {@link CustomTypeSafeMatcher} that simply wraps the input predicate.
*/
public static <T> Matcher<T> match(Predicate<T> function) {
return new CustomTypeSafeMatcher<T>("Did not match") {
@Override
protected boolean matchesSafely(T item) {
return function.test(item);
}
};
}
PipelineExecutionServiceTests.java 文件源码
项目:elasticsearch_my
阅读 34
收藏 0
点赞 0
评论 0
public void testExecuteBulkPipelineDoesNotExist() {
CompoundProcessor processor = mock(CompoundProcessor.class);
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
bulkRequest.add(indexRequest1);
IndexRequest indexRequest2 =
new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("does_not_exist");
bulkRequest.add(indexRequest2);
@SuppressWarnings("unchecked")
BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
@SuppressWarnings("unchecked")
Consumer<Exception> completionHandler = mock(Consumer.class);
executionService.executeBulkRequest(bulkRequest.requests(), failureHandler, completionHandler);
verify(failureHandler, times(1)).accept(
argThat(new CustomTypeSafeMatcher<IndexRequest>("failure handler was not called with the expected arguments") {
@Override
protected boolean matchesSafely(IndexRequest item) {
return item == indexRequest2;
}
}),
argThat(new CustomTypeSafeMatcher<IllegalArgumentException>("failure handler was not called with the expected arguments") {
@Override
protected boolean matchesSafely(IllegalArgumentException iae) {
return "pipeline with id [does_not_exist] does not exist".equals(iae.getMessage());
}
})
);
verify(completionHandler, times(1)).accept(null);
}
FileSystemOfPathTest.java 文件源码
项目:sunshine
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void files() throws FileSystemException {
CustomTypeSafeMatcher<Integer> matcher = new CustomTypeSafeMatcher<Integer>("Has at least one item") {
@Override
protected boolean matchesSafely(Integer item) {
return item > 0;
}
};
MatcherAssert.assertThat(new FileSystemOfPath(RESOURCES).files(), Matchers.hasSize(matcher));
}
CustomEspressoMatchers.java 文件源码
项目:Sherlock
阅读 29
收藏 0
点赞 0
评论 0
public static Matcher<View> withRecyclerView(final int recyclerViewId, final int position) {
return new CustomTypeSafeMatcher<View>("") {
@Override
protected boolean matchesSafely(View item) {
RecyclerView view = (RecyclerView) item.getRootView().findViewById(recyclerViewId);
return view.getChildAt(position) == item;
}
};
}
EspressoIntentMatchers.java 文件源码
项目:AndroidSnooper
阅读 33
收藏 0
点赞 0
评论 0
public static Matcher<Bundle> forMailChooserIntent(final String action, final String mimeType, final String extraData, final String fileName) {
return new CustomTypeSafeMatcher<Bundle>("Custom matcher for matching mail chooser intent") {
@Override
protected boolean matchesSafely(Bundle item) {
Intent intent = (Intent) item.get(EXTRA_INTENT);
Uri uri = intent.getParcelableExtra(EXTRA_STREAM);
return action.equals(intent.getAction()) &&
mimeType.equals(intent.getType()) &&
intent.getStringExtra(EXTRA_SUBJECT).equalsIgnoreCase(extraData) &&
uri.getPath().endsWith(fileName);
}
};
}
EspressoViewMatchers.java 文件源码
项目:AndroidSnooper
阅读 35
收藏 0
点赞 0
评论 0
public static Matcher<View> withRecyclerView(final int recyclerViewId, final int position) {
return new CustomTypeSafeMatcher<View>(format("recycler view with id: {0} at position: {1}",
recyclerViewId, position)) {
@Override
protected boolean matchesSafely(View item) {
View view = item.getRootView().findViewById(recyclerViewId);
if (view == null || !(view instanceof RecyclerView))
return false;
RecyclerView recyclerView = (RecyclerView) view;
View childView = recyclerView.findViewHolderForAdapterPosition(position).itemView;
return childView == item;
}
};
}
EspressoViewMatchers.java 文件源码
项目:AndroidSnooper
阅读 38
收藏 0
点赞 0
评论 0
public static Matcher<View> withListSize(final int size) {
return new CustomTypeSafeMatcher<View>(format("recycler view with id: {0} ",
size)) {
@Override
protected boolean matchesSafely(View view) {
if (view == null || !(view instanceof RecyclerView))
return false;
RecyclerView recyclerView = (RecyclerView) view;
return recyclerView.getAdapter().getItemCount() == size;
}
};
}
WaitForViewAction.java 文件源码
项目:AndroidSnooper
阅读 38
收藏 0
点赞 0
评论 0
@NonNull
private CustomTypeSafeMatcher<View> anyView() {
return new CustomTypeSafeMatcher<View>("") {
@Override
protected boolean matchesSafely(View item) {
return true;
}
};
}
SnooperRepoTest.java 文件源码
项目:AndroidSnooper
阅读 26
收藏 0
点赞 0
评论 0
private Matcher<? super List<HttpHeaderValue>> containsWithValue(final String value) {
return new CustomTypeSafeMatcher<List<HttpHeaderValue>>("contains with value:" + value) {
@Override
protected boolean matchesSafely(List<HttpHeaderValue> list) {
return any(list, new Predicate<HttpHeaderValue>() {
@Override
public boolean apply(@Nullable HttpHeaderValue httpHeaderValue) {
return httpHeaderValue.getValue().equals(value);
}
});
}
};
}
SnooperRepoTest.java 文件源码
项目:AndroidSnooper
阅读 26
收藏 0
点赞 0
评论 0
@NonNull
private CustomTypeSafeMatcher<List<HttpCallRecord>> hasCallWithUrl(final String url) {
return new CustomTypeSafeMatcher<List<HttpCallRecord>>("with url") {
@Override
protected boolean matchesSafely(List<HttpCallRecord> item) {
for (HttpCallRecord httpCall : item) {
if (httpCall.getUrl().equals(url)) {
return true;
}
}
return false;
}
};
}
SnooperRepoTest.java 文件源码
项目:AndroidSnooper
阅读 27
收藏 0
点赞 0
评论 0
private Matcher<? super HttpCallRecord> hasDate(final Calendar date) {
return new CustomTypeSafeMatcher<HttpCallRecord>("has date: " + date) {
@Override
protected boolean matchesSafely(HttpCallRecord item) {
Calendar actualCalendar = Calendar.getInstance();
actualCalendar.setTime(item.getDate());
assertThat(actualCalendar.get(DATE), is(date.get(DATE)));
assertThat(actualCalendar.get(DAY_OF_MONTH), is(date.get(DAY_OF_MONTH)));
assertThat(actualCalendar.get(YEAR), is(date.get(YEAR)));
return true;
}
};
}
HttpCallActivityTest.java 文件源码
项目:AndroidSnooper
阅读 29
收藏 0
点赞 0
评论 0
private Matcher<HttpHeaderViewModel> withHeaderData(final String headerName, final String headerValue) {
return new CustomTypeSafeMatcher<HttpHeaderViewModel>("Header with") {
@Override
protected boolean matchesSafely(HttpHeaderViewModel viewModel) {
return viewModel.headerName().equals(headerName) &&
viewModel.headerValues().equals(headerValue);
}
};
}
TestUtilities.java 文件源码
项目:AndroidSnooper
阅读 41
收藏 0
点赞 0
评论 0
public static CustomTypeSafeMatcher<ResponseFormatter> withConcreteClass(final Class<? extends ResponseFormatter> clazz) {
return new CustomTypeSafeMatcher<ResponseFormatter>("Matches exact class " + clazz.getName()) {
@Override
protected boolean matchesSafely(ResponseFormatter object) {
return object.getClass().getName().equals(clazz.getName());
}
};
}
HttpClassSearchPresenterTest.java 文件源码
项目:AndroidSnooper
阅读 28
收藏 0
点赞 0
评论 0
@NonNull
private CustomTypeSafeMatcher<List<HttpCallRecord>> withSize(final int size) {
return new CustomTypeSafeMatcher<List<HttpCallRecord>>("with size") {
@Override
protected boolean matchesSafely(List<HttpCallRecord> item) {
return item.size() == size;
}
};
}
PublicOccupationSearchFeatureTest.java 文件源码
项目:oma-riista-web
阅读 33
收藏 0
点赞 0
评论 0
@Nonnull
private static CustomTypeSafeMatcher<PublicOccupationTypeDTO> equalToOccupationType(final OrganisationType organisationType,
final OccupationType occupationType) {
return new CustomTypeSafeMatcher<PublicOccupationTypeDTO>(
String.format("occupationType=%s organisationType=%s", occupationType, organisationType)) {
@Override
protected boolean matchesSafely(final PublicOccupationTypeDTO o) {
return o.getOccupationType() == occupationType && o.getOrganisationType() == organisationType;
}
};
}
PublicOccupationSearchFeatureTest.java 文件源码
项目:oma-riista-web
阅读 28
收藏 0
点赞 0
评论 0
@Nonnull
private static CustomTypeSafeMatcher<AddressDTO> equalToAddress(final Address address) {
return new CustomTypeSafeMatcher<AddressDTO>("Address does not match") {
@Override
protected boolean matchesSafely(final AddressDTO o) {
return Objects.equals(o.getStreetAddress(), address.getStreetAddress()) &&
Objects.equals(o.getCity(), address.getCity()) &&
Objects.equals(o.getPostalCode(), address.getPostalCode());
}
};
}
CompletableFuturesTest.java 文件源码
项目:completable-futures
阅读 29
收藏 0
点赞 0
评论 0
private static <T> Matcher<CompletionStage<T>> completesTo(final Matcher<T> expected) {
return new CustomTypeSafeMatcher<CompletionStage<T>>("completes to " + String.valueOf(expected)) {
@Override
protected boolean matchesSafely(CompletionStage<T> item) {
try {
final T value = item.toCompletableFuture().get(1, SECONDS);
return expected.matches(value);
} catch (Exception ex) {
return false;
}
}
};
}
LineMessagingClientImplWiremockTest.java 文件源码
项目:line-bot-sdk-java
阅读 29
收藏 0
点赞 0
评论 0
private CustomTypeSafeMatcher<LineMessagingException> errorResponseIs(final ErrorResponse errorResponse) {
return new CustomTypeSafeMatcher<LineMessagingException>("Error Response") {
@Override
protected boolean matchesSafely(LineMessagingException item) {
assertThat(item.getErrorResponse())
.isEqualTo(errorResponse);
return true;
}
};
}