Skip to content

Commit

Permalink
Polish JmsAccessor[Tests]
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jul 19, 2023
1 parent 4e00c98 commit 15253f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ public boolean isSessionTransacted() {
}

/**
* 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());
Expand All @@ -149,6 +150,7 @@ public void setSessionAcknowledgeModeName(String constantName) {
* @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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,56 @@
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 {
}

}

0 comments on commit 15253f3

Please sign in to comment.