Commit 726762113dbcbe64bb983dd7f11a5eead32825cd
1 parent
d72e319d
Exists in
master
Testes com valores nulos e com erro de conversão
Showing
6 changed files
with
118 additions
and
4 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperFieldConfig.java
| ... | ... | @@ -40,8 +40,16 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig { |
| 40 | 40 | |
| 41 | 41 | private int primitiveInteger; |
| 42 | 42 | |
| 43 | + private int nullPrimitiveInteger; | |
| 44 | + | |
| 45 | + private int errorPrimitiveInteger; | |
| 46 | + | |
| 43 | 47 | private Integer wrappedInteger; |
| 44 | 48 | |
| 49 | + private Integer nullWrappedInteger; | |
| 50 | + | |
| 51 | + private Integer errorWrappedInteger; | |
| 52 | + | |
| 45 | 53 | public Integer getWrappedInteger() { |
| 46 | 54 | return wrappedInteger; |
| 47 | 55 | } |
| ... | ... | @@ -49,4 +57,20 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig { |
| 49 | 57 | public int getPrimitiveInteger() { |
| 50 | 58 | return primitiveInteger; |
| 51 | 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 | + } | |
| 52 | 76 | } | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/ConfigurationPrimitiveOrWrapperFieldTest.java
| ... | ... | @@ -37,20 +37,26 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.configuration.field.primitiveorwrapper; |
| 38 | 38 | |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | +import static junit.framework.Assert.fail; | |
| 40 | 41 | |
| 41 | 42 | import java.io.File; |
| 42 | 43 | |
| 43 | 44 | import javax.inject.Inject; |
| 44 | 45 | |
| 46 | +import junit.framework.Assert; | |
| 47 | + | |
| 48 | +import org.apache.commons.configuration.ConversionException; | |
| 45 | 49 | import org.jboss.arquillian.container.test.api.Deployment; |
| 46 | 50 | import org.jboss.arquillian.junit.Arquillian; |
| 47 | 51 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 48 | 52 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 49 | 53 | import org.junit.BeforeClass; |
| 50 | 54 | import org.junit.Test; |
| 55 | +import org.junit.internal.runners.statements.Fail; | |
| 51 | 56 | import org.junit.runner.RunWith; |
| 52 | 57 | |
| 53 | 58 | import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; |
| 59 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | |
| 54 | 60 | |
| 55 | 61 | @RunWith(Arquillian.class) |
| 56 | 62 | public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurationTest { |
| ... | ... | @@ -70,7 +76,8 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 70 | 76 | |
| 71 | 77 | deployment.addPackages(true, ConfigurationPrimitiveOrWrapperFieldTest.class.getPackage()); |
| 72 | 78 | deployment.addAsResource( |
| 73 | - new FileAsset(new File("src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties")), | |
| 79 | + new FileAsset(new File( | |
| 80 | + "src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties")), | |
| 74 | 81 | "demoiselle.properties").addAsResource( |
| 75 | 82 | new FileAsset(new File("src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml")), |
| 76 | 83 | "demoiselle.xml"); |
| ... | ... | @@ -81,7 +88,11 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 81 | 88 | @BeforeClass |
| 82 | 89 | public static void afterClass() { |
| 83 | 90 | System.setProperty("primitiveInteger", String.valueOf(1)); |
| 91 | + System.setProperty("nullPrimitiveInteger", String.valueOf("")); | |
| 92 | + System.setProperty("errorPrimitiveInteger", String.valueOf("a")); | |
| 84 | 93 | System.setProperty("wrappedInteger", String.valueOf(2)); |
| 94 | + System.setProperty("nullWrappedInteger", String.valueOf("")); | |
| 95 | + System.setProperty("errorWrappedInteger", String.valueOf("a")); | |
| 85 | 96 | } |
| 86 | 97 | |
| 87 | 98 | @Test |
| ... | ... | @@ -101,4 +112,75 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 101 | 112 | assertEquals(expected, propertiesConfig.getWrappedInteger()); |
| 102 | 113 | assertEquals(expected, xmlConfig.getWrappedInteger()); |
| 103 | 114 | } |
| 115 | + | |
| 116 | + @Test | |
| 117 | + public void loadNullPrimitiveInteger() { | |
| 118 | + int expected = 0; | |
| 119 | + | |
| 120 | + assertEquals(expected, systemConfig.getNullPrimitiveInteger()); | |
| 121 | + assertEquals(expected, propertiesConfig.getNullPrimitiveInteger()); | |
| 122 | + assertEquals(expected, xmlConfig.getNullPrimitiveInteger()); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @Test | |
| 126 | + public void loadNullWrappedInteger() { | |
| 127 | + Integer expected = null; | |
| 128 | + | |
| 129 | + assertEquals(expected, systemConfig.getNullWrappedInteger()); | |
| 130 | + assertEquals(expected, propertiesConfig.getNullWrappedInteger()); | |
| 131 | + assertEquals(expected, xmlConfig.getNullWrappedInteger()); | |
| 132 | + } | |
| 133 | + | |
| 134 | + @Test | |
| 135 | + public void loadErrorPrimitiveInteger() { | |
| 136 | + int expected = 0; | |
| 137 | + | |
| 138 | + try { | |
| 139 | + assertEquals(expected, propertiesConfig.getErrorPrimitiveInteger()); | |
| 140 | + fail(); | |
| 141 | + } catch (ConversionException cause) { | |
| 142 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 143 | + } | |
| 144 | + | |
| 145 | + try { | |
| 146 | + assertEquals(expected, propertiesConfig.getErrorPrimitiveInteger()); | |
| 147 | + fail(); | |
| 148 | + } catch (ConversionException cause) { | |
| 149 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 150 | + } | |
| 151 | + | |
| 152 | + try { | |
| 153 | + assertEquals(expected, xmlConfig.getErrorPrimitiveInteger()); | |
| 154 | + fail(); | |
| 155 | + } catch (ConversionException cause) { | |
| 156 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 157 | + } | |
| 158 | + | |
| 159 | + } | |
| 160 | + | |
| 161 | + @Test | |
| 162 | + public void loadErrorWrappedInteger() { | |
| 163 | + Integer expected = 2; | |
| 164 | + | |
| 165 | + try { | |
| 166 | + assertEquals(expected, propertiesConfig.getErrorWrappedInteger()); | |
| 167 | + fail(); | |
| 168 | + } catch (ConversionException cause) { | |
| 169 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 170 | + } | |
| 171 | + | |
| 172 | + try { | |
| 173 | + assertEquals(expected, propertiesConfig.getErrorWrappedInteger()); | |
| 174 | + fail(); | |
| 175 | + } catch (ConversionException cause) { | |
| 176 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 177 | + } | |
| 178 | + | |
| 179 | + try { | |
| 180 | + assertEquals(expected, xmlConfig.getErrorWrappedInteger()); | |
| 181 | + fail(); | |
| 182 | + } catch (ConversionException cause) { | |
| 183 | + Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 184 | + } | |
| 185 | + } | |
| 104 | 186 | } | ... | ... |
impl/core/src/test/resources/configuration/field/notnull/empty-field.properties
impl/core/src/test/resources/configuration/field/notnull/empty-field.xml
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties
| ... | ... | @@ -34,4 +34,8 @@ |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | |
| 36 | 36 | primitiveInteger=1 |
| 37 | -wrappedInteger=2 | |
| 38 | 37 | \ No newline at end of file |
| 38 | +nullPrimitiveInteger= | |
| 39 | +errorPrimitiveInteger=a | |
| 40 | +wrappedInteger=2 | |
| 41 | +nullWrappedInteger= | |
| 42 | +errorWrappedInteger=a | |
| 39 | 43 | \ No newline at end of file | ... | ... |
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml
| ... | ... | @@ -37,5 +37,9 @@ |
| 37 | 37 | |
| 38 | 38 | <configuration> |
| 39 | 39 | <primitiveInteger>1</primitiveInteger> |
| 40 | + <nullPrimitiveInteger></nullPrimitiveInteger> | |
| 41 | + <errorPrimitiveInteger>a</errorPrimitiveInteger> | |
| 40 | 42 | <wrappedInteger>2</wrappedInteger> |
| 43 | + <nullWrappedInteger></nullWrappedInteger> | |
| 44 | + <errorWrappedInteger>a</errorWrappedInteger> | |
| 41 | 45 | </configuration> | ... | ... |