Search in sources :

Example 16 with FavoritesEditor

use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor 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 17 with FavoritesEditor

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

the class FavoritesTest method editExpectingNoError.

/**
     * This edits the favorite and expects NO error. It makes sure the error was received and that the original task was
     * not altered.
     */
private void editExpectingNoError(FavoritesEditor editor, FavoriteTask favoriteTaskToEdit, String newName, String newFullName) {
    String originalFullName = favoriteTaskToEdit.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);
    //now perform the edit.
    ValidationErrorTestEditFavoriteInteraction interaction = new ValidationErrorTestEditFavoriteInteraction(newName, newFullName);
    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.assertNull(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)

Example 18 with FavoritesEditor

use of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor 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)

Example 19 with FavoritesEditor

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

the class FavoritesTest method testRemovingNonExistantFavorite.

/**
     * This tests removing a favorite that isn't in our favorites editor. We just want to make sure we're not notified
     * of a change and that this doesn't blow up.
     */
public void testRemovingNonExistantFavorite() {
    //remove a task that doesn't exist. We should NOT be notified and it should not blow up
    FavoritesEditor otherEditor = new FavoritesEditor();
    Assert.assertTrue(otherEditor.getFavoriteTasks().isEmpty());
    otherEditor.addFavorite(mySubProject1Comple, true);
    FavoriteTask favoriteTask = otherEditor.getFavoriteTasks().get(0);
    //create another editor. This is the one we're really interested in.
    FavoritesEditor interestedEditor = new FavoritesEditor();
    //create an observer so we can make sure we're NOT notified of the deletion. We won't assign it any expectations.
    final FavoritesEditor.FavoriteTasksObserver observer = context.mock(FavoritesEditor.FavoriteTasksObserver.class);
    interestedEditor.addFavoriteTasksObserver(observer, false);
    //now remove the task
    List<FavoriteTask> tasks = new ArrayList<FavoriteTask>();
    tasks.add(favoriteTask);
    interestedEditor.removeFavorites(tasks);
    //it should still exist in the original
    Assert.assertEquals(1, otherEditor.getFavoriteTasks().size());
    //nothing exists in the new one.
    Assert.assertTrue(interestedEditor.getFavoriteTasks().isEmpty());
}
Also used : FavoritesEditor(org.gradle.gradleplugin.foundation.favorites.FavoritesEditor) ArrayList(java.util.ArrayList) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask)

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