Skip to content

Commit

Permalink
Add test for ResolveClassName.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriedenhagen-ui committed Oct 5, 2012
1 parent d8dbe10 commit 3ec36d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
Expand Up @@ -15,14 +15,17 @@
*/
package org.codeartisans.mojo.artifactinfo;

import java.util.Locale;
import org.codehaus.plexus.util.StringUtils;

/**
* @author Paul Merlin
* @author Mirko Friedenhagen
*/
class ResolveClassName extends Resolver {

final String givenClassName;

final String artifactId;

public ResolveClassName(final String givenClassName, final String artifactId) {
Expand All @@ -36,18 +39,17 @@ String resolve() {
validatesName(givenClassName);
return givenClassName;
}
StringBuilder sb = new StringBuilder();
String nonFiltered = artifactId;
nonFiltered = specialTrim(nonFiltered);
final StringBuilder sb = new StringBuilder();
final String nonFiltered = specialTrim(artifactId);
String previous = new String(new char[]{nonFiltered.charAt(0)});
sb.append(previous.toUpperCase());
sb.append(previous.toUpperCase(Locale.ENGLISH));
for (int idx = 1; idx < nonFiltered.length(); idx++) {
char current = nonFiltered.charAt(idx);
if (validCharacters.indexOf((int) current) != -1) {
if (validCharacters.contains(previous)) {
sb.append(current);
} else {
sb.append(new String(new char[]{current}).toUpperCase());
sb.append(new String(new char[]{current}).toUpperCase(Locale.ENGLISH));
}
}
previous = new String(new char[]{current});
Expand Down
@@ -0,0 +1,44 @@
/*
* Copyright 2012 Mirko Friedenhagen.
*
* 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.codeartisans.mojo.artifactinfo;

import junit.framework.TestCase;

/**
* @author Mirko Friedenhagen
*/
public class ResolveClassNameTest extends TestCase {

/**
* Test of resolve method, of class ResolveClassName.
*/
public void testResolveClassNameGiven() {
ResolveClassName instance = new ResolveClassName("FooBar", "DOES_NOT_MATTER");
String expResult = "FooBar";
String result = instance.resolve();
assertEquals(expResult, result);
}

/**
* Test of resolve method, of class ResolveClassName.
*/
public void testResolveNoClassNameGiven() {
ResolveClassName instance = new ResolveClassName(null, "artifact-info");
String expResult = "ArtifactInfo_ArtifactInfo";
String result = instance.resolve();
assertEquals(expResult, result);
}
}

0 comments on commit 3ec36d1

Please sign in to comment.