@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory, "AnnotationInjectedBeanPostProcessor requires a ConfigurableListableBeanFactory"); this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; }
@Override public void setEnvironment(Environment environment) { Assert.isInstanceOf(ConfigurableEnvironment.class, environment); this.environment = (ConfigurableEnvironment) environment; }
/** * 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, ""); }
/** * 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"); }
/** * {@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); }
private MockHttpServletResponse unwrapResponseIfNecessary(ServletResponse servletResponse) { while (servletResponse instanceof HttpServletResponseWrapper) { servletResponse = ((HttpServletResponseWrapper) servletResponse).getResponse(); } Assert.isInstanceOf(MockHttpServletResponse.class, servletResponse); return (MockHttpServletResponse) servletResponse; }
/** * {@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); }
/** * 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"); }
@Nullable @Override public Object resolveArgumentValue( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext); return ((InitBinderBindingContext) bindingContext).getSessionStatus(); }
public Mono<WebSession> updateLastAccessTime(WebSession session) { return Mono.fromSupplier(() -> { Assert.isInstanceOf(InMemoryWebSession.class, session); ((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant()); return session; }); }
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()); }
/** * 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"); }
@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); }
@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:"); }
@Test public void isInstanceOfWithNullType() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Type to check against must not be null"); Assert.isInstanceOf(null, "foo", "enigma"); }
@Test public void isInstanceOfWithTypeMismatchAndCustomMessage() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Custom message: java.lang.Long"); Assert.isInstanceOf(String.class, 42L, "Custom message"); }
@Test public void isInstanceOfWithTypeMismatchAndCustomMessageWithSpace() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Custom message for java.lang.Long"); Assert.isInstanceOf(String.class, 42L, "Custom message for "); }
@Test public void isInstanceOfWithNullInstanceAndMessageSupplier() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma: null"); Assert.isInstanceOf(String.class, null, () -> "enigma"); }
@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); }
@Test public void isInstanceOfWithTypeMismatchAndMessageSupplier() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma: java.lang.Long"); Assert.isInstanceOf(String.class, 42L, () -> "enigma"); }