Commit ebd26f7231dcc2404080cc6847a6c656007817d3

Authored by Emerson Oliveira
1 parent 767178c0
Exists in master

Refatoração e adição de testes para os atributos de configuração

dos tipos primitivo e wrapped
impl/core/src/test/java/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java
@@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
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 configuration.field.primitiveorwrapper;  
38 -  
39 -public abstract class AbstractPrimitiveOrWrapperEmptyFieldConfig {  
40 -  
41 - private int primitiveInteger;  
42 -  
43 - private int nullPrimitiveInteger;  
44 -  
45 - private int errorPrimitiveInteger;  
46 -  
47 - private Integer wrappedInteger;  
48 -  
49 - private Integer nullWrappedInteger;  
50 -  
51 - private Integer errorWrappedInteger;  
52 -  
53 - public Integer getWrappedInteger() {  
54 - return wrappedInteger;  
55 - }  
56 -  
57 - public int getPrimitiveInteger() {  
58 - return primitiveInteger;  
59 - }  
60 -  
61 - public int getNullPrimitiveInteger() {  
62 - return nullPrimitiveInteger;  
63 - }  
64 -  
65 - public Integer getNullWrappedInteger() {  
66 - return nullWrappedInteger;  
67 - }  
68 -  
69 - public int getErrorPrimitiveInteger() {  
70 - return errorPrimitiveInteger;  
71 - }  
72 -  
73 - public Integer getErrorWrappedInteger() {  
74 - return errorWrappedInteger;  
75 - }  
76 -}  
impl/core/src/test/java/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperErrorFieldConfig.java
@@ -38,27 +38,27 @@ package configuration.field.primitiveorwrapper; @@ -38,27 +38,27 @@ package configuration.field.primitiveorwrapper;
38 38
39 public abstract class AbstractPrimitiveOrWrapperErrorFieldConfig { 39 public abstract class AbstractPrimitiveOrWrapperErrorFieldConfig {
40 40
41 - private int emptyPrimitiveInteger; 41 + private int emptyPrimitiveField;
42 42
43 - private int errorPrimitiveInteger; 43 + private int conversionErrorPrimitiveField;
44 44
45 - private Integer emptyWrappedInteger; 45 + private Integer emptyWrappedField;
46 46
47 - private Integer errorWrappedInteger;  
48 -  
49 - public int getEmptyPrimitiveInteger() {  
50 - return emptyPrimitiveInteger; 47 + private Integer conversionErrorWrappedField;
  48 +
  49 + public int getEmptyPrimitiveField() {
  50 + return emptyPrimitiveField;
51 } 51 }
52 52
53 - public Integer getEmptyWrappedInteger() {  
54 - return emptyWrappedInteger; 53 + public Integer getEmptyWrappedField() {
  54 + return emptyWrappedField;
55 } 55 }
56 56
57 - public int getErrorPrimitiveInteger() {  
58 - return errorPrimitiveInteger; 57 + public int getConversionErrorPrimitiveField() {
  58 + return conversionErrorPrimitiveField;
59 } 59 }
60 60
61 - public Integer getErrorWrappedInteger() {  
62 - return errorWrappedInteger; 61 + public Integer getConversionErrorWrappedField() {
  62 + return conversionErrorWrappedField;
63 } 63 }
64 } 64 }
impl/core/src/test/java/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperFieldConfig.java
@@ -38,15 +38,15 @@ package configuration.field.primitiveorwrapper; @@ -38,15 +38,15 @@ package configuration.field.primitiveorwrapper;
38 38
39 public abstract class AbstractPrimitiveOrWrapperFieldConfig { 39 public abstract class AbstractPrimitiveOrWrapperFieldConfig {
40 40
41 - private int primitiveInteger; 41 + private int primitiveField;
42 42
43 - private Integer wrappedInteger; 43 + private Integer wrappedField;
44 44
45 - public Integer getWrappedInteger() {  
46 - return wrappedInteger; 45 + public Integer getWrappedField() {
  46 + return wrappedField;
47 } 47 }
48 48
49 - public int getPrimitiveInteger() {  
50 - return primitiveInteger; 49 + public int getPrimitiveField() {
  50 + return primitiveField;
51 } 51 }
52 } 52 }
impl/core/src/test/java/configuration/field/primitiveorwrapper/ConfigurationPrimitiveOrWrapperFieldTest.java
@@ -38,6 +38,7 @@ package configuration.field.primitiveorwrapper; @@ -38,6 +38,7 @@ package configuration.field.primitiveorwrapper;
38 38
39 import static junit.framework.Assert.assertEquals; 39 import static junit.framework.Assert.assertEquals;
40 import static junit.framework.Assert.fail; 40 import static junit.framework.Assert.fail;
  41 +import static org.junit.Assert.assertNull;
