Skip to content

Commit

Permalink
New project overwrite enabled now correctly calculated.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Apr 9, 2013
1 parent 4220cae commit 6bdfbc4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Expand Up @@ -101,9 +101,10 @@ public void initializeUI(final UIBuilder builder) throws Exception
@Override
public Boolean call() throws Exception
{
return targetLocation.getValue() != null
&& targetLocation.getValue().exists()
&& !targetLocation.getValue().listResources().isEmpty();
String projectName = named.getValue();
return targetLocation.getValue() != null && projectName != null
&& targetLocation.getValue().getChild(projectName).exists()
&& !targetLocation.getValue().getChild(projectName).listResources().isEmpty();
}
});
type.setLabel("Project Type:");
Expand Down
Expand Up @@ -57,6 +57,8 @@ public static ForgeArchive getDeployment()

@Inject
private NewProjectWizard command;
@Inject
private NewProjectWizard command2;

@Inject
private ResourceFactory factory;
Expand Down Expand Up @@ -95,8 +97,14 @@ public UIContext getUIContext()
try
{
command.initializeUI(builder);

Assert.assertFalse(command.getOverwrite().isEnabled());

command.getTargetLocation().setValue(factory.create(DirectoryResource.class, tempDir));
command.getNamed().setValue("test");

Assert.assertFalse(command.getOverwrite().isEnabled());

command.getTopLevelPackage().setValue("org.example");

command.validate(new UIValidationContext()
Expand Down Expand Up @@ -126,4 +134,47 @@ public void addValidationError(InputComponent<?, ?> input, String errorMessage)
Files.delete(tempDir, true);
}
}

@Test
public void testOverwriteEnabledWhenTargetDirectoryExistsNotEmpty() throws Exception
{
final List<InputComponent<?, ?>> inputs = new ArrayList<InputComponent<?, ?>>();

final UIContext context = new UIContextBase();
final UIBuilder builder = new UIBuilder()
{
@Override
public UIBuilder add(InputComponent<?, ?> input)
{
inputs.add(input);
return this;
}

@Override
public UIContext getUIContext()
{
return context;
}
};

File tempDir = File.createTempFile("forge", "projectTests");
tempDir.delete();
new File(tempDir, "test/something").mkdirs();

try
{
command2.initializeUI(builder);

Assert.assertFalse(command2.getOverwrite().isEnabled());

command2.getTargetLocation().setValue(factory.create(DirectoryResource.class, tempDir));
command2.getNamed().setValue("test");

Assert.assertTrue(command2.getOverwrite().isEnabled());
}
finally
{
Files.delete(tempDir, true);
}
}
}

0 comments on commit 6bdfbc4

Please sign in to comment.