Polish JmsAccessor[Tests]
This commit is contained in:
@@ -121,15 +121,16 @@ public abstract class JmsAccessor implements InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JMS acknowledgement mode by the name of the corresponding constant
|
||||
* in the JMS {@link Session} interface, e.g. "CLIENT_ACKNOWLEDGE".
|
||||
* Set the JMS acknowledgement mode by the name of the corresponding constant in
|
||||
* the JMS {@link Session} interface — for example, {@code "CLIENT_ACKNOWLEDGE"}.
|
||||
* <p>If you want to use vendor-specific extensions to the acknowledgement mode,
|
||||
* use {@link #setSessionAcknowledgeMode(int)} instead.
|
||||
* @param constantName the name of the {@link Session} acknowledge mode constant
|
||||
* @see jakarta.jms.Session#AUTO_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Session#CLIENT_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Session#DUPS_OK_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Connection#createSession(boolean, int)
|
||||
* @see jakarta.jms.Session#SESSION_TRANSACTED
|
||||
* @see jakarta.jms.Connection#createSession(int)
|
||||
*/
|
||||
public void setSessionAcknowledgeModeName(String constantName) {
|
||||
setSessionAcknowledgeMode(sessionConstants.asNumber(constantName).intValue());
|
||||
@@ -149,6 +150,7 @@ public abstract class JmsAccessor implements InitializingBean {
|
||||
* @see jakarta.jms.Session#AUTO_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Session#CLIENT_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Session#DUPS_OK_ACKNOWLEDGE
|
||||
* @see jakarta.jms.Session#SESSION_TRANSACTED
|
||||
* @see jakarta.jms.Connection#createSession(boolean, int)
|
||||
*/
|
||||
public void setSessionAcknowledgeMode(int sessionAcknowledgeMode) {
|
||||
|
||||
@@ -25,55 +25,56 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link JmsAccessor} class.
|
||||
* Unit tests for {@link JmsAccessor}.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
* @author Vedran Pavic
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class JmsAccessorTests {
|
||||
|
||||
/**
|
||||
* No-op stub of the {@link JmsAccessor} class.
|
||||
*/
|
||||
private final JmsAccessor accessor = new JmsAccessor() {};
|
||||
|
||||
|
||||
@Test
|
||||
void testChokesIfConnectionFactoryIsNotSupplied() {
|
||||
JmsAccessor accessor = new StubJmsAccessor();
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
accessor::afterPropertiesSet);
|
||||
void failsIfConnectionFactoryIsNotSupplied() {
|
||||
assertThatIllegalArgumentException().isThrownBy(accessor::afterPropertiesSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSessionTransactedModeReallyDoesDefaultToFalse() {
|
||||
JmsAccessor accessor = new StubJmsAccessor();
|
||||
assertThat(accessor.isSessionTransacted()).as("The [sessionTransacted] property of JmsAccessor must default to " +
|
||||
"false. Change this test (and the attendant Javadoc) if you have " +
|
||||
"changed the default.").isFalse();
|
||||
void sessionTransactedModeDefaultsToFalse() {
|
||||
String message = """
|
||||
The [sessionTransacted] property of JmsAccessor must default to \
|
||||
false. Change this test (and the attendant Javadoc) if you have \
|
||||
changed the default.""";
|
||||
assertThat(accessor.isSessionTransacted()).as(message).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAcknowledgeModeReallyDoesDefaultToAutoAcknowledge() {
|
||||
JmsAccessor accessor = new StubJmsAccessor();
|
||||
assertThat(accessor.getSessionAcknowledgeMode()).as("The [sessionAcknowledgeMode] property of JmsAccessor must default to " +
|
||||
"[Session.AUTO_ACKNOWLEDGE]. Change this test (and the attendant " +
|
||||
"Javadoc) if you have changed the default.").isEqualTo(Session.AUTO_ACKNOWLEDGE);
|
||||
void acknowledgeModeDefaultsToAutoAcknowledge() {
|
||||
String message = """
|
||||
The [sessionAcknowledgeMode] property of JmsAccessor must default to \
|
||||
"[Session.AUTO_ACKNOWLEDGE]. Change this test (and the attendant \
|
||||
"Javadoc) if you have changed the default.""";
|
||||
assertThat(accessor.getSessionAcknowledgeMode()).as(message).isEqualTo(Session.AUTO_ACKNOWLEDGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAcknowledgeModeNameChokesIfBadAckModeIsSupplied() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new StubJmsAccessor().setSessionAcknowledgeModeName("Tally ho chaps!"));
|
||||
void setSessionAcknowledgeModeNameToUnsupportedValues() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> accessor.setSessionAcknowledgeModeName(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> accessor.setSessionAcknowledgeModeName(" "));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> accessor.setSessionAcknowledgeModeName("bogus"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomAcknowledgeModeIsConsideredClientAcknowledge() throws Exception {
|
||||
Session session = mock(Session.class);
|
||||
void customAcknowledgeModeIsConsideredClientAcknowledge() throws Exception {
|
||||
Session session = mock();
|
||||
given(session.getAcknowledgeMode()).willReturn(100);
|
||||
JmsAccessor accessor = new StubJmsAccessor();
|
||||
assertThat(accessor.isClientAcknowledge(session)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crummy, stub, do-nothing subclass of the JmsAccessor class for use in testing.
|
||||
*/
|
||||
private static final class StubJmsAccessor extends JmsAccessor {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user