Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Jan 21, 2016
1 parent acfae2e commit cf93f84
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ public void testDetailsAreIncludedInAuditEvent() throws Exception {
assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(),
hasEntry("details", details));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,27 @@ public FlywayJpaDependencyConfiguration() {
private static class StringOrNumberToMigrationVersionConverter
implements GenericConverter {

private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS = createConvertiblePairs();
private static final Set<ConvertiblePair> CONVERTIBLE_TYPES;

static {
Set<ConvertiblePair> types = new HashSet<ConvertiblePair>(2);
types.add(new ConvertiblePair(String.class, MigrationVersion.class));
types.add(new ConvertiblePair(Number.class, MigrationVersion.class));
CONVERTIBLE_TYPES = Collections.unmodifiableSet(types);
}

@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return CONVERTIBLE_PAIRS;
return CONVERTIBLE_TYPES;
}

@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
String value = ObjectUtils.nullSafeToString(source);
return MigrationVersion.fromVersion(value);
}

private static Set<ConvertiblePair> createConvertiblePairs() {
Set<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>(2);
convertiblePairs.add(new ConvertiblePair(String.class, MigrationVersion.class));
convertiblePairs.add(new ConvertiblePair(Number.class, MigrationVersion.class));
return Collections.unmodifiableSet(convertiblePairs);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/**
* {@link Conditional} that checks whether or not the Spring resource handling chain is
* enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or
* if {@code webjars-locator} is on the classpath.
* enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or if
* {@code webjars-locator} is on the classpath.
*
* @author Stephane Nicoll
* @since 1.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
class OnEnabledResourceChainCondition extends SpringBootCondition {

public static final String WEBJAR_ASSERT_LOCATOR = "org.webjars.WebJarAssetLocator";
private static final String WEBJAR_ASSERT_LOCATOR = "org.webjars.WebJarAssetLocator";

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
Expand All @@ -46,8 +46,8 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
Boolean match = properties.getChain().getEnabled();
if (match == null) {
boolean webJarsLocatorPresent = ClassUtils.isPresent(
WEBJAR_ASSERT_LOCATOR, getClass().getClassLoader());
boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
getClass().getClassLoader());
return new ConditionOutcome(webJarsLocatorPresent,
"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
+ (webJarsLocatorPresent ? "present" : "absent"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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 @@ -175,11 +175,10 @@ public static class Chain {
/**
* Return whether the resource chain is enabled. Return {@code null} if no
* specific settings are present.
* @return whether the resource chain is enabled or {@code null} if no
* specified settings are present.
* @return whether the resource chain is enabled or {@code null} if no specified
* settings are present.
*/
public Boolean getEnabled() {
// Check if at least one of the available strategy has been enabled
Boolean strategyEnabled = getStrategy().getFixed().isEnabled()
|| getStrategy().getContent().isEnabled();
return (strategyEnabled ? Boolean.TRUE : this.enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,24 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
}
Integer cachePeriod = this.resourceProperties.getCachePeriod();
if (!registry.hasMappingForPattern("/webjars/**")) {
customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
customizeResourceHandlerRegistration(
registry.addResourceHandler("/webjars/**")
.addResourceLocations(
"classpath:/META-INF/resources/webjars/")
.setCachePeriod(cachePeriod));
}
String staticPathPattern = this.mvcProperties.getStaticPathPattern();
if (!registry.hasMappingForPattern(staticPathPattern)) {
customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern)
.addResourceLocations(
this.resourceProperties.getStaticLocations())
customizeResourceHandlerRegistration(
registry.addResourceHandler(staticPathPattern)
.addResourceLocations(
this.resourceProperties.getStaticLocations())
.setCachePeriod(cachePeriod));
}
}

