org.springframework.util.Assert.isInstanceOf()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(463)

本文整理了Java中org.springframework.util.Assert.isInstanceOf()方法的一些代码示例,展示了Assert.isInstanceOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.isInstanceOf()方法的具体详情如下:
包路径:org.springframework.util.Assert
类名称:Assert
方法名:isInstanceOf

Assert.isInstanceOf介绍

[英]Assert that the provided object is an instance of the provided class.

Assert.instanceOf(Foo.class, foo);

[中]断言所提供的对象是所提供类的实例

Assert.instanceOf(Foo.class, foo);

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
  Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory,
      "AnnotationInjectedBeanPostProcessor requires a ConfigurableListableBeanFactory");
  this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public void setEnvironment(Environment environment) {
  Assert.isInstanceOf(ConfigurableEnvironment.class, environment);
  this.environment = (ConfigurableEnvironment) environment;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Assert that the provided object is an instance of the provided class.
 * <pre class="code">Assert.instanceOf(Foo.class, foo);</pre>
 * @param type the type to check against
 * @param obj the object to check
 * @throws IllegalArgumentException if the object is not an instance of type
 */
public static void isInstanceOf(Class<?> type, @Nullable Object obj) {
  isInstanceOf(type, obj, "");
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code MappingJackson2CborHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be configured with a {@code CBORFactory} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#cbor()
 */
public MappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) {
  super(objectMapper, new MediaType("application", "cbor"));
  Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * The {@code ObjectMapper} must be configured with a {@code SmileFactory} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
  Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
  super.setObjectMapper(objectMapper);
}

代码示例来源:origin: spring-projects/spring-framework

private MockHttpServletResponse unwrapResponseIfNecessary(ServletResponse servletResponse) {
  while (servletResponse instanceof HttpServletResponseWrapper) {
    servletResponse = ((HttpServletResponseWrapper) servletResponse).getResponse();
  }
  Assert.isInstanceOf(MockHttpServletResponse.class, servletResponse);
  return (MockHttpServletResponse) servletResponse;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * The {@code ObjectMapper} parameter must be a {@link XmlMapper} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
  Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
  super.setObjectMapper(objectMapper);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code MappingJackson2SmileHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be configured with a {@code SmileFactory} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#smile()
 */
public MappingJackson2SmileHttpMessageConverter(ObjectMapper objectMapper) {
  super(objectMapper, new MediaType("application", "x-jackson-smile"));
  Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
@Override
public Object resolveArgumentValue(
    MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {
  Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext);
  return ((InitBinderBindingContext) bindingContext).getSessionStatus();
}

代码示例来源:origin: spring-projects/spring-framework

public Mono<WebSession> updateLastAccessTime(WebSession session) {
  return Mono.fromSupplier(() -> {
    Assert.isInstanceOf(InMemoryWebSession.class, session);
    ((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant());
    return session;
  });
}

代码示例来源:origin: spring-projects/spring-framework

public final void sendMessage(WebSocketMessage<?> message) throws IOException {
  Assert.state(!isClosed(), "Cannot send a message when session is closed");
  Assert.isInstanceOf(TextMessage.class, message, "SockJS supports text messages only");
  sendMessageInternal(((TextMessage) message).getPayload());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code MappingJackson2XmlHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be a {@link XmlMapper} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#xml()
 */
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
  super(objectMapper, new MediaType("application", "xml"),
      new MediaType("text", "xml"),
      new MediaType("application", "*+xml"));
  Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndNullMessage() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Object of class [java.lang.Long] must be an instance of class java.lang.String");
  Assert.isInstanceOf(String.class, 42L, (String) null);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndCustomMessageWithSeparator() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage(
      "Custom message: Object of class [java.lang.Long] must be an instance of class java.lang.String");
  Assert.isInstanceOf(String.class, 42L, "Custom message:");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithNullType() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Type to check against must not be null");
  Assert.isInstanceOf(null, "foo", "enigma");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndCustomMessage() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Custom message: java.lang.Long");
  Assert.isInstanceOf(String.class, 42L, "Custom message");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndCustomMessageWithSpace() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Custom message for java.lang.Long");
  Assert.isInstanceOf(String.class, 42L, "Custom message for ");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithNullInstanceAndMessageSupplier() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("enigma: null");
  Assert.isInstanceOf(String.class, null, () -> "enigma");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndNullMessageSupplier() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Object of class [java.lang.Long] must be an instance of class java.lang.String");
  Assert.isInstanceOf(String.class, 42L, (Supplier<String>) null);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void isInstanceOfWithTypeMismatchAndMessageSupplier() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("enigma: java.lang.Long");
  Assert.isInstanceOf(String.class, 42L, () -> "enigma");
}

相关文章