当前位置: 首页>>代码示例>>Java>>正文


Java CustomTypeSafeMatcher类代码示例

本文整理汇总了Java中org.hamcrest.CustomTypeSafeMatcher的典型用法代码示例。如果您正苦于以下问题:Java CustomTypeSafeMatcher类的具体用法?Java CustomTypeSafeMatcher怎么用?Java CustomTypeSafeMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CustomTypeSafeMatcher类属于org.hamcrest包,在下文中一共展示了CustomTypeSafeMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldInitializeCrashView

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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));
}
 
开发者ID:ajitsing,项目名称:Sherlock,代码行数:22,代码来源:CrashPresenterTest.java

示例2: withTableLayout

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
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;
    }
  };
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:17,代码来源:EspressoViewMatchers.java

示例3: hasBackgroundSpanOn

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的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

示例4: areSortedAccordingToDate

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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;
    }
  };
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:17,代码来源:SnooperRepoTest.java

示例5: shouldReturnBoundsToHighlight

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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;
    }
  }));
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:25,代码来源:HttpCallFragmentPresenterTest.java

示例6: errorResponseViewMatches

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
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);
        }
    };
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:21,代码来源:UnhandledExceptionHandlerBaseTest.java

示例7: testInjection

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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;
        }
    });
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:26,代码来源:ModelParameterTypeListenerTest.java

示例8: testZip3

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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");
        }
    }));
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:18,代码来源:ProductsTest.java

示例9: checkNullability

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
/**
 * 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);
                }
            }
        )
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:NullabilityTest.java

示例10: checkImmutability

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
/**
 * 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);
                }
            }
        )
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:32,代码来源:ImmutabilityTest.java

示例11: matchUploadPart

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
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);
            }
        }
    };
}
 
开发者ID:peerindex,项目名称:s3-stream-uploader,代码行数:17,代码来源:S3StreamFactoryTest.java

示例12: match

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
/**
 * 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);
    }
  };
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:17,代码来源:FluentMatcher.java

示例13: testExecuteBulkPipelineDoesNotExist

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:PipelineExecutionServiceTests.java

示例14: files

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
@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));
}
 
开发者ID:tatools,项目名称:sunshine,代码行数:11,代码来源:FileSystemOfPathTest.java

示例15: withRecyclerView

import org.hamcrest.CustomTypeSafeMatcher; //导入依赖的package包/类
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;
    }
  };
}
 
开发者ID:ajitsing,项目名称:Sherlock,代码行数:10,代码来源:CustomEspressoMatchers.java


注:本文中的org.hamcrest.CustomTypeSafeMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。