private void customizeResourceHandlerRegistration(ResourceHandlerRegistration registration) {
private void customizeResourceHandlerRegistration(
ResourceHandlerRegistration registration) {
if (this.resourceHandlerRegistrationCustomizer != null) {
this.resourceHandlerRegistrationCustomizer.customize(registration);
}
Expand Down Expand Up @@ -411,6 +415,7 @@ private ResourceResolver getVersionResourceResolver(
}
return resolver;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ public void overrideBaselineVersionString() throws Exception {

@Test
public void overrideBaselineVersionNumber() throws Exception {
Map<String, Object> source = Collections.<String, Object>singletonMap("flyway.baseline-version", 1);
this.context.getEnvironment().getPropertySources().addLast(new MapPropertySource("flyway", source));
Map<String, Object> source = Collections
.<String, Object>singletonMap("flyway.baseline-version", 1);
this.context.getEnvironment().getPropertySources()
.addLast(new MapPropertySource("flyway", source));
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

/**
Expand All @@ -34,25 +34,25 @@ public class ResourcePropertiesTest {
@Test
public void resourceChainNoCustomization() {
System.out.println(this.properties.getChain().getEnabled());
assertThat(this.properties.getChain().getEnabled(), is(nullValue()));
assertThat(this.properties.getChain().getEnabled(), nullValue());
}

@Test
public void resourceChainStrategyEnabled() {
this.properties.getChain().getStrategy().getFixed().setEnabled(true);
assertThat(this.properties.getChain().getEnabled(), is(true));
assertThat(this.properties.getChain().getEnabled(), equalTo(true));
}

@Test
public void resourceChainEnabled() {
this.properties.getChain().setEnabled(true);
assertThat(this.properties.getChain().getEnabled(), is(true));
assertThat(this.properties.getChain().getEnabled(), equalTo(true));
}

@Test
public void resourceChainDisabled() {
this.properties.getChain().setEnabled(false);
assertThat(this.properties.getChain().getEnabled(), is(false));
assertThat(this.properties.getChain().getEnabled(), equalTo(false));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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 @@ -111,8 +111,8 @@ protected void loadConfiguration(String location, LogFile logFile) {
@Override
public void setLogLevel(String loggerName, LogLevel level) {
Assert.notNull(level, "Level must not be null");
Logger logger = Logger
.getLogger(StringUtils.hasText(loggerName) ? loggerName : "");
String name = (StringUtils.hasText(loggerName) ? loggerName : "");
Logger logger = Logger.getLogger(name);
logger.setLevel(LEVELS.get(level));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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 @@ -208,10 +208,9 @@ private LoggerConfig getRootLoggerConfig() {
return getLoggerContext().getConfiguration().getLoggerConfig("");
}

private LoggerConfig getLoggerConfig(String loggerName) {
loggerName = StringUtils.hasText(loggerName) ? loggerName
: LogManager.ROOT_LOGGER_NAME;
return getLoggerContext().getConfiguration().getLoggers().get(loggerName);
private LoggerConfig getLoggerConfig(String name) {
name = (StringUtils.hasText(name) ? name : LogManager.ROOT_LOGGER_NAME);
return getLoggerContext().getConfiguration().getLoggers().get(name);
}

private LoggerContext getLoggerContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(TestConfig.class)
@IntegrationTest({"foo=one", "bar=two"})
@IntegrationTest({ "foo=one", "bar=two" })
public class ConverterBindingTests {

@Value("${foo:}")
Expand Down Expand Up @@ -88,11 +88,13 @@ public GenericConverter genericConverter() {
return new GenericConverter() {
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(String.class, Bar.class));
return Collections
.singleton(new ConvertiblePair(String.class, Bar.class));
}

@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
return new Bar((String) source);
}
};
Expand All @@ -112,6 +114,7 @@ public static class Foo {
public Foo(String name) {
this.name = name;
}

}

public static class Bar {
Expand All @@ -121,6 +124,7 @@ public static class Bar {
public Bar(String name) {
this.name = name;
}

}

@ConfigurationProperties
Expand All @@ -145,6 +149,7 @@ public Bar getBar() {
public void setBar(Bar bar) {
this.bar = bar;
}

}

}

0 comments on commit cf93f84

Please sign in to comment.