Skip to content

Commit

Permalink
Ensure that unit tests can be run when WebEnvironment.NONE is used (#109
Browse files Browse the repository at this point in the history
)

Fixes #108
  • Loading branch information
geoand authored Jul 3, 2019
1 parent 1267f75 commit 146a1ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public SkipPattern skipPatternForActuatorEndpointsDifferentPort(
@Configuration
protected static class DefaultSkipPatternConfig {

@Autowired(required = false)
WebTracingProperties webTracingProperties;

private static String combinedPatterns(String skipPattern) {
String pattern = skipPattern;
if (!StringUtils.hasText(skipPattern)) {
Expand All @@ -152,9 +155,12 @@ private static String combinedPatterns(String skipPattern) {
}

@Bean
SkipPattern defaultSkipPatternBean(WebTracingProperties webTracingProperties) {
SkipPattern defaultSkipPatternBean() {
if (webTracingProperties == null) {
return Optional::empty;
}
return () -> Optional.of(Pattern.compile(combinedPatterns(webTracingProperties.getSkipPattern())));
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public class SkipPatternConfigTest {
public void testShouldPickSkipPatternFromWebProperties() {
WebTracingProperties webTracingProperties = new WebTracingProperties();
webTracingProperties.setSkipPattern("foo.*|bar.*");
Pattern pattern = new SkipPatternAutoConfiguration.DefaultSkipPatternConfig()
.defaultSkipPatternBean(webTracingProperties).pattern().get();
SkipPatternAutoConfiguration.DefaultSkipPatternConfig defaultSkipPatternConfig =
new SkipPatternAutoConfiguration.DefaultSkipPatternConfig();
defaultSkipPatternConfig.webTracingProperties = webTracingProperties;
Pattern pattern = defaultSkipPatternConfig
.defaultSkipPatternBean().pattern().get();

then(pattern.pattern()).isEqualTo("foo.*|bar.*");
}
Expand Down Expand Up @@ -195,4 +198,4 @@ public Collection<WebOperation> getOperations() {
}
};
}
}
}

0 comments on commit 146a1ff

Please sign in to comment.