Refine search
@Test @SuppressWarnings("resource") public void invalidProxy() { thrown.expect(BeanCreationException.class); thrown.expectCause(is(instanceOf(IllegalStateException.class))); thrown.expectMessage("handleIt2"); new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, InvalidProxyTestBean.class); }
@Test public void withMissingPropertySource() { thrown.expect(BeanDefinitionStoreException.class); thrown.expectCause(isA(FileNotFoundException.class)); new AnnotationConfigApplicationContext(ConfigWithMissingPropertySource.class); }
private void expectContainerMissingValueAttribute() { exception.expect(AnnotationConfigurationException.class); exception.expectMessage(startsWith("Invalid declaration of container type")); exception.expectMessage(containsString(ContainerMissingValueAttribute.class.getName())); exception.expectMessage(containsString("for repeatable annotation")); exception.expectMessage(containsString(InvalidRepeatable.class.getName())); exception.expectCause(isA(NoSuchMethodException.class)); }
@Test public void testIndexTaskTuningConfigTargetPartitionSizeAndNumShards() throws Exception { thrown.expectCause(CoreMatchers.isA(IllegalArgumentException.class)); jsonMapper.readValue( "{\"type\":\"index\", \"targetPartitionSize\":10, \"numShards\":10}", IndexTask.IndexTuningConfig.class ); }
@Test public void loadIndexWithException() throws IOException { final IOException cause = new IOException("test exception"); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Unable to load indexes"); this.thrown.expectCause(is(cause)); CandidateComponentsIndexLoader.loadIndex(new CandidateComponentsTestClassLoader( getClass().getClassLoader(), cause)); }
@Test public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException { Stream<Integer> stream = Arrays.asList(1, 2, 3).stream(); TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); thrown.expect(ConversionFailedException.class); thrown.expectCause(is(instanceOf(ConverterNotFoundException.class))); this.conversionService.convert(stream, arrayOfLongs); }
@Test public void shouldForceUserToCallWith() { expected.expectCause( allOf( instanceOf( IllegalArgumentException.class ), hasProperty( "message", is( "You need to call 'with(GraphDatabaseService)' on the template in order to use it" ) ) ) ); TransactionTemplate transactionTemplate = new TransactionTemplate(); transactionTemplate.execute( transaction -> null ); }
@Test public void testBadTypeSerde() throws IOException { final String json = "{" + "\"format\":\"foo\", " + "\"timestampSpec\": {\"column\":\"timestamp\"}, " + "\"dimensionsSpec\":{}" + "}"; final Object mapValue = mapper.readValue(json, JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT); expectedException.expect(IllegalArgumentException.class); expectedException.expectCause(CoreMatchers.instanceOf(JsonMappingException.class)); expectedException.expectMessage("Could not resolve type id 'foo' into a subtype"); mapper.convertValue(mapValue, ParseSpec.class); } }
@Test public void invokeListenerCheckedException() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "generateCheckedException", GenericTestEvent.class); GenericTestEvent<String> event = createGenericTestEvent("fail"); this.thrown.expect(UndeclaredThrowableException.class); this.thrown.expectCause(is(instanceOf(IOException.class))); invokeListener(method, event); }
@Test public void input_stream_should_be_closed() throws Exception { logInAsSystemAdministrator(); InputStream inputStream = newInputStream(plugin.toPath()); call(inputStream, PLUGIN_NAME); // As the same InputStream is used, it will fail as it should have been called during the first execution of the WS expectedException.expectCause(hasType(ClosedChannelException.class)); call(inputStream, PLUGIN_NAME); }
@Test public void testFailWithExceptionDuringPublish() throws Exception { expectedException.expect(ExecutionException.class); expectedException.expectCause(CoreMatchers.instanceOf(RuntimeException.class)); expectedException.expectMessage("test"); testFailDuringPublishInternal(true); }
@Override @Test public void jmsHandlerMethodFactoryConfiguration() throws JMSException { ApplicationContext context = new ClassPathXmlApplicationContext( "annotation-driven-custom-handler-method-factory.xml", getClass()); thrown.expect(ListenerExecutionFailedException.class); thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class)); testJmsHandlerMethodFactoryConfiguration(context); }
@Test public void failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption() throws IOException { addCorruptedCommandsToLastLogFile(); expectedException.expectCause( new RootCauseMatcher<>( NegativeArraySizeException.class ) ); GraphDatabaseService recoveredDatabase = databaseFactory.newEmbeddedDatabase( storeDir ); recoveredDatabase.shutdown(); }
@Test public void invokeListenerRuntimeException() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "generateRuntimeException", GenericTestEvent.class); GenericTestEvent<String> event = createGenericTestEvent("fail"); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Test exception"); this.thrown.expectCause(is((Throwable) isNull())); invokeListener(method, event); }
@Override @Test public void jmsHandlerMethodFactoryConfiguration() throws JMSException { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class); thrown.expect(ListenerExecutionFailedException.class); thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class)); testJmsHandlerMethodFactoryConfiguration(context); }
@Test public void commitTimeNotAccessibleBeforeCommit() { db.registerTransactionEventHandler( getBeforeCommitHandler( TransactionData::getCommitTime ) ); String message = "Transaction commit time is not assigned yet. It will be assigned during transaction commit."; expectedException.expectCause( new RootCauseMatcher<>( IllegalStateException.class, message ) ); runTransaction(); }
@Test public void testFailDuringPublish() throws Exception { expectedException.expect(ExecutionException.class); expectedException.expectCause(CoreMatchers.instanceOf(ISE.class)); expectedException.expectMessage("Failed to publish segments."); testFailDuringPublishInternal(false); }
@Test public void fromMessageWithFailedConversion() { Message<String> content = MessageBuilder.withPayload("test not a number").build(); thrown.expect(MessageConversionException.class); thrown.expectCause(isA(ConversionException.class)); converter.fromMessage(content, Integer.class); } }
@Test public void transactionIdNotAccessibleBeforeCommit() { db.registerTransactionEventHandler( getBeforeCommitHandler( TransactionData::getTransactionId ) ); String message = "Transaction id is not assigned yet. It will be assigned during transaction commit."; expectedException.expectCause( new RootCauseMatcher<>( IllegalStateException.class, message ) ); runTransaction(); }
@Test public void testCountStarWithTimeFilterUsingStringLiteralsInvalid() throws Exception { // Strings are implicitly cast to timestamps. Test an invalid string. // This error message isn't ideal but it is at least better than silently ignoring the problem. expectedException.expect(RuntimeException.class); expectedException.expectMessage("Error while applying rule ReduceExpressionsRule"); expectedException.expectCause( ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("Illegal TIMESTAMP constant")) ); testQuery( "SELECT COUNT(*) FROM druid.foo\n" + "WHERE __time >= 'z2000-01-01 00:00:00' AND __time < '2001-01-01 00:00:00'\n", ImmutableList.of(), ImmutableList.of() ); }