public void testCreateEnum() throws Exception
{
Project project = projectFactory.createTempProject();
facetFactory.install(project, JavaSourceFacet.class);
JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
JavaEnumSource javaEnum = Roaster.parse(JavaEnumSource.class,
"package org.jboss.forge.test; public enum CreditCardType{}");
facet.saveJavaSource(javaEnum);
JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
Assert.assertNotNull(javaResource);
Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaEnum.class)));
CommandController controller = testHarness.createCommandController(JavaEnumConstantCommand.class,
javaResource);
controller.initialize();
controller.setValueFor("arguments", Arrays.asList("VISA", "AMERICAN_EXPRESS", "MASTERCARD"));
Assert.assertTrue(controller.isValid());
Assert.assertTrue(controller.canExecute());
Result result = controller.execute();
Assert.assertThat(result, is(not(instanceOf(Failed.class))));
javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
JavaEnumSource enumClass = javaResource.getJavaType();
List<EnumConstantSource> enumConstants = enumClass.getEnumConstants();
Assert.assertEquals(3, enumConstants.size());
Assert.assertEquals("VISA", enumConstants.get(0).getName());
Assert.assertEquals("AMERICAN_EXPRESS", enumConstants.get(1).getName());
Assert.assertEquals("MASTERCARD", enumConstants.get(2).getName());