本文整理汇总了Java中org.hamcrest.core.IsInstanceOf类的典型用法代码示例。如果您正苦于以下问题:Java IsInstanceOf类的具体用法?Java IsInstanceOf怎么用?Java IsInstanceOf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IsInstanceOf类属于org.hamcrest.core包,在下文中一共展示了IsInstanceOf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Transport
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void decodeFromTransport_shouldThrowADecodeMessageExceptionWithAClassNotFoundExceptionIfTheMessageSchemaNameClassDoesNotExist()
throws Exception {
// expect
exception.expect(DecodeMessageException.class);
exception.expectMessage("Failed to consume message: Failed to decode message");
exception.expectCause(IsInstanceOf.<Throwable>instanceOf(ClassNotFoundException.class));
// given
Transport transport = new Transport();
transport.setMessageSchemaName("invalid");
Message message = new Message();
// when
message.decodeFromTransport(transport);
}
示例2: consume_throwsAHandleMessageExceptionForAnInvalidMessage
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void consume_throwsAHandleMessageExceptionForAnInvalidMessage() throws Exception {
// expect
exception.expect(HandleMessageException.class);
exception.expectMessage("Failed to consume message: Failed to handle message");
exception.expectCause(IsInstanceOf.<Throwable>instanceOf(NullPointerException.class));
// given
byte[] body = VALID_MESSAGE.getBytes();
IConsumer consumer = new ErrorConsumer(QUEUE_NAME);
// when
consumer.consume(body);
}
示例3: consume_throwsAHandleMessageExceptionWithAnAlteredInvalidMessage
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void consume_throwsAHandleMessageExceptionWithAnAlteredInvalidMessage() throws Exception {
// expect
exception.expect(HandleMessageException.class);
exception.expectMessage("Failed to consume message: Failed to handle message: test");
exception.expectCause(IsInstanceOf.<Throwable>instanceOf(NullPointerException.class));
// given
byte[] body = VALID_MESSAGE.getBytes();
IConsumer consumer = new ErrorConsumer2(QUEUE_NAME);
// when
consumer.consume(body);
}
示例4: publish_shouldThrowAnEncodeTransportExceptionForAnInvalidTransportMessage
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void publish_shouldThrowAnEncodeTransportExceptionForAnInvalidTransportMessage() throws Exception {
// expect
exception.expect(EncodeMessageContentException.class);
exception.expectCause(IsInstanceOf.<Throwable>instanceOf(ClassCastException.class));
exception.expectMessage("Failed to publish message: Failed to encode message content");
// given
Context context = mock(Context.class);
when(context.getSchema())
.thenReturn(new Schema.Parser().parse("{\"name\":\"test\",\"type\":\"record\",\"fields\":[]}"));
when(context.getDataBuffer()).thenReturn(ByteBuffer.wrap("{}".getBytes()));
GenericRecordBuilder builder = new GenericRecordBuilder(schema);
builder.set("testString", Boolean.TRUE);
Record record = builder.build();
// when
publisher.publish(context, record);
}
示例5: publish_shouldThrowAnEncodeTransportExceptionForAnInvalidTransportContext
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void publish_shouldThrowAnEncodeTransportExceptionForAnInvalidTransportContext() throws Exception {
// expect
exception.expect(EncodeTransportException.class);
exception.expectCause(IsInstanceOf.<Throwable>instanceOf(NullPointerException.class));
exception.expectMessage("Failed to publish message: Failed to encode transport");
// given
Context context = mock(Context.class);
when(context.getSchema())
.thenReturn(new Schema.Parser().parse("{\"name\":\"test\",\"type\":\"record\",\"fields\":[]}"));
when(context.getDataBuffer()).thenReturn(null);
GenericRecordBuilder builder = new GenericRecordBuilder(schema);
builder.set("testString", "testString");
Record record = builder.build();
// when
publisher.publish(context, record);
}
示例6: testAction
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testAction() throws Exception {
RestTriggerResource.Action action = new RestTriggerResource()
.redirectToAction();
RequestParameters params = new RequestParameters();
params.setId(1L);
UriInfo uri = Mockito.mock(UriInfo.class);
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle(PARAM_VERSION, "v" + VERSION_1);
when(uri.getPathParameters()).thenReturn(map);
Response response = action.getCollection(uri, params);
assertThat(response.getEntity(),
IsInstanceOf.instanceOf(RepresentationCollection.class));
assertNull(action.getItem(uri, params));
}
示例7: testAfterSessionStart_nullRevision
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testAfterSessionStart_nullRevision()
throws MavenExecutionException,
RevisionGeneratorException {
String revision = null;
exceptions.expect(MavenExecutionException.class);
exceptions.expectMessage("RevisionGenerator returned a null revision value");
exceptions.expectCause(IsInstanceOf.any(RevisionGeneratorException.class));
when(revisionGenerator.getRevision()).thenReturn(revision);
try {
item.afterSessionStart(session);
} finally {
verify(revisionGenerator).init(eq(session), any(Logger.class));
verify(revisionGenerator).getRevision();
verifyNoMoreInteractions(revisionGenerator);
verifyZeroInteractions(session);
verifyZeroInteractions(pluginMerger);
verifyZeroInteractions(plugins);
}
}
示例8: testAlreadyAuthenticatedNotAuthorized
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test(timeout = 1000)
public void testAlreadyAuthenticatedNotAuthorized(final TestContext testContext) throws Exception {
simulatePreviousAuthenticationSuccess();
final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME);
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient);
when(config.getClients()).thenReturn(clients);
final String authorizers = NAME;
addSingleAuthorizerToConfig((context, prof) -> prof.get(0).getId().equals(BAD_USERNAME));
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
final Async async = testContext.async();
final CompletableFuture<Object> result = simulatePreviousAuthenticationSuccess()
.thenCompose(v -> asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, authorizers, null));
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
hasProperty("message", is("forbidden")),
hasProperty("code", is(403))));
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
assertThat(status.get(), is(403));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例9: testAuthorizerThrowsRequiresHttpAction
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test(timeout = 1000)
public void testAuthorizerThrowsRequiresHttpAction(final TestContext testContext) throws Exception {
simulatePreviousAuthenticationSuccess();
final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME);
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient);
when(config.getClients()).thenReturn(clients);
final String authorizers = NAME;
addSingleAuthorizerToConfig((context, prof) -> { throw HttpAction.status("bad request", 400, context); });
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
final Async async = testContext.async();
final CompletableFuture<Object> result = simulatePreviousAuthenticationSuccess()
.thenCompose(v -> asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, authorizers, null));
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
hasProperty("message", is("bad request")),
hasProperty("code", is(400))));
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
assertThat(status.get(), is(400));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例10: testDirectClientThrowsRequiresHttpAction
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testDirectClientThrowsRequiresHttpAction(final TestContext testContext) throws Exception {
final AsyncClient directClient = getMockDirectClient(NAME, TEST_CREDENTIALS);
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, directClient);
when(config.getClients()).thenReturn(clients);
final String clientNames = NAME;
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
when(directClient.getCredentials(eq(webContext))).thenReturn(delayedException(250,
(() -> HttpAction.status("bad request", 400, webContext))));
final Async async = testContext.async();
final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
hasProperty("message", is("bad request")),
hasProperty("code", is(400))));
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
assertThat(status.get(), is(400));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例11: testDoubleDirectClientChooseBadDirectClient
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testDoubleDirectClientChooseBadDirectClient(final TestContext testContext) throws Exception {
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = doubleDirectClients();
when(config.getClients()).thenReturn(clients);
final String clientNames = NAME;
when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, true, config, httpActionAdapter);
final Async async = testContext.async();
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(TechnicalException.class),
hasProperty("message", is("Client not allowed: " + VALUE))));
final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例12: testDoubleIndirectClientBadOneChosen
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testDoubleIndirectClientBadOneChosen(final TestContext testContext) throws Exception {
final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME, PAC4J_URL);
final AsyncClient<TestCredentials, TestProfile> indirectClient2 = getMockIndirectClient(VALUE, PAC4J_BASE_URL);
final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient, indirectClient2);
when(config.getClients()).thenReturn(clients);
final String clientNames = NAME;
when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);
asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
final Async async = testContext.async();
exception.expect(CompletionException.class);
exception.expectCause(allOf(IsInstanceOf.instanceOf(TechnicalException.class),
hasProperty("message", is("Client not allowed: " + VALUE))));
final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
assertThat(o, is(nullValue()));
verify(accessGrantedAdapter, times(0)).adapt(webContext);
}), async);
}
示例13: shouldHaveTitleAndSubtitle
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void shouldHaveTitleAndSubtitle() {
ViewInteraction textView = onView(
allOf(withText("Turbo Chat"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0)),
0),
isDisplayed()));
textView.check(matches(withText("Turbo Chat")));
ViewInteraction textView2 = onView(
allOf(withText("Teams"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0)),
1),
isDisplayed()));
textView2.check(matches(withText("Teams")));
}
示例14: getConnectionTest_registerDriver_returnsConnection
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void getConnectionTest_registerDriver_returnsConnection() throws SQLException {
//given
DataSource ds = KerberosDataSource.Builder.create()
.connectTo("jdbc:hive2://localhost:10000/")
.asWho("jojo")
.useKeyTab("/some/path/to/keytab.file")
.with(hadoopConf)
.with(loginManager).build();
((KerberosDataSource)ds).JDBC_DRIVER = MockedJdbcDriver.class.getCanonicalName();
//when
Connection conn = ds.getConnection();
//then
Assert.assertThat(conn, IsInstanceOf.instanceOf(MockConnection.class));
}
示例15: testShouldVerifyRegisteredProjectType
import org.hamcrest.core.IsInstanceOf; //导入依赖的package包/类
@Test
public void testShouldVerifyRegisteredProjectType() throws Exception {
ProjectTypeRegistry registry = injector.getInstance(ProjectTypeRegistry.class);
ProjectTypeDef projectType = registry.getProjectType(PROJECT_TYPE_ID);
assertNotNull(projectType);
assertThat(projectType, new IsInstanceOf(GradleProjectType.class));
assertEquals(projectType.getId(), PROJECT_TYPE_ID);
assertEquals(projectType.getDisplayName(), PROJECT_TYPE_DISPLAY_NAME);
assertEquals(projectType.getParents().size(), 1);
assertEquals(projectType.getParents().get(0), PROJECT_TYPE_PARENT);
assertEquals(projectType.isMixable(), PROJECT_TYPE_MIXABLE);
assertEquals(projectType.isPrimaryable(), PROJECT_TYPE_PRIMARY);
assertEquals(projectType.isPersisted(), PROJECT_TYPE_PERSISTED);
}