Commit ebd26f7231dcc2404080cc6847a6c656007817d3
1 parent
767178c0
Exists in
master
Refatoração e adição de testes para os atributos de configuração
dos tipos primitivo e wrapped
Showing
7 changed files
with
89 additions
and
137 deletions
Show diff stats
impl/core/src/test/java/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java
| ... | ... | @@ -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 | 38 | |
| 39 | 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 | 38 | |
| 39 | 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 | 38 | |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | 40 | import static junit.framework.Assert.fail; |
| 41 | +import static org.junit.Assert.assertNull; | |
| 41 | 42 | |
| 42 | 43 | import javax.inject.Inject; |
| 43 | 44 | |
| ... | ... | @@ -75,6 +76,9 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { |
| 75 | 76 | @Inject |
| 76 | 77 | private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; |
| 77 | 78 | |
| 79 | + @Inject | |
| 80 | + private PropertiesNullWrappedField nullWrappedField; | |
| 81 | + | |
| 78 | 82 | @Deployment |
| 79 | 83 | public static JavaArchive createDeployment() { |
| 80 | 84 | JavaArchive deployment = Tests.createDeployment(ConfigurationPrimitiveOrWrapperFieldTest.class); |
| ... | ... | @@ -85,92 +89,98 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { |
| 85 | 89 | |
| 86 | 90 | @BeforeClass |
| 87 | 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 | 100 | @Test |
| 97 | - public void loadPrimitiveInteger() { | |
| 101 | + public void loadPrimitiveField() { | |
| 98 | 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 | 109 | @Test |
| 106 | - public void loadWrappedInteger() { | |
| 110 | + public void loadWrappedField() { | |
| 107 | 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 | 118 | @Test |
| 115 | - public void loadEmptyPrimitiveInteger() { | |
| 119 | + public void loadEmptyPrimitiveField() { | |
| 116 | 120 | try { |
| 117 | - systemErrorConfig.getEmptyPrimitiveInteger(); | |
| 121 | + systemErrorConfig.getEmptyPrimitiveField(); | |
| 122 | + fail(); | |
| 118 | 123 | } catch (ConfigurationException cause) { |
| 119 | 124 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 120 | 125 | } |
| 121 | 126 | |
| 122 | 127 | try { |
| 123 | - propertiesErrorConfig.getEmptyPrimitiveInteger(); | |
| 128 | + propertiesErrorConfig.getEmptyPrimitiveField(); | |
| 129 | + fail(); | |
| 124 | 130 | } catch (ConfigurationException cause) { |
| 125 | 131 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 126 | 132 | } |
| 127 | 133 | |
| 128 | 134 | try { |
| 129 | - propertiesErrorConfig.getEmptyPrimitiveInteger(); | |
| 135 | + propertiesErrorConfig.getEmptyPrimitiveField(); | |
| 136 | + fail(); | |
| 130 | 137 | } catch (ConfigurationException cause) { |
| 131 | 138 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 132 | 139 | } |
| 133 | 140 | } |
| 134 | 141 | |
| 135 | 142 | @Test |
| 136 | - public void loadNullWrappedInteger() { | |
| 143 | + public void loadEmptyWrappedField() { | |
| 137 | 144 | try { |
| 138 | - systemErrorConfig.getEmptyWrappedInteger(); | |
| 145 | + systemErrorConfig.getEmptyWrappedField(); | |
| 146 | + fail(); | |
| 139 | 147 | } catch (ConfigurationException cause) { |
| 140 | 148 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 141 | 149 | } |
| 142 | 150 | |
| 143 | 151 | try { |
| 144 | - propertiesErrorConfig.getEmptyWrappedInteger(); | |
| 152 | + propertiesErrorConfig.getEmptyWrappedField(); | |
| 153 | + fail(); | |
| 145 | 154 | } catch (ConfigurationException cause) { |
| 146 | 155 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 147 | 156 | } |
| 148 | 157 | |
| 149 | 158 | try { |
| 150 | - propertiesErrorConfig.getEmptyWrappedInteger(); | |
| 159 | + propertiesErrorConfig.getEmptyWrappedField(); | |
| 160 | + fail(); | |
| 151 | 161 | } catch (ConfigurationException cause) { |
| 152 | 162 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 153 | 163 | } |
| 154 | 164 | } |
| 155 | 165 | |
| 156 | 166 | @Test |
| 157 | - public void loadErrorPrimitiveInteger() { | |
| 167 | + public void loadErrorPrimitiveField() { | |
| 158 | 168 | try { |
| 159 | - propertiesErrorConfig.getErrorPrimitiveInteger(); | |
| 169 | + propertiesErrorConfig.getConversionErrorPrimitiveField(); | |
| 160 | 170 | fail(); |
| 161 | 171 | } catch (ConfigurationException cause) { |
| 162 | 172 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 163 | 173 | } |
| 164 | 174 | |
| 165 | 175 | try { |
| 166 | - propertiesErrorConfig.getErrorPrimitiveInteger(); | |
| 176 | + propertiesErrorConfig.getConversionErrorPrimitiveField(); | |
| 167 | 177 | fail(); |
| 168 | 178 | } catch (ConfigurationException cause) { |
| 169 | 179 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 170 | 180 | } |
| 171 | 181 | |
| 172 | 182 | try { |
| 173 | - xmlErrorConfig.getErrorPrimitiveInteger(); | |
| 183 | + xmlErrorConfig.getConversionErrorPrimitiveField(); | |
| 174 | 184 | fail(); |
| 175 | 185 | } catch (ConfigurationException cause) { |
| 176 | 186 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| ... | ... | @@ -178,26 +188,31 @@ public class ConfigurationPrimitiveOrWrapperFieldTest { |
| 178 | 188 | } |
| 179 | 189 | |
| 180 | 190 | @Test |
| 181 | - public void loadErrorWrappedInteger() { | |
| 191 | + public void loadErrorWrappedField() { | |
| 182 | 192 | try { |
| 183 | - propertiesErrorConfig.getErrorWrappedInteger(); | |
| 193 | + propertiesErrorConfig.getConversionErrorWrappedField(); | |
| 184 | 194 | fail(); |
| 185 | 195 | } catch (ConfigurationException cause) { |
| 186 | 196 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 187 | 197 | } |
| 188 | 198 | |
| 189 | 199 | try { |
| 190 | - propertiesErrorConfig.getErrorWrappedInteger(); | |
| 200 | + propertiesErrorConfig.getConversionErrorWrappedField(); | |
| 191 | 201 | fail(); |
| 192 | 202 | } catch (ConfigurationException cause) { |
| 193 | 203 | assertEquals(ConversionException.class, cause.getCause().getClass()); |
| 194 | 204 | } |
| 195 | 205 | |
| 196 | 206 | try { |
| 197 | - xmlErrorConfig.getErrorWrappedInteger(); | |
| 207 | + xmlErrorConfig.getConversionErrorWrappedField(); | |
| 198 | 208 | fail(); |
| 199 | 209 | } catch (ConfigurationException cause) { |
| 200 | 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 @@ |
| 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 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | 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 | 36 | \ No newline at end of file |
| 37 | +primitiveField=1 | |
| 38 | +emptyPrimitiveField= | |
| 39 | +conversionErrorPrimitiveField=a | |
| 40 | +wrappedField=2 | |
| 41 | +emptyWrappedField= | |
| 42 | +conversionErrorWrappedField=a | |
| 43 | 43 | \ No newline at end of file | ... | ... |
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml
| ... | ... | @@ -36,10 +36,10 @@ |
| 36 | 36 | --> |
| 37 | 37 | |
| 38 | 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 | 45 | </configuration> | ... | ... |