Package org.gradle.gradleplugin.foundation.favorites

Examples of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor


     * 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());
    }
View Full Code Here


     * 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
                        = "myrootproject:mysubproject1:mysubsubproject:lib";   //change the task's full name
                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());
    }
View Full Code Here

     * 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";
                favoriteTask.fullCommandLine = "nonexistanttask";   //change the task's full name
                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";
                favoriteTask.fullCommandLine = "mysubproject1:compile";   //change the task's full name
                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());
    }
View Full Code Here

    /**
     * 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";
                favoriteTask.fullCommandLine = "nonexistanttask";   //change the task's full name
                favoriteTask.alwaysShowOutput = !favoriteTask.alwaysShowOutput;
                return false//return false to cancel!
            }

            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());
    }
View Full Code Here

     * 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());
    }
View Full Code Here

     * 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);
        Assert.assertNotNull(favoriteTaskToEdit);   //the original name should no longer be present

        favoriteTaskToEdit = editor.getFavorite(newFullName);
        Assert.assertNotNull(favoriteTaskToEdit);   //the new name should be present

        Assert.assertEquals(newName, favoriteTaskToEdit.getDisplayName());
        Assert.assertEquals(newFullName, favoriteTaskToEdit.getFullCommandLine());
    }
View Full Code Here

    /**
     * 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(), "");
    }
View Full Code Here

    /**
     * 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());
    }
View Full Code Here

     * 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);
    }
View Full Code Here

    /**
     * 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);
    }
View Full Code Here

TOP

Related Classes of org.gradle.gradleplugin.foundation.favorites.FavoritesEditor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.