From 824145c6a88d579520eb2d14c6ec48801692ac8f Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Fri, 21 Jun 2013 20:03:28 -0300 Subject: [PATCH] Changed test to use the already installed facet --- .../configuration/ConfigurationFacetImpl.java | 16 +++++++++++++--- .../addon/configuration/ConfigurationTest.java | 16 ++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/configuration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigurationFacetImpl.java b/configuration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigurationFacetImpl.java index ca3f0241c1..81c6c77cf6 100644 --- a/configuration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigurationFacetImpl.java +++ b/configuration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigurationFacetImpl.java @@ -25,14 +25,20 @@ public class ConfigurationFacetImpl extends AbstractFacet implements Co @Override public boolean install() { - this.configuration = ConfigurationProducer.readConfig(getConfigLocation().getUnderlyingResourceObject()); return true; } @Override public boolean isInstalled() { - return getConfigLocation().exists(); + return true; + } + + @Override + public boolean uninstall() + { + getConfigLocation().delete(); + return true; } @Override @@ -44,6 +50,10 @@ public FileResource getConfigLocation() @Override public Configuration getConfiguration() { - return configuration; + if (this.configuration == null) + { + this.configuration = ConfigurationProducer.readConfig(getConfigLocation().getUnderlyingResourceObject()); + } + return this.configuration; } } diff --git a/configuration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationTest.java b/configuration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationTest.java index 2c21b0ccf5..bc6b6cfa09 100644 --- a/configuration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationTest.java +++ b/configuration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationTest.java @@ -7,13 +7,15 @@ package org.jboss.forge.addon.configuration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import javax.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; -import org.jboss.forge.addon.facets.FacetFactory; import org.jboss.forge.addon.projects.Project; import org.jboss.forge.addon.projects.ProjectFactory; import org.jboss.forge.arquillian.Addon; @@ -22,7 +24,6 @@ import org.jboss.forge.furnace.addons.AddonId; import org.jboss.forge.furnace.repositories.AddonDependencyEntry; import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,9 +59,6 @@ public static ForgeArchive getDeployment() @Inject private ProjectFactory projectFactory; - @Inject - private FacetFactory facetFactory; - @Test public void testConfigurationInjection() throws Exception { @@ -71,10 +69,12 @@ public void testConfigurationInjection() throws Exception public void testProjectFacet() throws Exception { Project project = projectFactory.createTempProject(); - ConfigurationFacet facet = facetFactory.install(project, ConfigurationFacet.class); - Assert.assertFalse(facet.getConfigLocation().exists()); + assertTrue(project.hasFacet(ConfigurationFacet.class)); + ConfigurationFacet facet = project.getFacet(ConfigurationFacet.class); + assertFalse(facet.getConfigLocation().exists()); Configuration config = facet.getConfiguration(); config.setProperty("key", "value"); - Assert.assertTrue(facet.getConfigLocation().exists()); + assertEquals("value", config.getString("key")); + assertTrue(facet.getConfigLocation().exists()); } } \ No newline at end of file