From 042cff66d9d174b0bb96bceb0ad700c77bbcd355 Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Thu, 18 Apr 2013 14:33:00 -0300 Subject: [PATCH] Refatoração e adição de teste para situação na qual o atributo de configuração do tipo calsse é nulo. --- impl/core/src/test/java/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java | 2 +- impl/core/src/test/java/configuration/field/clazz/AbstractEmptyClassFieldConfig.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/clazz/AbstractNullClassFieldConfig.java | 52 ---------------------------------------------------- impl/core/src/test/java/configuration/field/clazz/ConfigurationClassFieldTest.java | 20 +++++++++++++------- impl/core/src/test/java/configuration/field/clazz/PropertiesEmptyClassFieldConfig.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/clazz/PropertiesNullClassFieldConfig.java | 12 ++++++++---- impl/core/src/test/resources/configuration/field/class/demoiselle.properties | 41 ----------------------------------------- impl/core/src/test/resources/configuration/field/class/demoiselle.xml | 43 ------------------------------------------- impl/core/src/test/resources/configuration/field/clazz/demoiselle.properties | 41 +++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/clazz/demoiselle.xml | 43 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 203 insertions(+), 148 deletions(-) create mode 100644 impl/core/src/test/java/configuration/field/clazz/AbstractEmptyClassFieldConfig.java delete mode 100644 impl/core/src/test/java/configuration/field/clazz/AbstractNullClassFieldConfig.java create mode 100644 impl/core/src/test/java/configuration/field/clazz/PropertiesEmptyClassFieldConfig.java delete mode 100644 impl/core/src/test/resources/configuration/field/class/demoiselle.properties delete mode 100644 impl/core/src/test/resources/configuration/field/class/demoiselle.xml create mode 100644 impl/core/src/test/resources/configuration/field/clazz/demoiselle.properties create mode 100644 impl/core/src/test/resources/configuration/field/clazz/demoiselle.xml diff --git a/impl/core/src/test/java/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java b/impl/core/src/test/java/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java index f45ae69..14b3e6a 100644 --- a/impl/core/src/test/java/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java +++ b/impl/core/src/test/java/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java @@ -41,7 +41,7 @@ public abstract class AbstractClassNotFoundFieldConfig { private Class nonExistentTypedClass; private Class nonExistentUntypedClass; - + public Class getNonExistentTypedClass() { return nonExistentTypedClass; } diff --git a/impl/core/src/test/java/configuration/field/clazz/AbstractEmptyClassFieldConfig.java b/impl/core/src/test/java/configuration/field/clazz/AbstractEmptyClassFieldConfig.java new file mode 100644 index 0000000..50c2960 --- /dev/null +++ b/impl/core/src/test/java/configuration/field/clazz/AbstractEmptyClassFieldConfig.java @@ -0,0 +1,52 @@ +/* + * 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 configuration.field.clazz; + +public abstract class AbstractEmptyClassFieldConfig { + + private Class emptyTypedClass; + + private Class emptyUntypedClass; + + public Class getEmptyTypedClass() { + return emptyTypedClass; + } + + public Class getEmptyUntypedClass() { + return emptyUntypedClass; + } +} diff --git a/impl/core/src/test/java/configuration/field/clazz/AbstractNullClassFieldConfig.java b/impl/core/src/test/java/configuration/field/clazz/AbstractNullClassFieldConfig.java deleted file mode 100644 index f2e2bfd..0000000 --- a/impl/core/src/test/java/configuration/field/clazz/AbstractNullClassFieldConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 configuration.field.clazz; - -public abstract class AbstractNullClassFieldConfig { - - private Class nullTypedClass; - - private Class nullUntypedClass; - - public Class getNullTypedClass() { - return nullTypedClass; - } - - public Class getNullUntypedClass() { - return nullUntypedClass; - } -} diff --git a/impl/core/src/test/java/configuration/field/clazz/ConfigurationClassFieldTest.java b/impl/core/src/test/java/configuration/field/clazz/ConfigurationClassFieldTest.java index c81e40d..9edf239 100644 --- a/impl/core/src/test/java/configuration/field/clazz/ConfigurationClassFieldTest.java +++ b/impl/core/src/test/java/configuration/field/clazz/ConfigurationClassFieldTest.java @@ -37,6 +37,7 @@ package configuration.field.clazz; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import javax.inject.Inject; @@ -62,7 +63,10 @@ public class ConfigurationClassFieldTest { private PropertiesClassNotFoundFieldConfig propertiesNotFoundConfig; @Inject - private PropertiesNullClassFieldConfig propertiesNullFieldConfig; + private PropertiesEmptyClassFieldConfig propertiesEmptyFieldConfig; + + @Inject + private PropertiesNullClassFieldConfig propertiesNullFieldClassConfig; @Deployment public static JavaArchive createDeployment() { @@ -87,7 +91,6 @@ public class ConfigurationClassFieldTest { propertiesNotFoundConfig.getNonExistentTypedClass(); fail(); } catch (ConfigurationException cause) { - cause.printStackTrace(); assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } @@ -103,24 +106,27 @@ public class ConfigurationClassFieldTest { } @Test - public void loadNullTypedClass() { + public void loadTypedClassFromEmptyKey() { try { - propertiesNullFieldConfig.getNullTypedClass(); + propertiesEmptyFieldConfig.getEmptyTypedClass(); fail(); } catch (ConfigurationException cause) { - cause.printStackTrace(); assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } @Test - public void loadNullUntypedClass() { + public void loadUntypedClassFromEmptyKey() { try { - propertiesNullFieldConfig.getNullUntypedClass(); + propertiesEmptyFieldConfig.getEmptyUntypedClass(); fail(); } catch (ConfigurationException cause) { assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } + @Test + public void loadNullClass() { + assertNull(propertiesNullFieldClassConfig.getNullClass()); + } } diff --git a/impl/core/src/test/java/configuration/field/clazz/PropertiesEmptyClassFieldConfig.java b/impl/core/src/test/java/configuration/field/clazz/PropertiesEmptyClassFieldConfig.java new file mode 100644 index 0000000..babe3b4 --- /dev/null +++ b/impl/core/src/test/java/configuration/field/clazz/PropertiesEmptyClassFieldConfig.java @@ -0,0 +1,45 @@ +/* + * 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 configuration.field.clazz; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(type = PROPERTIES) +public class PropertiesEmptyClassFieldConfig extends AbstractEmptyClassFieldConfig { + +} diff --git a/impl/core/src/test/java/configuration/field/clazz/PropertiesNullClassFieldConfig.java b/impl/core/src/test/java/configuration/field/clazz/PropertiesNullClassFieldConfig.java index 8b8e429..cc51f30 100644 --- a/impl/core/src/test/java/configuration/field/clazz/PropertiesNullClassFieldConfig.java +++ b/impl/core/src/test/java/configuration/field/clazz/PropertiesNullClassFieldConfig.java @@ -36,10 +36,14 @@ */ package configuration.field.clazz; -import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; import br.gov.frameworkdemoiselle.configuration.Configuration; -@Configuration(type = PROPERTIES) -public class PropertiesNullClassFieldConfig extends AbstractNullClassFieldConfig { - +@Configuration +public class PropertiesNullClassFieldConfig { + + private Class nullClass; + + public Class getNullClass() { + return nullClass; + } } diff --git a/impl/core/src/test/resources/configuration/field/class/demoiselle.properties b/impl/core/src/test/resources/configuration/field/class/demoiselle.properties deleted file mode 100644 index 1be98ac..0000000 --- a/impl/core/src/test/resources/configuration/field/class/demoiselle.properties +++ /dev/null @@ -1,41 +0,0 @@ -# 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. - -existentTypedClass=configuration.field.clazz.MyClass -existentUntypedClass=configuration.field.clazz.MyClass -nonExistentTypedClass=com.fake.NonExistentClass -nonExistentUntypedClass=com.fake.NonExistentClass -nullTypedClass= -nullUntypedClass= diff --git a/impl/core/src/test/resources/configuration/field/class/demoiselle.xml b/impl/core/src/test/resources/configuration/field/class/demoiselle.xml deleted file mode 100644 index 62ee827..0000000 --- a/impl/core/src/test/resources/configuration/field/class/demoiselle.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - 1 - 2 - demoiselle framework - demoiselle,framework - diff --git a/impl/core/src/test/resources/configuration/field/clazz/demoiselle.properties b/impl/core/src/test/resources/configuration/field/clazz/demoiselle.properties new file mode 100644 index 0000000..c0f4ed5 --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/clazz/demoiselle.properties @@ -0,0 +1,41 @@ +# 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. + +existentTypedClass=configuration.field.clazz.MyClass +existentUntypedClass=configuration.field.clazz.MyClass +nonExistentTypedClass=com.fake.NonExistentClass +nonExistentUntypedClass=com.fake.NonExistentClass +emptyTypedClass= +emptyUntypedClass= diff --git a/impl/core/src/test/resources/configuration/field/clazz/demoiselle.xml b/impl/core/src/test/resources/configuration/field/clazz/demoiselle.xml new file mode 100644 index 0000000..62ee827 --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/clazz/demoiselle.xml @@ -0,0 +1,43 @@ + + + + 1 + 2 + demoiselle framework + demoiselle,framework + -- libgit2 0.21.2