41 42
42 import javax.inject.Inject; 43 import javax.inject.Inject;
43 44
@@ -75,6 +76,9 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { @@ -75,6 +76,9 @@ public class ConfigurationPrimitiveOrWrapperFieldTest {
75 @Inject 76 @Inject
76 private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; 77 private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig;
77 78
  79 + @Inject
  80 + private PropertiesNullWrappedField nullWrappedField;
  81 +
78 @Deployment 82 @Deployment
79 public static JavaArchive createDeployment() { 83 public static JavaArchive createDeployment() {
80 JavaArchive deployment = Tests.createDeployment(ConfigurationPrimitiveOrWrapperFieldTest.class); 84 JavaArchive deployment = Tests.createDeployment(ConfigurationPrimitiveOrWrapperFieldTest.class);
@@ -85,92 +89,98 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { @@ -85,92 +89,98 @@ public class ConfigurationPrimitiveOrWrapperFieldTest {
85 89
86 @BeforeClass 90 @BeforeClass
87 public static void afterClass() { 91 public static void afterClass() {
88 - System.setProperty("primitiveInteger", String.valueOf(1));  
89 - System.setProperty("emptyPrimitiveInteger", String.valueOf(""));  
90 - System.setProperty("errorPrimitiveInteger", String.valueOf("a"));  
91 - System.setProperty("wrappedInteger", String.valueOf(2));  
92 - System.setProperty("emptyWrappedInteger", String.valueOf(""));  
93 - System.setProperty("errorWrappedInteger", String.valueOf("a")); 92 + System.setProperty("primitiveField", String.valueOf(1));
  93 + System.setProperty("emptyPrimitiveField", String.valueOf(""));
  94 + System.setProperty("errorPrimitiveField", String.valueOf("a"));
  95 + System.setProperty("wrappedField", String.valueOf(2));
  96 + System.setProperty("emptyWrappedField", String.valueOf(""));
  97 + System.setProperty("errorWrappedField", String.valueOf("a"));
94 } 98 }
95 99
96 @Test 100 @Test
97 - public void loadPrimitiveInteger() { 101 + public void loadPrimitiveField() {
98 int expected = 1; 102 int expected = 1;
99 103
100 - assertEquals(expected, systemConfig.getPrimitiveInteger());  
101 - assertEquals(expected, propertiesConfig.getPrimitiveInteger());  
102 - assertEquals(expected, xmlConfig.getPrimitiveInteger()); 104 + assertEquals(expected, systemConfig.getPrimitiveField());
  105 + assertEquals(expected, propertiesConfig.getPrimitiveField());
  106 + assertEquals(expected, xmlConfig.getPrimitiveField());
103 } 107 }
104 108
105 @Test 109 @Test
106 - public void loadWrappedInteger() { 110 + public void loadWrappedField() {
107 Integer expected = 2; 111 Integer expected = 2;
108 112
109 - assertEquals(expected, systemConfig.getWrappedInteger());  
110 - assertEquals(expected, propertiesConfig.getWrappedInteger());  
111 - assertEquals(expected, xmlConfig.getWrappedInteger()); 113 + assertEquals(expected, systemConfig.getWrappedField());
  114 + assertEquals(expected, propertiesConfig.getWrappedField());
  115 + assertEquals(expected, xmlConfig.getWrappedField());
112 } 116 }
113 117
114 @Test 118 @Test
115 - public void loadEmptyPrimitiveInteger() { 119 + public void loadEmptyPrimitiveField() {
116 try { 120 try {
117 - systemErrorConfig.getEmptyPrimitiveInteger(); 121 + systemErrorConfig.getEmptyPrimitiveField();
  122 + fail();
118 } catch (ConfigurationException cause) { 123 } catch (ConfigurationException cause) {
119 assertEquals(ConversionException.class, cause.getCause().getClass()); 124 assertEquals(ConversionException.class, cause.getCause().getClass());
120 } 125 }
121 126
122 try { 127 try {
123 - propertiesErrorConfig.getEmptyPrimitiveInteger(); 128 + propertiesErrorConfig.getEmptyPrimitiveField();
  129 + fail();
124 } catch (ConfigurationException cause) { 130 } catch (ConfigurationException cause) {
125 assertEquals(ConversionException.class, cause.getCause().getClass()); 131 assertEquals(ConversionException.class, cause.getCause().getClass());
126 } 132 }
127 133
128 try { 134 try {
129 - propertiesErrorConfig.getEmptyPrimitiveInteger(); 135 + propertiesErrorConfig.getEmptyPrimitiveField();
  136 + fail();
130 } catch (ConfigurationException cause) { 137 } catch (ConfigurationException cause) {
131 assertEquals(ConversionException.class, cause.getCause().getClass()); 138 assertEquals(ConversionException.class, cause.getCause().getClass());
132 } 139 }
133 } 140 }
134 141
135 @Test 142 @Test
136 - public void loadNullWrappedInteger() { 143 + public void loadEmptyWrappedField() {
137 try { 144 try {
138 - systemErrorConfig.getEmptyWrappedInteger(); 145 + systemErrorConfig.getEmptyWrappedField();
  146 + fail();
139 } catch (ConfigurationException cause) { 147 } catch (ConfigurationException cause) {
140 assertEquals(ConversionException.class, cause.getCause().getClass()); 148 assertEquals(ConversionException.class, cause.getCause().getClass());
141 } 149 }
142 150
143 try { 151 try {
144 - propertiesErrorConfig.getEmptyWrappedInteger(); 152 + propertiesErrorConfig.getEmptyWrappedField();
  153 + fail();
145 } catch (ConfigurationException cause) { 154 } catch (ConfigurationException cause) {
146 assertEquals(ConversionException.class, cause.getCause().getClass()); 155 assertEquals(ConversionException.class, cause.getCause().getClass());
147 } 156 }
148 157
149 try { 158 try {
150 - propertiesErrorConfig.getEmptyWrappedInteger(); 159 + propertiesErrorConfig.getEmptyWrappedField();
  160 + fail();
151 } catch (ConfigurationException cause) { 161 } catch (ConfigurationException cause) {
152 assertEquals(ConversionException.class, cause.getCause().getClass()); 162 assertEquals(ConversionException.class, cause.getCause().getClass());
153 } 163 }
154 } 164 }
155 165
156 @Test 166 @Test
157 - public void loadErrorPrimitiveInteger() { 167 + public void loadErrorPrimitiveField() {
158 try { 168 try {
159 - propertiesErrorConfig.getErrorPrimitiveInteger(); 169 + propertiesErrorConfig.getConversionErrorPrimitiveField();
160 fail(); 170 fail();
161 } catch (ConfigurationException cause) { 171 } catch (ConfigurationException cause) {
162 assertEquals(ConversionException.class, cause.getCause().getClass()); 172 assertEquals(ConversionException.class, cause.getCause().getClass());
163 } 173 }
164 174
165 try { 175 try {
166 - propertiesErrorConfig.getErrorPrimitiveInteger(); 176 + propertiesErrorConfig.getConversionErrorPrimitiveField();
167 fail(); 177 fail();
168 } catch (ConfigurationException cause) { 178 } catch (ConfigurationException cause) {
169 assertEquals(ConversionException.class, cause.getCause().getClass()); 179 assertEquals(ConversionException.class, cause.getCause().getClass());
170 } 180 }
171 181
172 try { 182 try {
173 - xmlErrorConfig.getErrorPrimitiveInteger(); 183 + xmlErrorConfig.getConversionErrorPrimitiveField();
174 fail(); 184 fail();
175 } catch (ConfigurationException cause) { 185 } catch (ConfigurationException cause) {
176 assertEquals(ConversionException.class, cause.getCause().getClass()); 186 assertEquals(ConversionException.class, cause.getCause().getClass());
@@ -178,26 +188,31 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { @@ -178,26 +188,31 @@ public class ConfigurationPrimitiveOrWrapperFieldTest {
178 } 188 }
179 189
180 @Test 190 @Test
181 - public void loadErrorWrappedInteger() { 191 + public void loadErrorWrappedField() {
182 try { 192 try {
183 - propertiesErrorConfig.getErrorWrappedInteger(); 193 + propertiesErrorConfig.getConversionErrorWrappedField();
184 fail(); 194 fail();
185 } catch (ConfigurationException cause) { 195 } catch (ConfigurationException cause) {
186 assertEquals(ConversionException.class, cause.getCause().getClass()); 196 assertEquals(ConversionException.class, cause.getCause().getClass());
187 } 197 }
188 198
189 try { 199 try {
190 - propertiesErrorConfig.getErrorWrappedInteger(); 200 + propertiesErrorConfig.getConversionErrorWrappedField();
191 fail(); 201 fail();
192 } catch (ConfigurationException cause) { 202 } catch (ConfigurationException cause) {
193 assertEquals(ConversionException.class, cause.getCause().getClass()); 203 assertEquals(ConversionException.class, cause.getCause().getClass());
194 } 204 }
195 205
196 try { 206 try {
197 - xmlErrorConfig.getErrorWrappedInteger(); 207 + xmlErrorConfig.getConversionErrorWrappedField();
198 fail(); 208 fail();
199 } catch (ConfigurationException cause) { 209 } catch (ConfigurationException cause) {
200 assertEquals(ConversionException.class, cause.getCause().getClass()); 210 assertEquals(ConversionException.class, cause.getCause().getClass());
201 } 211 }
202 } 212 }
  213 +
  214 + @Test
  215 + public void loadNullWrappedField(){
  216 + assertNull(nullWrappedField.getNullWrappedField());
  217 + }
203 } 218 }
impl/core/src/test/java/configuration/field/primitiveorwrapper/PropertiesNullWrappedField.java 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +package configuration.field.primitiveorwrapper;
  2 +
  3 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  4 +
  5 +@Configuration
  6 +public class PropertiesNullWrappedField {
  7 +
  8 + private Integer nullWrappedField;
  9 +
  10 + public Integer getNullWrappedField() {
  11 + return nullWrappedField;
  12 + }
  13 +}
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties
@@ -33,9 +33,9 @@ @@ -33,9 +33,9 @@
33 # ou escreva para a Fundação do Software Livre (FSF) Inc., 33 # ou escreva para a Fundação do Software Livre (FSF) Inc.,
34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
35 35
36 -primitiveInteger=1  
37 -emptyPrimitiveInteger=  
38 -errorPrimitiveInteger=a  
39 -wrappedInteger=2  
40 -aemptyWrappedInteger=  
41 -errorWrappedInteger=a  
42 \ No newline at end of file 36 \ No newline at end of file
  37 +primitiveField=1
  38 +emptyPrimitiveField=
  39 +conversionErrorPrimitiveField=a
  40 +wrappedField=2
  41 +emptyWrappedField=
  42 +conversionErrorWrappedField=a
43 \ No newline at end of file 43 \ No newline at end of file
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml
@@ -36,10 +36,10 @@ @@ -36,10 +36,10 @@
36 --> 36 -->
37 37
38 <configuration> 38 <configuration>
39 - <primitiveInteger>1</primitiveInteger>  
40 - <nullPrimitiveInteger></nullPrimitiveInteger>  
41 - <errorPrimitiveInteger>a</errorPrimitiveInteger>  
42 - <wrappedInteger>2</wrappedInteger>  
43 - <nullWrappedInteger></nullWrappedInteger>  
44 - <errorWrappedInteger>a</errorWrappedInteger> 39 + <primitiveField>1</primitiveField>
  40 + <emptyPrimitiveField></emptyPrimitiveField>
  41 + <conversionErrorPrimitiveField>a</conversionErrorPrimitiveField>
  42 + <wrappedField>2</wrappedField>
  43 + <emptyWrappedField></emptyWrappedField>
  44 + <conversionErrorWrappedField>a</conversionErrorWrappedField>
45 </configuration> 45 </configuration>