use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testMoveDown.
/**
* Same as testMoveUp, but moving down. See it for more information.
*/
@Test
public void testMoveDown() {
FavoritesEditor editor = new FavoritesEditor();
Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
FavoriteTask mySubProject1CompleFavorite = editor.addFavorite(mySubProject1Comple, false);
FavoriteTask mySubProject1LibFavorite = editor.addFavorite(mySubProject1Lib, false);
FavoriteTask mySubProject1DocFavorite = editor.addFavorite(mySubProject1Doc, false);
FavoriteTask mySubSubProjectCompileFavorite = editor.addFavorite(mySubSubProjectCompile, false);
FavoriteTask mySubSubProjectLibFavorite = editor.addFavorite(mySubSubProjectLib, false);
FavoriteTask mySubSubProjectDocFavorite = editor.addFavorite(mySubSubProjectDoc, false);
List<FavoriteTask> favoritesToMove = new ArrayList<FavoriteTask>();
favoritesToMove.add(mySubProject1CompleFavorite);
favoritesToMove.add(mySubProject1DocFavorite);
favoritesToMove.add(mySubSubProjectLibFavorite);
//our observer will make sure the order is correct.
TestOrderFavoritesObserver observer = new TestOrderFavoritesObserver(editor, mySubProject1LibFavorite, mySubProject1CompleFavorite, mySubSubProjectCompileFavorite, mySubProject1DocFavorite, mySubSubProjectDocFavorite, mySubSubProjectLibFavorite);
editor.addFavoriteTasksObserver(observer, false);
editor.moveFavoritesAfter(favoritesToMove);
//we're going to move them again, set the new expected order.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubProject1CompleFavorite, mySubSubProjectDocFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesAfter(favoritesToMove);
//move again. Set the new order. Notice that both mySubProject1DocFavorite and mySubSubProjectLibFavorite has stopped moving.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubSubProjectDocFavorite, mySubProject1CompleFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesAfter(favoritesToMove);
//one last time. Set the new order. Notice that the items have stopped moving. They're all at the bottom.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubSubProjectDocFavorite, mySubProject1CompleFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesAfter(favoritesToMove);
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testCancelingEditingFavorite.
/**
* This edits a favorite and cancels. We want to make sure that none of our changes during the editing are saved.
*/
@Test
public void testCancelingEditingFavorite() {
FavoritesEditor editor = new FavoritesEditor();
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 NOT notified of the edit. We'll provide no expectations for this mock object.
final FavoritesEditor.FavoriteTasksObserver observer = context.mock(FavoritesEditor.FavoriteTasksObserver.class);
editor.addFavoriteTasksObserver(observer, false);
//now perform the edit, but cancel out.
editor.editFavorite(favoriteTask, new FavoritesEditor.EditFavoriteInteraction() {
public boolean editFavorite(FavoritesEditor.EditibleFavoriteTask favoriteTask) {
favoriteTask.displayName = "newname";
//change the task's full name
favoriteTask.fullCommandLine = "nonexistanttask";
favoriteTask.alwaysShowOutput = !favoriteTask.alwaysShowOutput;
//return false to cancel!
return false;
}
public void reportError(String error) {
throw new AssertionError("unexpected error: " + error);
}
});
//make sure nothing was changed
favoriteTask = editor.getFavoriteTasks().get(0);
Assert.assertEquals("mysubproject1:compile", favoriteTask.getDisplayName());
Assert.assertEquals("mysubproject1:compile", favoriteTask.getFullCommandLine());
Assert.assertTrue(favoriteTask.alwaysShowOutput());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testChangingFullNameToNonExistantTask.
/**
* This edits a favorite, but specifically, we change the task's full name to something that doesn't exist. We don't
* want this to be an error. Maybe the task is temporarily unavailable because of a compile error. We shouldn't stop
* everything or throw it away just because the task isn't present. The UI should provide some indication of this
* however.
*/
@Test
public void testChangingFullNameToNonExistantTask() {
FavoritesEditor editor = new FavoritesEditor();
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";
//change the task's full name
favoriteTask.fullCommandLine = "nonexistanttask";
return true;
}
public void reportError(String error) {
throw new AssertionError("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";
//change the task's full name
favoriteTask.fullCommandLine = "mysubproject1:compile";
return true;
}
public void reportError(String error) {
throw new AssertionError("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());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testRemovingFavorites.
/**
* Tests removing a favorite. We add one, make sure its right, then remove it and make sure that it goes away as
* well as that we're notified.
*/
@Test
public void testRemovingFavorites() {
FavoritesEditor editor = new FavoritesEditor();
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 deletion.
final FavoritesEditor.FavoriteTasksObserver observer = context.mock(FavoritesEditor.FavoriteTasksObserver.class);
context.checking(new Expectations() {
{
one(observer).favoritesChanged();
}
});
editor.addFavoriteTasksObserver(observer, false);
//now remove the task
List<FavoriteTask> tasks = new ArrayList<FavoriteTask>();
tasks.add(favoriteTask);
editor.removeFavorites(tasks);
//make sure we were notified
context.assertIsSatisfied();
//there shouldn't be any more favorites.
Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testEditingFavoriteFullNameAlreadyExists.
/**
* This edits a favorite so the task is the same as an existing favorite. This doesn't make any sense to have two of
* these. We're expecting an error from this.
*/
@Test
public void testEditingFavoriteFullNameAlreadyExists() {
FavoritesEditor editor = new FavoritesEditor();
Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
//add two tasks
editor.addFavorite(mySubProject1Comple, true);
editor.addFavorite(mySubSubProjectLib, true);
//make sure they were added properly
FavoriteTask favoriteTask1 = editor.getFavoriteTasks().get(0);
Assert.assertEquals("mysubproject1:compile", favoriteTask1.getFullCommandLine());
FavoriteTask favoriteTask2 = editor.getFavoriteTasks().get(1);
Assert.assertEquals("mysubproject1:mysubsubproject:lib", favoriteTask2.getFullCommandLine());
//now perform the actual edit.
editExpectingNoError(editor, favoriteTask1, "new name", favoriteTask2.getFullCommandLine());
}
Aggregations