use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesIntegrationTest method testDuplicateSingleFavorite.
/**
* This tests duplicating a single favorite. First, we'll create some, then duplicate one.
*/
@Test
public void testDuplicateSingleFavorite() {
FavoritesEditor editor = new FavoritesEditor();
//add some tasks
FavoriteTask favoriteTask1 = editor.addFavorite(mySubProject1Comple, true);
FavoriteTask favoriteTask2 = editor.addFavorite(mySubSubProjectLib, false);
FavoriteTask favoriteTask3 = editor.addFavorite(mySubSubProjectDoc, false);
//now change the display names and the alwaysShowOutput field, just so we can verify that all fields are copied.
editFavorite(editor, favoriteTask1, "name1", false);
editFavorite(editor, favoriteTask2, "name2", true);
editFavorite(editor, favoriteTask3, "name3", false);
//duplicate a single task
FavoriteTask favoriteTask4 = editor.duplicateFavorite(favoriteTask1, new TestEditFavoriteInteraction("name4", "command4"));
Assert.assertNotNull(favoriteTask4);
Assert.assertEquals("command4", favoriteTask4.getFullCommandLine());
Assert.assertEquals("name4", favoriteTask4.getDisplayName());
Assert.assertEquals(favoriteTask1.alwaysShowOutput(), favoriteTask4.alwaysShowOutput());
//there should be 4 tasks now
Assert.assertEquals(4, editor.getFavoriteTasks().size());
//now duplicate another one
FavoriteTask favoriteTask5 = editor.duplicateFavorite(favoriteTask2, new TestEditFavoriteInteraction("name5", "command5"));
Assert.assertNotNull(favoriteTask5);
Assert.assertEquals("command5", favoriteTask5.getFullCommandLine());
Assert.assertEquals("name5", favoriteTask5.getDisplayName());
Assert.assertEquals(favoriteTask2.alwaysShowOutput(), favoriteTask5.alwaysShowOutput());
//there should be 5 tasks now
Assert.assertEquals(5, editor.getFavoriteTasks().size());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesIntegrationTest method testDuplicatingMultipleFavorites.
/**
* This tests duplicating multiple favorites at once. First, we'll create some, then duplicate them.
*/
@Test
public void testDuplicatingMultipleFavorites() {
FavoritesEditor editor = new FavoritesEditor();
//add some tasks
FavoriteTask favoriteTask1 = editor.addFavorite(mySubProject1Comple, true);
FavoriteTask favoriteTask2 = editor.addFavorite(mySubSubProjectLib, false);
FavoriteTask favoriteTask3 = editor.addFavorite(mySubSubProjectDoc, false);
//now change the display names and the alwaysShowOutput field, just so we can verify that all fields are copied.
editFavorite(editor, favoriteTask1, "name1", false);
editFavorite(editor, favoriteTask2, "name2", true);
editFavorite(editor, favoriteTask3, "name3", false);
//get the ones to dupicate in a list
List<FavoriteTask> tasksToCopy = new ArrayList<FavoriteTask>();
tasksToCopy.add(favoriteTask1);
tasksToCopy.add(favoriteTask2);
//now perform the duplication
editor.duplicateFavorites(tasksToCopy, new TestEditFavoriteInteraction(new NameAndCommand("newname1", "newcommand1"), new NameAndCommand("newname2", "newcommand2")));
//there should be 5 tasks now
Assert.assertEquals(5, editor.getFavoriteTasks().size());
//the 4th one (3 from index 0) should be the same as the first one
FavoriteTask favoriteTask4 = editor.getFavoriteTasks().get(3);
Assert.assertNotNull(favoriteTask4);
Assert.assertEquals("newcommand1", favoriteTask4.getFullCommandLine());
Assert.assertEquals("newname1", favoriteTask4.getDisplayName());
Assert.assertEquals(favoriteTask1.alwaysShowOutput(), favoriteTask4.alwaysShowOutput());
//the 5th one (4 from index 0) should be the same as the second one
FavoriteTask favoriteTask5 = editor.getFavoriteTasks().get(4);
Assert.assertNotNull(favoriteTask5);
Assert.assertEquals("newcommand2", favoriteTask5.getFullCommandLine());
Assert.assertEquals("newname2", favoriteTask5.getDisplayName());
Assert.assertEquals(favoriteTask2.alwaysShowOutput(), favoriteTask5.alwaysShowOutput());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesIntegrationTest method testConfirmOverwrite.
/**
* This confirms that overwriting a file requires confirmation. We'll create a file (just by creating a temporary file), then try to save to it.
*/
@Test
public void testConfirmOverwrite() {
//we should be prompted to confirm overwriting an existing file.
FavoritesEditor originalEditor = new FavoritesEditor();
Assert.assertTrue(originalEditor.getFavoriteTasks().isEmpty());
//add a favorite
FavoriteTask favoriteTask1 = originalEditor.addFavorite(mySubProject1Comple, true);
File file = tempDir.createFile("test.favorite-tasks");
//make sure the file exists, so we know our save will be overwritting something.
Assert.assertTrue(file.exists());
long originalSize = file.length();
TestOverwriteConfirmExportInteraction exportInteraction = new TestOverwriteConfirmExportInteraction(file, false);
//do the export
originalEditor.exportToFile(exportInteraction);
//make sure we were prompted to confirm overwriting
Assert.assertTrue(exportInteraction.wasConfirmed);
//make sure the size didn't change. This means we didn't write to it.
Assert.assertEquals(originalSize, file.length());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testEditingFavorite.
/**
* Here we edit a favorite. We want to make sure that we get notified of the edit and that we the edited values are
* stored properly. We'll add a favorite, then we perform an edit. Lastly, we verify our values. Notice that we're
* going to change the task's full name. This should update the task inside the favorite.
*/
@Test
public void testEditingFavorite() {
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.alwaysShowOutput = false;
favoriteTask.displayName = "newname";
favoriteTask.fullCommandLine = //change the task's full name
"myrootproject:mysubproject1:mysubsubproject:lib";
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("myrootproject:mysubproject1:mysubsubproject:lib", favoriteTask.getFullCommandLine());
Assert.assertTrue(!favoriteTask.alwaysShowOutput());
}
use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor in project gradle by gradle.
the class FavoritesTest method testMoveUp.
/**
* Tests moving favorites up. This mechansim is more advanced than just move the item up one. If you select multiple
* things with non-selected items between them and then repeatedly move up, this will 'bunch up' the items at the
* top while keeping the items in relative order between themselves. This seems like most users would actually want
* to happen (but I'm sure someone won't like it). This moves every other item and keeps moving them until they all
* wind up at the top.
*/
@Test
public void testMoveUp() {
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(mySubProject1LibFavorite);
favoritesToMove.add(mySubSubProjectCompileFavorite);
favoritesToMove.add(mySubSubProjectDocFavorite);
//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.moveFavoritesBefore(favoritesToMove);
//we're going to move them again, set the new expected order.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubProject1CompleFavorite, mySubSubProjectDocFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesBefore(favoritesToMove);
//move again. Set the new order. Notice that both mySubProject1LibFavorite mySubSubProjectCompileFavorite has stopped moving.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubSubProjectDocFavorite, mySubProject1CompleFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesBefore(favoritesToMove);
//one last time. Set the new order. Notice that the items have stopped moving. They're all at the top.
observer.setExpectedOrder(mySubProject1LibFavorite, mySubSubProjectCompileFavorite, mySubSubProjectDocFavorite, mySubProject1CompleFavorite, mySubProject1DocFavorite, mySubSubProjectLibFavorite);
editor.moveFavoritesBefore(favoritesToMove);
}
Aggregations