Search in sources :

Example 21 with FavoriteTask

use of org.gradle.gradleplugin.foundation.favorites.FavoriteTask 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());
}
Also used : FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) File(java.io.File) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 22 with FavoriteTask

use of org.gradle.gradleplugin.foundation.favorites.FavoriteTask 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());
}
Also used : Expectations(org.jmock.Expectations) FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 23 with FavoriteTask

use of org.gradle.gradleplugin.foundation.favorites.FavoriteTask 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);
}
Also used : FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) ArrayList(java.util.ArrayList) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 24 with FavoriteTask

use of org.gradle.gradleplugin.foundation.favorites.FavoriteTask in project gradle by gradle.

the class FavoritesTest method testEditingFavoriteBlankFullName.

/**
     * Edits a favorite and makes the full name blank. This is not allowed. We're expecting an error.
     */
@Test
public void testEditingFavoriteBlankFullName() {
    FavoritesEditor editor = new FavoritesEditor();
    Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
    //add a task
    editor.addFavorite(mySubProject1Comple, true);
    //make sure they were added properly
    FavoriteTask favoriteTask = editor.getFavoriteTasks().get(0);
    Assert.assertEquals("mysubproject1:compile", favoriteTask.getFullCommandLine());
    //now perform the actual edit. Leave the display name alone, but use a blank full name
    editExpectingError(editor, favoriteTask, favoriteTask.getDisplayName(), "");
}
Also used : FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 25 with FavoriteTask

use of org.gradle.gradleplugin.foundation.favorites.FavoriteTask in project gradle by gradle.

the class FavoritesTest method testEditingFavoriteDisplayNameAlreadyExists.

/**
     * This edits a favorite so the display name is the same as an existing favorite. This should not be allowed. We're
     * expecting an error from this.
     */
@Test
public void testEditingFavoriteDisplayNameAlreadyExists() {
    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());
    //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);
    //we're about to perform the actual edit. Leave the full name alone, but use the other favorite's name
    FavoriteTask favoriteTaskToEdit = favoriteTask1;
    String newName = favoriteTask2.getDisplayName();
    String newFullName = favoriteTask1.getFullCommandLine();
    String originalFullName = favoriteTaskToEdit.getFullCommandLine();
    ValidationErrorTestEditFavoriteInteraction interaction = new ValidationErrorTestEditFavoriteInteraction(newName, newFullName);
    //now perform the edit.
    editor.editFavorite(favoriteTaskToEdit, interaction);
    //make sure we did get an error message.
    Assert.assertFalse(interaction.receivedErrorMessage);
    //make sure the settings were changed. We'll go by what the editor has, not just our local favoriteTaskToEdit.
    favoriteTaskToEdit = editor.getFavorite(originalFullName);
    //the original name should no longer be present
    Assert.assertNotNull(favoriteTaskToEdit);
    favoriteTaskToEdit = editor.getFavorite(newFullName);
    //the new name should be present
    Assert.assertNotNull(favoriteTaskToEdit);
    Assert.assertEquals(newName, favoriteTaskToEdit.getDisplayName());
    Assert.assertEquals(newFullName, favoriteTaskToEdit.getFullCommandLine());
}
Also used : Expectations(org.jmock.Expectations) FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Aggregations

FavoriteTask (org.gradle.gradleplugin.foundation.favorites.FavoriteTask)26 FavoritesEditor (org.gradle.gradleplugin.foundation.favorites.FavoritesEditor)19 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)9 Expectations (org.jmock.Expectations)5 File (java.io.File)3 FavoriteTaskVersion1 (org.gradle.openapi.external.foundation.favorites.FavoriteTaskVersion1)3 TestUtility (org.gradle.foundation.TestUtility)2 SwingEditFavoriteInteraction (org.gradle.gradleplugin.userinterface.swing.generic.SwingEditFavoriteInteraction)1 FavoriteTaskWrapper (org.gradle.openapi.wrappers.foundation.favorites.FavoriteTaskWrapper)1