View Javadoc

1   /*
2    * Copyright 2010-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.testdoc.core.doc.names;
17  
18  import java.util.Locale;
19  
20  import org.apache.commons.lang.StringUtils;
21  
22  
23  /**
24   * Calculates valid names for test names written in English.
25   *
26   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
27   * @version $Revision:591 $
28   */
29  public class EnglishTestNameUtils implements TestNameUtils
30  {
31    // ********************************* Fields *********************************
32  
33    // --- constants ------------------------------------------------------------
34  
35    // --- members --------------------------------------------------------------
36  
37    // ****************************** Initializer *******************************
38  
39    // ****************************** Constructors ******************************
40  
41    /**
42     * Default constructor.
43     */
44    public EnglishTestNameUtils()
45    {
46    }
47  
48    // ****************************** Inner Classes *****************************
49  
50    // ********************************* Methods ********************************
51  
52    // --- init -----------------------------------------------------------------
53  
54    // --- get&set --------------------------------------------------------------
55  
56    // --- business -------------------------------------------------------------
57  
58    /**
59     * {@inheritDoc}
60     *
61     * @see de.smartics.testdoc.core.doc.names.TestNameUtils#calculateTestNameSentence(java.lang.String)
62     */
63    @Override
64    public String calculateTestNameSentence(final String testName) throws IllegalArgumentException
65    {
66      if (StringUtils.isBlank(testName))
67      {
68        throw new IllegalArgumentException("The name of the test must not be blank.");
69      }
70  
71      final String[] words = StringUtils.splitByCharacterTypeCamelCase(testName);
72  
73      final StringBuilder buffer = new StringBuilder(64);
74      for (final String word : words)
75      {
76        buffer.append(word.toLowerCase(Locale.ENGLISH)).append(' ');
77      }
78  
79      buffer.setCharAt(buffer.length() - 1, '.');
80      buffer.setCharAt(0, Character.toUpperCase(buffer.charAt(0)));
81  
82      final String sentence = buffer.toString();
83      return sentence;
84    }
85  
86    // --- object basics --------------------------------------------------------
87  
88  }