Skip to content

Commit

Permalink
Assert DefaultMessageListenerContainer.setCacheLevel() values
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jul 31, 2023
1 parent 81181c3 commit b45bfca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void setCacheLevelName(String constantName) throws IllegalArgumentExcepti
Assert.hasText(constantName, "'constantName' must not be null or blank");
Integer cacheLevel = constants.get(constantName);
Assert.notNull(cacheLevel, "Only cache constants allowed");
setCacheLevel(cacheLevel);
this.cacheLevel = cacheLevel;
}

/**
Expand All @@ -304,6 +304,7 @@ public void setCacheLevelName(String constantName) throws IllegalArgumentExcepti
* @see #setTransactionManager
*/
public void setCacheLevel(int cacheLevel) {
Assert.isTrue(constants.containsValue(cacheLevel), "Only values of cache constants allowed");
this.cacheLevel = cacheLevel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ void setCacheLevelNameToAllSupportedValues() {
assertThat(uniqueValues).hasSize(5);
}

@Test
void setCacheLevel() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();

assertThatIllegalArgumentException().isThrownBy(() -> container.setCacheLevel(999));

container.setCacheLevel(DefaultMessageListenerContainer.CACHE_NONE);
assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_NONE);

container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONNECTION);
assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_CONNECTION);

container.setCacheLevel(DefaultMessageListenerContainer.CACHE_SESSION);
assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_SESSION);

container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_CONSUMER);

container.setCacheLevel(DefaultMessageListenerContainer.CACHE_AUTO);
assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_AUTO);
}


private static Stream<String> streamCacheConstants() {
return Arrays.stream(DefaultMessageListenerContainer.class.getFields())
Expand Down

0 comments on commit b45bfca

Please sign in to comment.