Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
editor.addFavorite(mySubProject1Comple, true);
//make sure it was added properly
FavoriteTask favoriteTask = editor.getFavoriteTasks().get(0);
Assert.assertEquals("mysubproject1:compile", favoriteTask.getDisplayName());
Assert.assertEquals("mysubproject1:compile", favoriteTask.getFullCommandLine());
Assert.assertTrue(favoriteTask.alwaysShowOutput());
//create an observer so we can make sure we're notified of the edit.
final FavoritesEditor.FavoriteTasksObserver observer = context.mock(
FavoritesEditor.FavoriteTasksObserver.class);
context.checking(new Expectations() {{
one(observer).favoritesChanged();
}});
editor.addFavoriteTasksObserver(observer, false);
//now perform the edit.
editor.editFavorite(favoriteTask, new FavoritesEditor.EditFavoriteInteraction() {
public boolean editFavorite(FavoritesEditor.EditibleFavoriteTask favoriteTask) {
favoriteTask.displayName = "newname";
favoriteTask.fullCommandLine = "nonexistanttask"; //change the task's full name
return true;
}
public void reportError(String error) {
throw new AssertionFailedError("unexpected error: " + error);
}
});
//make sure we were notified
context.assertIsSatisfied();
//make sure the settings were changed
favoriteTask = editor.getFavoriteTasks().get(0);
Assert.assertEquals("newname", favoriteTask.getDisplayName());
Assert.assertEquals("nonexistanttask", favoriteTask.getFullCommandLine());
Assert.assertFalse(!favoriteTask.alwaysShowOutput());
//now change the full name back. Make sure the task is changed back.
//reset our expectations. We'll get notified again.
context.checking(new Expectations() {{
one(observer).favoritesChanged();
}});
//now perform the edit.
editor.editFavorite(favoriteTask, new FavoritesEditor.EditFavoriteInteraction() {
public boolean editFavorite(FavoritesEditor.EditibleFavoriteTask favoriteTask) {
favoriteTask.displayName = "newname";
favoriteTask.fullCommandLine = "mysubproject1:compile"; //change the task's full name
return true;
}
public void reportError(String error) {
throw new AssertionFailedError("unexpected error: " + error);
}
});
//make sure we were notified
context.assertIsSatisfied();
//make sure the settings were changed
favoriteTask = editor.getFavoriteTasks().get(0);
Assert.assertEquals("newname", favoriteTask.getDisplayName());
Assert.assertEquals("mysubproject1:compile", favoriteTask.getFullCommandLine());
Assert.assertFalse(!favoriteTask.alwaysShowOutput());
}