本文整理了Java中org.hamcrest.core.Is
类的一些代码示例,展示了Is
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Is
类的具体详情如下:
包路径:org.hamcrest.core.Is
类名称:Is
[英]Decorates another Matcher, retaining the behaviour but allowing tests to be slightly more expressive. For example: assertThat(cheese, equalTo(smelly)) vs. assertThat(cheese, is(equalTo(smelly)))
[中]装饰另一个匹配器,保留行为,但允许测试稍微更具表现力。例如:assertThat(奶酪,equalTo(臭))与assertThat(奶酪,is(equalTo(臭)))
代码示例来源:origin: apache/flink
@Test
public void testOpenWithConfigurableReader() throws Exception {
ConfigurableDummyRecordReader recordReader = mock(ConfigurableDummyRecordReader.class);
DummyInputFormat inputFormat = mock(DummyInputFormat.class);
when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader);
HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
hadoopInputFormat.open(getHadoopInputSplit());
verify(inputFormat, times(1)).getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class));
verify(recordReader, times(1)).setConf(any(JobConf.class));
verify(recordReader, times(1)).createKey();
verify(recordReader, times(1)).createValue();
assertThat(hadoopInputFormat.fetched, is(false));
}
代码示例来源:origin: google/j2objc
/**
* A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.
* <p/>
* For example:
* <pre>assertThat(cheese, isA(Cheddar.class))</pre>
* instead of:
* <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>
*/
public static <T> org.hamcrest.Matcher<T> isA(java.lang.Class<T> type) {
return org.hamcrest.core.Is.<T>isA(type);
}
代码示例来源:origin: hamcrest/JavaHamcrest
/**
* Decorates another Matcher, retaining its behaviour, but allowing tests
* to be slightly more expressive.
* For example:
* <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
* instead of:
* <pre>assertThat(cheese, equalTo(smelly))</pre>
*
*/
public static <T> Matcher<T> is(Matcher<T> matcher) {
return new Is<>(matcher);
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldDelegateGetSegmentToParentIfIndexNotEqualToSizeMinusOne() {
Path.Segment segment = mock(Path.Segment.class);
parent = mock(Path.class);
when(parent.size()).thenReturn(10);
path = new ChildPath(parent, segment("d"));
when(parent.getSegment(anyInt())).thenReturn(segment);
for (int i = 0; i < path.size() - 1; ++i) {
assertThat(path.getSegment(i), is(sameInstance(segment)));
}
verify(parent, times(parent.size())).getSegment(anyInt());
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testReplace2Args_doesNotReplace() throws Exception {
when(numberAuthoritativeTier.replace(eq(1), eq("one"))).thenReturn(null);
TieredStore<Number, CharSequence> tieredStore = new TieredStore<>(numberCachingTier, numberAuthoritativeTier);
assertThat(tieredStore.replace(1, "one"), is(nullValue()));
verify(numberCachingTier).invalidate(any(Number.class));
verify(numberAuthoritativeTier, times(1)).replace(eq(1), eq("one"));
}
代码示例来源:origin: apache/flink
@Test
public void testFetchNextRecordReaderHasNewValue() throws Exception {
DummyRecordReader recordReader = mock(DummyRecordReader.class);
when(recordReader.nextKeyValue()).thenReturn(true);
HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
hadoopInputFormat.fetchNext();
assertThat(hadoopInputFormat.fetched, is(true));
assertThat(hadoopInputFormat.hasNext, is(true));
}
代码示例来源:origin: apache/hive
@Test
public void setupInternalStateOnObjectCreation() throws IOException, TezException {
when(dagStatus.getState()).thenReturn(DAGStatus.State.RUNNING);
when(dagClient.getVertexStatus(eq(MAPPER), anySet())).thenReturn(succeeded);
when(dagClient.getVertexStatus(eq(REDUCER), anySet())).thenReturn(running);
TezProgressMonitor monitor =
new TezProgressMonitor(dagClient, dagStatus, new ArrayList<BaseWork>(), progressMap(), console,
Long.MAX_VALUE);
verify(dagClient).getVertexStatus(eq(MAPPER), isNull(Set.class));
verify(dagClient).getVertexStatus(eq(REDUCER), isNull(Set.class));
verifyNoMoreInteractions(dagClient);
assertThat(monitor.vertexStatusMap.keySet(), hasItems(MAPPER, REDUCER));
assertThat(monitor.vertexStatusMap.get(MAPPER), is(sameInstance(succeeded)));
assertThat(monitor.vertexStatusMap.get(REDUCER), is(sameInstance(running)));
assertThat(monitor.progressCountsMap.keySet(), hasItems(MAPPER, REDUCER));
TezProgressMonitor.VertexProgress expectedMapperState =
new TezProgressMonitor.VertexProgress(2, 1, 3, 4, 5, DAGStatus.State.RUNNING);
assertThat(monitor.progressCountsMap.get(MAPPER), is(equalTo(expectedMapperState)));
TezProgressMonitor.VertexProgress expectedReducerState =
new TezProgressMonitor.VertexProgress(3, 2, 1, 0, 1, DAGStatus.State.RUNNING);
assertThat(monitor.progressCountsMap.get(REDUCER), is(equalTo(expectedReducerState)));
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldNotifyListenerOnRotationErrorDuringJobExecution() throws Exception
{
RotationListener rotationListener = mock( RotationListener.class );
Executor executor = mock( Executor.class );
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile, 10, 0,
10, executor, rotationListener );
OutputStream outputStream = supplier.get();
RejectedExecutionException exception = new RejectedExecutionException( "text exception" );
doThrow( exception ).when( executor ).execute( any( Runnable.class ) );
write( supplier, "A string longer than 10 bytes" );
assertThat( supplier.get(), is( outputStream ) );
verify( rotationListener ).rotationError( exception, outputStream );
}
代码示例来源:origin: apache/flink
@Test
public void testFetchNextRecordReaderThrowsException() throws Exception {
DummyRecordReader recordReader = mock(DummyRecordReader.class);
when(recordReader.nextKeyValue()).thenThrow(new InterruptedException());
HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
exception.expect(IOException.class);
hadoopInputFormat.fetchNext();
assertThat(hadoopInputFormat.hasNext, is(true));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_extract_http_method() {
when(request.getMethod()).thenReturn(HttpMethod.GET);
assertThat(extractor.extract(request).get(), is(HttpMethod.GET.name()));
}
}
代码示例来源:origin: org.mule.runtime/mule-core-tests
@Test
public void setsExpressionPayload() throws MuleException {
setPayloadMessageProcessor.setValue(EXPRESSION);
when(expressionManager.isExpression(EXPRESSION)).thenReturn(true);
setPayloadMessageProcessor.initialise();
TypedValue typedValue = new TypedValue(PLAIN_TEXT, DataType.STRING);
when(expressionManager.evaluate(EXPRESSION, testEvent())).thenReturn(typedValue);
when(expressionManager.evaluate(eq(EXPRESSION), eq(testEvent()), any(CoreEvent.Builder.class), eq(null)))
.thenReturn(typedValue);
CoreEvent response = setPayloadMessageProcessor.process(testEvent());
assertThat(response.getMessage().getPayload().getValue(), is(PLAIN_TEXT));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testPutIfAbsent_whenAbsent() throws Exception {
TieredStore<Number, CharSequence> tieredStore = new TieredStore<>(numberCachingTier, numberAuthoritativeTier);
assertThat(tieredStore.putIfAbsent(1, "one", b -> {}), is(nullValue()));
verify(numberCachingTier, times(1)).invalidate(eq(1));
verify(numberAuthoritativeTier, times(1)).putIfAbsent(eq(1), eq("one"), any());
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void checksWhetherHeadersExist() {
assertThat(headers.contains("header1"), is(true));
assertThat(headers.contains("header2"), is(true));
assertThat(headers.contains("nonExistent"), is(false));
}
代码示例来源:origin: spotify/helios
assumeThat(dockerClient.version(), is(execCompatibleDockerVersion()));
verify(registrar, never()).register(any(ServiceRegistration.class));
dockerClient.close();
verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS)))
.register(registrationCaptor.capture());
final ServiceRegistration serviceRegistration = registrationCaptor.getValue();
代码示例来源:origin: org.mule.runtime/mule-core-tests
@Test
public void transformerFactoryProperties() {
SetPropertyAnswer setPropertyAnswer = new SetPropertyAnswer(transformerFactory);
doAnswer(setPropertyAnswer).when(transformerFactoryWrapper).setAttribute(anyString(), anyObject());
defaultXMLSecureFactories.configureTransformerFactory(transformerFactoryWrapper);
assertThat(setPropertyAnswer.exception, is(nullValue()));
for (String property : FACTORY_ATTRIBUTES) {
verify(transformerFactoryWrapper).setAttribute(property, "");
}
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void emptyHeadersHasEmptyNames() {
HttpHeaders httpHeaders = new HttpHeaders.Builder().build();
assertThat(httpHeaders.names(), is(emptyIterable()));
}
代码示例来源:origin: org.mule.runtime/mule-core-tests
@Test
public void resolveBooleanWithBooleanStringValue() {
AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:expression]", BOOLEAN);
attributeEvaluator.initialize(mockExpressionManager);
final String expectedValue = "true";
doReturn(new TypedValue<>(Boolean.valueOf(expectedValue), BOOLEAN))
.when(mockExpressionManager)
.evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class));
assertThat(attributeEvaluator.resolveValue(event), is(Boolean.valueOf(expectedValue)));
}
代码示例来源:origin: neo4j/neo4j
private void assertLogOccurred( Level level, String message )
{
ArrayList<LoggingEvent> events = getLoggingEvents();
assertThat( events, hasSize( 1 ) );
LoggingEvent event = events.get( 0 );
assertThat( event.getLoggerName(), is( getClass().getName() ) );
assertThat( event.getLevel(), is( level ) );
assertThat( event.getMessage(), is( message ) );
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void retrievesPreviouslyRegisteredTimer() {
Timer timer = metricRegistry.timer("newTimer");
assertThat(timer, is(notNullValue()));
assertThat(metricRegistry.timer("newTimer"), is(sameInstance(timer)));
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldCreatePathThatPointsToFile() throws Exception
{
fsa.mkdirs( path );
assertTrue( fsa.fileExists( path ) );
path = new File( path, "some_file" );
try ( StoreChannel channel = fsa.create( path ) )
{
assertThat( channel, is( not( nullValue() ) ) );
fsa.mkdirs( path );
assertTrue( fsa.fileExists( path ) );
}
}
内容来源于网络,如有侵权,请联系作者删除!