Search in sources :

Example 6 with FavoritesEditor

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

the class FavoritesTest method testAddingFavorites.

/**
     * This tests adding a favorite task. We'll verify that we get notified and that the task is added properly.
     */
@Test
public void testAddingFavorites() {
    FavoritesEditor editor = new FavoritesEditor();
    Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
    final FavoritesEditor.FavoriteTasksObserver observer = context.mock(FavoritesEditor.FavoriteTasksObserver.class);
    context.checking(new Expectations() {

        {
            one(observer).favoritesChanged();
        }
    });
    editor.addFavoriteTasksObserver(observer, false);
    editor.addFavorite(mySubProject1Comple, true);
    context.assertIsSatisfied();
    //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());
    //now add another one, this time set alwaysShowOutput to false
    context.checking(new Expectations() {

        {
            one(observer).favoritesChanged();
        }
    });
    editor.addFavorite(mySubSubProjectDoc, false);
    context.assertIsSatisfied();
    //make sure it was added properly
    favoriteTask = editor.getFavoriteTasks().get(1);
    Assert.assertEquals("mysubproject1:mysubsubproject:doc", favoriteTask.getDisplayName());
    Assert.assertEquals("mysubproject1:mysubsubproject:doc", favoriteTask.getFullCommandLine());
    Assert.assertFalse(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 7 with FavoritesEditor

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

the class FavoritesTest method testEditingFavoriteBlankDisplayName.

/**
     * Edits a favorite and makes the display name blank. This is not allowed. We're expecting an error.
     */
@Test
public void testEditingFavoriteBlankDisplayName() {
    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 full name alone, but use a blank full name
    editExpectingError(editor, favoriteTask, "", favoriteTask.getFullCommandLine());
}
Also used : FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 8 with FavoritesEditor

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

the class FavoritesIntegrationTest method testSavingRestoringFavorites.

/**
     * This creates favorites, saves them to a file, then reads them from that file.
     */
@Test
public void testSavingRestoringFavorites() {
    FavoritesEditor originalEditor = new FavoritesEditor();
    Assert.assertTrue(originalEditor.getFavoriteTasks().isEmpty());
    //add some tasks
    FavoriteTask favoriteTask1 = originalEditor.addFavorite(mySubProject1Comple, true);
    FavoriteTask favoriteTask2 = originalEditor.addFavorite(mySubSubProjectLib, false);
    //now change the display name so its not the same as the full name, just so know each field is working.
    originalEditor.editFavorite(favoriteTask1, new FavoritesEditor.EditFavoriteInteraction() {

        public boolean editFavorite(FavoritesEditor.EditibleFavoriteTask favoriteTask) {
            favoriteTask.displayName = "favorite 1";
            return true;
        }

        public void reportError(String error) {
            throw new AssertionError("Unexpected error");
        }
    });
    //make sure they were added properly
    FavoriteTask originalFavoriteTask1 = originalEditor.getFavoriteTasks().get(0);
    assertFavorite(originalFavoriteTask1, "mysubproject1:compile", "favorite 1", true);
    FavoriteTask originalFavoriteTask2 = originalEditor.getFavoriteTasks().get(1);
    assertFavorite(originalFavoriteTask2, "mysubproject1:mysubsubproject:lib", "mysubproject1:mysubsubproject:lib", false);
    File file = tempDir.createFile("fred.favorite-tasks");
    //confirm overwrite because the above function actually creates the file.
    originalEditor.exportToFile(new TestUtility.TestExportInteraction(file, true));
    FavoritesEditor newEditor = new FavoritesEditor();
    newEditor.importFromFile(new TestUtility.TestImportInteraction(file));
    //make sure they're the same
    FavoriteTask readInFavoriteTask1 = originalEditor.getFavoriteTasks().get(0);
    assertFavorite(readInFavoriteTask1, originalFavoriteTask1);
    FavoriteTask readInFavoriteTask2 = originalEditor.getFavoriteTasks().get(1);
    assertFavorite(readInFavoriteTask2, originalFavoriteTask2);
}
Also used : TestUtility(org.gradle.foundation.TestUtility) FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) File(java.io.File) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Example 9 with FavoritesEditor

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

the class FavoritesIntegrationTest method testDuplicatingMultipleFavoritesAndCanceling.

/**
     * This tests duplicating multiple favorites at once, but we cancel out after duplicating one. We want to make sure that it doesn't continue to create the others. First, we'll create some, then
     * duplicate them.
     */
@Test
public void testDuplicatingMultipleFavoritesAndCanceling() {
    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 duplicate in a list
    List<FavoriteTask> tasksToCopy = new ArrayList<FavoriteTask>();
    tasksToCopy.add(favoriteTask1);
    tasksToCopy.add(favoriteTask2);
    //now perform the duplication, we only pass in one NameAndCommand but we're editing 2. This makes it cancel the second one.
    editor.duplicateFavorites(tasksToCopy, new TestEditFavoriteInteraction(new NameAndCommand("newname1", "newcommand1")));
    //there should be 4 tasks now
    //this just provides a better error if this fails to cancel
    Assert.assertNotSame("Failed to cancel", 5, editor.getFavoriteTasks().size());
    Assert.assertEquals(4, 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());
}
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 10 with FavoritesEditor

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

the class FavoritesIntegrationTest method testEnsureFileHasCorrectExtension.

/**
     * This verifies that the serialization mechanism corrects the extension so that it is correct. We'll save a file with the wrong extension. The save mechanism should save it with the correct
     * extension appended to the end (leaving the wrong extension in tact, just not at the end).
     */
@Test
public void testEnsureFileHasCorrectExtension() {
    FavoritesEditor originalEditor = new FavoritesEditor();
    Assert.assertTrue(originalEditor.getFavoriteTasks().isEmpty());
    //add a favorite
    FavoriteTask favoriteTask1 = originalEditor.addFavorite(mySubProject1Comple, true);
    //specify a wrong extension. It should actually end in ".favorite-tasks"
    File incorrectFile = tempDir.createFile("fred.wrong");
    File correctFile = new File(incorrectFile.getParentFile(), incorrectFile.getName() + ".favorite-tasks");
    //Technically, I should place these in a new temporary directory, but I didn't want the hassle of cleanup.
    if (correctFile.exists()) {
        throw new AssertionError("'correct' file already exists. This means this test WILL succeed but perhaps not for the correct reasons.");
    }
    //do the export
    //confirm overwrite because the above function actually creates the file.
    originalEditor.exportToFile(new TestUtility.TestExportInteraction(incorrectFile, true));
    //it should have been saved to the correct file
    if (!correctFile.exists()) {
        throw new AssertionError("failed to correct the file name. Expected it to be saved to '" + correctFile.getAbsolutePath() + "'");
    }
    //now read in the file to verify it actually worked.
    FavoritesEditor newEditor = new FavoritesEditor();
    newEditor.importFromFile(new TestUtility.TestImportInteraction(correctFile));
    FavoriteTask readInFavoriteTask = newEditor.getFavoriteTasks().get(0);
    assertFavorite(readInFavoriteTask, favoriteTask1);
}
Also used : TestUtility(org.gradle.foundation.TestUtility) FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) File(java.io.File) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Test(org.junit.Test)

Aggregations

FavoritesEditor (org.gradle.gradleplugin.foundation.favorites.FavoritesEditor)19 FavoriteTask (org.gradle.gradleplugin.foundation.favorites.FavoriteTask)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)6 Expectations (org.jmock.Expectations)6 File (java.io.File)3 TestUtility (org.gradle.foundation.TestUtility)2