View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2015 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  package com.puppycrawl.tools.checkstyle.checks;
20  
21  import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
22  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
23  import com.puppycrawl.tools.checkstyle.api.Configuration;
24  import java.io.File;
25  import org.junit.Test;
26  
27  import static com.puppycrawl.tools.checkstyle.checks.TranslationCheck.MSG_KEY;
28  
29  public class TranslationCheckTest
30      extends BaseCheckTestSupport
31  {
32      @Override
33      protected DefaultConfiguration createCheckerConfig(
34          Configuration checkConfig)
35      {
36          final DefaultConfiguration dc = new DefaultConfiguration("root");
37          dc.addChild(checkConfig);
38          return dc;
39      }
40  
41      @Test
42      public void testTranslation() throws Exception
43      {
44          final Configuration checkConfig = createCheckConfig(TranslationCheck.class);
45          final String[] expected = {
46              "0: " + getCheckMessage(MSG_KEY, "only.english"),
47          };
48          final File[] propertyFiles = new File[] {
49              new File(getPath("messages_test_de.properties")),
50              new File(getPath("messages_test.properties")),
51          };
52          verify(
53              createChecker(checkConfig),
54              propertyFiles,
55              getPath("messages_test_de.properties"),
56              expected);
57      }
58  
59      // TODO: test with the same resourcebundle name in different packages
60      // x/messages.properties
61      //     key1=x
62      // y/messages.properties
63      //     key2=y
64      // should not result in error message about key1 missing in the y bundle
65  
66      @Test
67      public void testBaseNameSeparator() throws Exception
68      {
69          final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class);
70          checkConfig.addAttribute("basenameSeparator", "-");
71          final String[] expected = {
72              "0: " + getCheckMessage(MSG_KEY, "only.english"),
73          };
74          final File[] propertyFiles = new File[] {
75              new File(getPath("app-dev.properties")),
76              new File(getPath("app-stage.properties")),
77          };
78          verify(
79              createChecker(checkConfig),
80              propertyFiles,
81              getPath("app-dev.properties"),
82              expected);
83      }
84  
85  }