Skip to content

Commit

Permalink
FORGE-2149: Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 13, 2015
1 parent 30209c3 commit f6f67ca
Showing 1 changed file with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.inject.Inject;

Expand All @@ -17,16 +18,12 @@
import org.jboss.forge.addon.projects.Project;
import org.jboss.forge.addon.projects.ProjectFactory;
import org.jboss.forge.addon.shell.test.ShellTest;
import org.jboss.forge.addon.ui.command.AbstractCommandExecutionListener;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.controller.CommandController;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.result.Failed;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.test.UITestHarness;
import org.jboss.forge.arquillian.AddonDependencies;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.archive.AddonArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
Expand All @@ -39,13 +36,7 @@ public class ValidationSetupCommandTest
{

@Deployment
@AddonDependencies({
@AddonDependency(name = "org.jboss.forge.addon:ui-test-harness"),
@AddonDependency(name = "org.jboss.forge.addon:shell-test-harness"),
@AddonDependency(name = "org.jboss.forge.addon:javaee"),
@AddonDependency(name = "org.jboss.forge.addon:maven"),
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi")
})
@AddonDependencies
public static AddonArchive getDeployment()
{
return ShrinkWrap.create(AddonArchive.class).addBeansXML().addClass(ProjectHelper.class);
Expand Down Expand Up @@ -99,6 +90,7 @@ public void checkCommandShell() throws Exception

Assert.assertThat(result, not(instanceOf(Failed.class)));
Assert.assertTrue(project.hasFacet(ValidationFacet.class));
Assert.assertEquals("1.1", project.getFacet(ValidationFacet.class).getConfig().getVersion());
}

@Test
Expand All @@ -114,21 +106,12 @@ public void testBeanValidationSetup() throws Exception
tester.setValueFor("providedScope", false);
Assert.assertTrue(tester.isValid());

final AtomicBoolean flag = new AtomicBoolean();
tester.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
{
@Override
public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
{
if (result.getMessage().equals("Bean Validation is installed."))
{
flag.set(true);
}
}
});
tester.execute();
// Ensure that the two pages were invoked
Assert.assertEquals(true, flag.get());
Result result = tester.execute();
Assert.assertThat(result, not(instanceOf(Failed.class)));
Assert.assertEquals("Bean Validation is installed.", result.getMessage());

Assert.assertTrue(project.hasFacet(ValidationFacet.class));
Assert.assertEquals("1.1", project.getFacet(ValidationFacet.class).getConfig().getVersion());
}
}
}

0 comments on commit f6f67ca

Please sign in to comment.