From 79d8947743bd089145c2fc430728aba4a62db60f Mon Sep 17 00:00:00 2001 From: Ednara Oliveira Date: Thu, 2 May 2013 15:58:46 -0300 Subject: [PATCH] Testes com ResourceBundle --- impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java | 7 +++++++ impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/resourcebundle/parameter/messages.properties | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 0 deletions(-) create mode 100644 impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java create mode 100644 impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java create mode 100644 impl/core/src/test/resources/resourcebundle/parameter/messages.properties diff --git a/impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java b/impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java index 753f897..7b227c2 100644 --- a/impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java +++ b/impl/core/src/test/java/resourcebundle/file/defaultfile/ResourceBundleDefaultTest.java @@ -77,5 +77,12 @@ public class ResourceBundleDefaultTest { bundleDefault = Beans.getReference(ResourceBundleDefault.class); Assert.assertEquals("message in English", bundleDefault.getMessage()); } + + @Test + public void loadResourceWithLocaleNotExist() { + Locale.setDefault(Locale.ITALY); + bundleDefault = Beans.getReference(ResourceBundleDefault.class); + Assert.assertEquals("mensagem em Portugues", bundleDefault.getMessage()); + } } diff --git a/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java b/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java new file mode 100644 index 0000000..339f0f4 --- /dev/null +++ b/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameter.java @@ -0,0 +1,51 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package resourcebundle.parameter; + +import javax.inject.Inject; + +import br.gov.frameworkdemoiselle.util.ResourceBundle; + +public class ResourceBundleWithParameter { + + @Inject + private ResourceBundle bundle; + + public ResourceBundle getBundle() { + return bundle; + } +} diff --git a/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java b/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java new file mode 100644 index 0000000..c830579 --- /dev/null +++ b/impl/core/src/test/java/resourcebundle/parameter/ResourceBundleWithParameterTest.java @@ -0,0 +1,115 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package resourcebundle.parameter; + +import junit.framework.Assert; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import test.Tests; +import br.gov.frameworkdemoiselle.util.Beans; + +@RunWith(Arquillian.class) +public class ResourceBundleWithParameterTest { + + private ResourceBundleWithParameter bundleCustom; + + private static final String PATH = "src/test/resources/resourcebundle/parameter/"; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = Tests.createDeployment(ResourceBundleWithParameterTest.class); + deployment.addAsResource(Tests.createFileAsset(PATH + "messages.properties"), "messages.properties"); + + return deployment; + } + + @Test + public void loadKeyWithOneParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem número 1"; + String value = bundleCustom.getBundle().getString("messageOneParameter", "1"); + Assert.assertEquals(expected, value); + } + + @Test + public void loadKeyWithTwoParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem número 1 com 2 parâmetros"; + String value = bundleCustom.getBundle().getString("messageTwoParameter", "1", "2"); + Assert.assertEquals(expected, value); + } + + @Test + public void loadKeyWithoutParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem"; + String value = bundleCustom.getBundle().getString("messageWithoutParameter", "1", "2", "3"); + Assert.assertEquals(expected, value); + } + + @Test + public void loadKeyWithStringParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem número 1"; + String value = bundleCustom.getBundle().getString("messageParameterString", "1"); + Assert.assertNotSame(expected, value); + + expected = "Mensagem número {numero}"; + Assert.assertEquals(expected, value); + } + + @Test + public void loadKeyWithMoreParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem número 1"; + String value = bundleCustom.getBundle().getString("messageOneParameter", "1", "2", "3"); + Assert.assertEquals(expected, value); + } + + @Test + public void loadKeyWithLessParameter() { + bundleCustom = Beans.getReference(ResourceBundleWithParameter.class); + String expected = "Mensagem número 1 com {1} parâmetros"; + String value = bundleCustom.getBundle().getString("messageTwoParameter", "1"); + Assert.assertEquals(expected, value); + } +} diff --git a/impl/core/src/test/resources/resourcebundle/parameter/messages.properties b/impl/core/src/test/resources/resourcebundle/parameter/messages.properties new file mode 100644 index 0000000..6f2c817 --- /dev/null +++ b/impl/core/src/test/resources/resourcebundle/parameter/messages.properties @@ -0,0 +1,38 @@ +# Demoiselle Framework +# Copyright (C) 2010 SERPRO +# ---------------------------------------------------------------------------- +# This file is part of Demoiselle Framework. +# +# Demoiselle Framework is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License version 3 +# along with this program; if not, see +# or write to the Free Software Foundation, Inc., 51 Franklin Street, +# Fifth Floor, Boston, MA 02110-1301, USA. +# ---------------------------------------------------------------------------- +# Este arquivo é parte do Framework Demoiselle. +# +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +# do Software Livre (FSF). +# +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +# para maiores detalhes. +# +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +# "LICENCA.txt", junto com esse programa. Se não, acesse +# ou escreva para a Fundação do Software Livre (FSF) Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +messageWithoutParameter=Mensagem +messageOneParameter=Mensagem n\u00FAmero {0} +messageTwoParameter=Mensagem n\u00FAmero {0} com {1} par\u00E2metros +messageParameterString=Mensagem n\u00FAmero {numero} \ No newline at end of file -- libgit2 0.21.2