Commit 179020f4ea848c8772e0f59f263efe14b531e51e

Authored by Emerson Oliveira
1 parent 72676211
Exists in master

Adição de testes com anotação @Name

impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/named/AbstractEmptyNamedFieldConfig.java 0 → 100644
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  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 br.gov.frameworkdemoiselle.configuration.field.named;
  38 +
  39 +import br.gov.frameworkdemoiselle.annotation.Name;
  40 +
  41 +public abstract class AbstractEmptyNamedFieldConfig {
  42 +
  43 + @Name("")
  44 + private int noNameAttribute;
  45 +
  46 + public int getNoNameAttribute() {
  47 + return noNameAttribute;
  48 + }
  49 +}
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/named/AbstractNamedFieldConfig.java
@@ -49,15 +49,15 @@ public abstract class AbstractNamedFieldConfig { @@ -49,15 +49,15 @@ public abstract class AbstractNamedFieldConfig {
49 @Name("attribute.without.file") 49 @Name("attribute.without.file")
50 private int namedWithoutFileAttribute; 50 private int namedWithoutFileAttribute;
51 51
52 - public int intUniqueNameAttribute() { 52 + public int getUniqueNameAttribute() {
53 return uniqueNameAttribute; 53 return uniqueNameAttribute;
54 } 54 }
55 55
56 - public int intNotPresentAttribute() { 56 + public int getNotPresentAttribute() {
57 return notPresentAttribute; 57 return notPresentAttribute;
58 } 58 }
59 59
60 - public int intNamedWithoutFileAttribute() { 60 + public int getNamedWithoutFileAttribute() {
61 return namedWithoutFileAttribute; 61 return namedWithoutFileAttribute;
62 } 62 }
63 } 63 }
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/named/ConfigurationNamedFieldTest.java
@@ -37,11 +37,14 @@ @@ -37,11 +37,14 @@
37 package br.gov.frameworkdemoiselle.configuration.field.named; 37 package br.gov.frameworkdemoiselle.configuration.field.named;
38 38
39 import static junit.framework.Assert.assertEquals; 39 import static junit.framework.Assert.assertEquals;
  40 +import static junit.framework.Assert.fail;
40 41
41 import java.io.File; 42 import java.io.File;
42 43
43 import javax.inject.Inject; 44 import javax.inject.Inject;
44 45
  46 +import junit.framework.Assert;
  47 +
45 import org.jboss.arquillian.container.test.api.Deployment; 48 import org.jboss.arquillian.container.test.api.Deployment;
46 import org.jboss.arquillian.junit.Arquillian; 49 import org.jboss.arquillian.junit.Arquillian;
47 import org.jboss.shrinkwrap.api.asset.FileAsset; 50 import org.jboss.shrinkwrap.api.asset.FileAsset;
@@ -50,6 +53,7 @@ import org.junit.Test; @@ -50,6 +53,7 @@ import org.junit.Test;
50 import org.junit.runner.RunWith; 53 import org.junit.runner.RunWith;
51 54
52 import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; 55 import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest;
  56 +import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
53 57
54 @RunWith(Arquillian.class) 58 @RunWith(Arquillian.class)
55 public class ConfigurationNamedFieldTest extends AbstractConfigurationTest { 59 public class ConfigurationNamedFieldTest extends AbstractConfigurationTest {
@@ -60,6 +64,12 @@ public class ConfigurationNamedFieldTest extends AbstractConfigurationTest { @@ -60,6 +64,12 @@ public class ConfigurationNamedFieldTest extends AbstractConfigurationTest {
60 @Inject 64 @Inject
61 private XMLNamed xmlNamed; 65 private XMLNamed xmlNamed;
62 66
  67 + @Inject
  68 + private PropertyEmptyNamed propertyEmptyNamed;
  69 +
  70 + @Inject
  71 + private XMLEmptyNamed xmlEmptyNamed;
  72 +
63 @Deployment 73 @Deployment
64 public static JavaArchive createDeployment() { 74 public static JavaArchive createDeployment() {
65 JavaArchive deployment = createConfigurationDeployment(); 75 JavaArchive deployment = createConfigurationDeployment();
@@ -76,19 +86,37 @@ public class ConfigurationNamedFieldTest extends AbstractConfigurationTest { @@ -76,19 +86,37 @@ public class ConfigurationNamedFieldTest extends AbstractConfigurationTest {
76 86
77 @Test 87 @Test
78 public void loadNamedConfigFromPropertyWithName() { 88 public void loadNamedConfigFromPropertyWithName() {
79 - assertEquals(1, propertyNamed.intUniqueNameAttribute());  
80 - assertEquals(1, xmlNamed.intUniqueNameAttribute()); 89 + assertEquals(1, propertyNamed.getUniqueNameAttribute());
  90 + assertEquals(1, xmlNamed.getUniqueNameAttribute());
81 } 91 }
82 92
83 @Test 93 @Test
84 public void loadNamedConfigFromNonexistentProperty() { 94 public void loadNamedConfigFromNonexistentProperty() {
85 - assertEquals(0, propertyNamed.intNotPresentAttribute());  
86 - assertEquals(0, xmlNamed.intNotPresentAttribute()); 95 + assertEquals(0, propertyNamed.getNotPresentAttribute());
  96 + assertEquals(0, xmlNamed.getNotPresentAttribute());
87 } 97 }
88 98
89 @Test 99 @Test
90 public void loadNamedConfigFromPropertyWithoutField() { 100 public void loadNamedConfigFromPropertyWithoutField() {
91 - assertEquals(0, propertyNamed.intNamedWithoutFileAttribute());  
92 - assertEquals(0, xmlNamed.intNamedWithoutFileAttribute()); 101 + assertEquals(0, propertyNamed.getNamedWithoutFileAttribute());
  102 + assertEquals(0, xmlNamed.getNamedWithoutFileAttribute());
  103 + }
  104 +
  105 + @Test
  106 + public void loadEmptyNameConfig() {
  107 + try {
  108 + xmlEmptyNamed.getNoNameAttribute();
  109 + fail();
  110 + } catch (ConfigurationException cause) {
  111 + assertEquals(IllegalArgumentException.class, cause.getCause().getClass());
  112 + }
  113 +
  114 + try {
  115 + propertyEmptyNamed.getNoNameAttribute();
  116 + fail();
  117 + } catch (ConfigurationException cause) {
  118 + assertEquals(IllegalArgumentException.class, cause.getCause().getClass());
  119 + }
  120 +
93 } 121 }
94 } 122 }
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/named/PropertyEmptyNamed.java 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +package br.gov.frameworkdemoiselle.configuration.field.named;
  2 +
  3 +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES;
  4 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  5 +
  6 +@Configuration(type = PROPERTIES)
  7 +public class PropertyEmptyNamed extends AbstractEmptyNamedFieldConfig {
  8 +}
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/named/XMLEmptyNamed.java 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +package br.gov.frameworkdemoiselle.configuration.field.named;
  2 +
  3 +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML;
  4 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  5 +
  6 +@Configuration(type = XML)
  7 +public class XMLEmptyNamed extends AbstractEmptyNamedFieldConfig {
  8 +}