Skip to content

Fix tests catching nested exceptions #4136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,7 @@
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.ScopeNotActiveException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -117,7 +118,9 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("job scope"));
}

@Test
Expand All @@ -128,7 +131,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("job scope"));
}

@Test
Expand All @@ -148,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
Callable<String> value = context.getBean(Callable.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("job scope"));
}

public void init(Class<?>... config) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.ScopeNotActiveException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -116,7 +117,9 @@ public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("step scope"));
}

@Test
Expand All @@ -127,7 +130,9 @@ public void testIntentionallyBlowupWithForcedInterface() throws Exception {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("step scope"));
}

@Test
Expand All @@ -148,7 +153,9 @@ public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Except
Callable<String> value = context.getBean(Callable.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
assertTrue(expectedException instanceof ScopeNotActiveException);
String message = expectedException.getCause().getMessage();
assertTrue(message.contains("step scope"));
}

public void init(Class<?>... config) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -180,7 +180,7 @@ public void testProcessorNonTransactionalNotAllowedWithTransactionalReader() thr
fail("Expected BeanCreationException");
}
catch (BeanCreationException e) {
String msg = e.getMessage();
String msg = e.getRootCause().getMessage();
assertTrue("Wrong message: " + msg,
msg.contains("The field 'processor-transactional' cannot be false if 'reader-transactional"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2014 the original author or authors.
* Copyright 2009-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,7 +58,7 @@ public void testNextOutOfScope() {
fail("Error expected");
}
catch (BeanCreationException e) {
String message = e.getMessage();
String message = e.getRootCause().getMessage();
assertTrue("Wrong message: " + message, message
.matches(".*Missing state for \\[StateTransition: \\[state=.*s2, pattern=\\*, next=.*s3\\]\\]"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -622,8 +622,8 @@ public void write(List<? extends String> item) throws Exception {
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
repository.add(stepExecution);
step.execute(stepExecution);
String message = stepExecution.getFailureExceptions().get(0).getMessage();
assertTrue("Wrong message: " + message, message.contains("Write error - planned but not skippable."));
String message = stepExecution.getFailureExceptions().get(0).getCause().getMessage();
assertEquals("Wrong message: " + message, "Write error - planned but not skippable.", message);

List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray(""));
assertEquals(expectedOutput, written);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,7 +79,7 @@ public class ChunkMessageItemWriterIntegrationTests {

@Before
public void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().generateUniqueName(true)
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,7 +91,7 @@ public void testNoReply() {
fail();
}
catch (MessagingException e) {
String message = e.getMessage();
String message = e.getCause().getMessage();
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
}
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2008-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.integration.launch;

import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -57,7 +72,7 @@ public void testNoReply() {
requestChannel.send(trigger);
}
catch (MessagingException e) {
String message = e.getMessage();
String message = e.getCause().getMessage();
assertTrue("Wrong message: " + message, message.contains("replyChannel"));
}
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
Expand Down