Improve property target name

Previously, non camel case properties were wrongly resolved, i.e.
getFOO() leading to a 'f-o-o'. While unusual, underscores can also be
added to a property name. In that case, the hyphen should not be added
as the binder consider this to be a single "word". Typically setFoo_Bar
on the "something" prefix is mapped using "something.foo_bar".

All these cases are now handled properly, generating the target name that
the binder expects.

Fixes gh-2118
This commit is contained in:
Stephane Nicoll
2014-12-11 14:38:33 +01:00
parent e96f75fdc1
commit 8f6f25f88e
2 changed files with 89 additions and 7 deletions

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.configurationprocessor.metadata;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests for {@link ConfigurationMetadata}.
*
* @author Stephane Nicoll
*/
public class ConfigurationMetadataTests {
@Test
public void toDashedCaseCamelCase() {
assertThat(ConfigurationMetadata.toDashedCase("simpleCamelCase"), is("simple-camel-case"));
}
@Test
public void toDashedCaseWordsUnderScore() {
assertThat(ConfigurationMetadata.toDashedCase("Word_With_underscore"), is("word_with_underscore"));
}
@Test
public void toDashedCaseWordsSeveralUnderScores() {
assertThat(ConfigurationMetadata.toDashedCase("Word___With__underscore"), is("word___with__underscore"));
}
@Test
public void toDashedCaseLowerCaseUnderscore() {
assertThat(ConfigurationMetadata.toDashedCase("lower_underscore"), is("lower_underscore"));
}
@Test
public void toDashedCaseUpperUnderscore() {
assertThat(ConfigurationMetadata.toDashedCase("UPPER_UNDERSCORE"), is("upper_underscore"));
}
@Test
public void toDashedCaseMultipleUnderscores() {
assertThat(ConfigurationMetadata.toDashedCase("super___crazy"), is("super___crazy"));
}
@Test
public void toDashedCaseUppercase() {
assertThat(ConfigurationMetadata.toDashedCase("UPPERCASE"), is("uppercase"));
}
@Test
public void toDashedCaseLowercase() {
assertThat(ConfigurationMetadata.toDashedCase("lowercase"), is("lowercase"));
}
}