當前位置: 首頁>>代碼示例>>Java>>正文


Java IsInstanceOf類代碼示例

本文整理匯總了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);

}
 
開發者ID:financialforcedev,項目名稱:orizuru-java,代碼行數:20,代碼來源:MessageTest.java

示例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);

}
 
開發者ID:financialforcedev,項目名稱:orizuru-java,代碼行數:18,代碼來源:AbstractConsumerTest.java

示例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);

}
 
開發者ID:financialforcedev,項目名稱:orizuru-java,代碼行數:18,代碼來源:AbstractConsumerTest.java

示例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);

}
 
開發者ID:financialforcedev,項目名稱:orizuru-java,代碼行數:23,代碼來源:AbstractPublisherTest.java

示例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);

}
 
開發者ID:financialforcedev,項目名稱:orizuru-java,代碼行數:23,代碼來源:AbstractPublisherTest.java

示例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));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:RestTriggerResourceTest.java

示例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);
    }
}
 
開發者ID:IG-Group,項目名稱:cdversion-maven-extension,代碼行數:22,代碼來源:CDVersionLifecycleParticipantTest.java

示例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);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:24,代碼來源:DefaultAsyncSecurityLogicTest.java

示例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);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:23,代碼來源:DefaultAsyncSecurityLogicTest.java

示例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);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:23,代碼來源:DefaultAsyncSecurityLogicTest.java

示例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);

}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:20,代碼來源:DefaultAsyncSecurityLogicTest.java

示例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);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:25,代碼來源:DefaultAsyncSecurityLogicTest.java

示例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")));

}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:26,代碼來源:TeamActivityStartTest.java

示例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));
}
 
開發者ID:trustedanalytics,項目名稱:hive-broker,代碼行數:18,代碼來源:KerberosDataSourceTest.java

示例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);
}
 
開發者ID:vzhukovskii,項目名稱:che-gradle-plugin,代碼行數:17,代碼來源:GradleProjectTypeUnitTest.java


注:本文中的org.hamcrest.core.IsInstanceOf類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。