Commit 79d8947743bd089145c2fc430728aba4a62db60f
1 parent
33b67edc
Exists in
master
Testes com ResourceBundle
Showing
4 changed files
with
211 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java
... | ... | @@ -77,5 +77,12 @@ public class ResourceBundleDefaultTest { |
77 | 77 | bundleDefault = Beans.getReference(ResourceBundleDefault.class); |
78 | 78 | Assert.assertEquals("message in English", bundleDefault.getMessage()); |
79 | 79 | } |
80 | + | |
81 | + @Test | |
82 | + public void loadResourceWithLocaleNotExist() { | |
83 | + Locale.setDefault(Locale.ITALY); | |
84 | + bundleDefault = Beans.getReference(ResourceBundleDefault.class); | |
85 | + Assert.assertEquals("mensagem em Portugues", bundleDefault.getMessage()); | |
86 | + } | |
80 | 87 | |
81 | 88 | } | ... | ... |
impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java
0 → 100644
... | ... | @@ -0,0 +1,51 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package resourcebundle.parameter; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
42 | + | |
43 | +public class ResourceBundleWithParameter { | |
44 | + | |
45 | + @Inject | |
46 | + private ResourceBundle bundle; | |
47 | + | |
48 | + public ResourceBundle getBundle() { | |
49 | + return bundle; | |
50 | + } | |
51 | +} | ... | ... |
impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java
0 → 100644
... | ... | @@ -0,0 +1,115 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package resourcebundle.parameter; | |
38 | + | |
39 | +import junit.framework.Assert; | |
40 | + | |
41 | +import org.jboss.arquillian.container.test.api.Deployment; | |
42 | +import org.jboss.arquillian.junit.Arquillian; | |
43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
44 | +import org.junit.Test; | |
45 | +import org.junit.runner.RunWith; | |
46 | + | |
47 | +import test.Tests; | |
48 | +import br.gov.frameworkdemoiselle.util.Beans; | |
49 | + | |
50 | +@RunWith(Arquillian.class) | |
51 | +public class ResourceBundleWithParameterTest { | |
52 | + | |
53 | + private ResourceBundleWithParameter bundleCustom; | |
54 | + | |
55 | + private static final String PATH = "src/test/resources/resourcebundle/parameter/"; | |
56 | + | |
57 | + @Deployment | |
58 | + public static JavaArchive createDeployment() { | |
59 | + JavaArchive deployment = Tests.createDeployment(ResourceBundleWithParameterTest.class); | |
60 | + deployment.addAsResource(Tests.createFileAsset(PATH + "messages.properties"), "messages.properties"); | |
61 | + | |
62 | + return deployment; | |
63 | + } | |
64 | + | |
65 | + @Test | |
66 | + public void loadKeyWithOneParameter() { | |
67 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
68 | + String expected = "Mensagem número 1"; | |
69 | + String value = bundleCustom.getBundle().getString("messageOneParameter", "1"); | |
70 | + Assert.assertEquals(expected, value); | |
71 | + } | |
72 | + | |
73 | + @Test | |
74 | + public void loadKeyWithTwoParameter() { | |
75 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
76 | + String expected = "Mensagem número 1 com 2 parâmetros"; | |
77 | + String value = bundleCustom.getBundle().getString("messageTwoParameter", "1", "2"); | |
78 | + Assert.assertEquals(expected, value); | |
79 | + } | |
80 | + | |
81 | + @Test | |
82 | + public void loadKeyWithoutParameter() { | |
83 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
84 | + String expected = "Mensagem"; | |
85 | + String value = bundleCustom.getBundle().getString("messageWithoutParameter", "1", "2", "3"); | |
86 | + Assert.assertEquals(expected, value); | |
87 | + } | |
88 | + | |
89 | + @Test | |
90 | + public void loadKeyWithStringParameter() { | |
91 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
92 | + String expected = "Mensagem número 1"; | |
93 | + String value = bundleCustom.getBundle().getString("messageParameterString", "1"); | |
94 | + Assert.assertNotSame(expected, value); | |
95 | + | |
96 | + expected = "Mensagem número {numero}"; | |
97 | + Assert.assertEquals(expected, value); | |
98 | + } | |
99 | + | |
100 | + @Test | |
101 | + public void loadKeyWithMoreParameter() { | |
102 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
103 | + String expected = "Mensagem número 1"; | |
104 | + String value = bundleCustom.getBundle().getString("messageOneParameter", "1", "2", "3"); | |
105 | + Assert.assertEquals(expected, value); | |
106 | + } | |
107 | + | |
108 | + @Test | |
109 | + public void loadKeyWithLessParameter() { | |
110 | + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); | |
111 | + String expected = "Mensagem número 1 com {1} parâmetros"; | |
112 | + String value = bundleCustom.getBundle().getString("messageTwoParameter", "1"); | |
113 | + Assert.assertEquals(expected, value); | |
114 | + } | |
115 | +} | ... | ... |
impl/core/src/test/resources/resourcebundle/parameter/messages.properties
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +# Demoiselle Framework | |
2 | +# Copyright (C) 2010 SERPRO | |
3 | +# ---------------------------------------------------------------------------- | |
4 | +# This file is part of Demoiselle Framework. | |
5 | +# | |
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
8 | +# as published by the Free Software Foundation. | |
9 | +# | |
10 | +# This program 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 | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | +# ---------------------------------------------------------------------------- | |
20 | +# Este arquivo é parte do Framework Demoiselle. | |
21 | +# | |
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
24 | +# do Software Livre (FSF). | |
25 | +# | |
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
29 | +# para maiores detalhes. | |
30 | +# | |
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
35 | +messageWithoutParameter=Mensagem | |
36 | +messageOneParameter=Mensagem n\u00FAmero {0} | |
37 | +messageTwoParameter=Mensagem n\u00FAmero {0} com {1} par\u00E2metros | |
38 | +messageParameterString=Mensagem n\u00FAmero {numero} | |
0 | 39 | \ No newline at end of file | ... | ... |