Examples of FavoritesEditor


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

     * 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

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

    /**
     * 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

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

   }



    public GradlePluginLord() {
        favoritesEditor = new FavoritesEditor();

        //create the queue that executes the commands. The contents of this interaction are where we actually launch gradle.
        executionQueue = new ExecutionQueue<Request>(new ExecutionQueueInteraction());

        currentDirectory = new File(System.getProperty("user.dir"));
View Full Code Here

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

    /**
     * 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 two 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 AssertionFailedError("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");
        originalEditor.exportToFile(new TestUtility.TestExportInteraction(file,
                true)); //confirm overwrite because the above function actually creates the file.

        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);

View Full Code Here

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

     * 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");

        //Make sure the correct file doesn't already exist before we've even done our test. This is highly unlikely, but it might happen.
        //Technically, I should place these in a new temporary directory, but I didn't want the hassle of cleanup.
        if (correctFile.exists()) {
            throw new AssertionFailedError(
                    "'correct' file already exists. This means this test WILL succeed but perhaps not for the correct reasons.");
        }

        //do the export
        originalEditor.exportToFile(new TestUtility.TestExportInteraction(incorrectFile,
                true)); //confirm overwrite because the above function actually creates the file.

        //it should have been saved to the correct file
        if (!correctFile.exists()) {
            throw new AssertionFailedError(
                    "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);
    }
View Full Code Here

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

     * 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.
View Full Code Here

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

    /**
     * This tests duplicating a single favorite. First, we'll create some, then duplicate one.
     */
    @Test
    public void testDuplicateSingleFavorite() {
        FavoritesEditor editor = new FavoritesEditor();

        //add two 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 );
        Assert.assertNotNull( favoriteTask4 );
        Assert.assertEquals( favoriteTask1.getFullCommandLine(), favoriteTask4.getFullCommandLine() );
        Assert.assertEquals( favoriteTask1.getDisplayName(), 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 );
        Assert.assertNotNull(favoriteTask5);
        Assert.assertEquals( favoriteTask2.getFullCommandLine(), favoriteTask5.getFullCommandLine() );
        Assert.assertEquals( favoriteTask2.getDisplayName(), favoriteTask5.getDisplayName() );
        Assert.assertEquals( favoriteTask2.alwaysShowOutput(), favoriteTask5.alwaysShowOutput() );

        //there should be 5 tasks now
        Assert.assertEquals( 5, editor.getFavoriteTasks().size() );
    }
View Full Code Here

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

    /**
     * This tests duplicating multiple favorites at once. First, we'll create some, then duplicate them.
     */
    @Test
    public void testDuplicatingMultipleFavorites() {
        FavoritesEditor editor = new FavoritesEditor();

        //add two 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 peform the duplication
        editor.duplicateFavorites( tasksToCopy );

        //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( favoriteTask1.getFullCommandLine(), favoriteTask4.getFullCommandLine() );
        Assert.assertEquals( favoriteTask1.getDisplayName(), 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( favoriteTask2.getFullCommandLine(), favoriteTask5.getFullCommandLine() );
        Assert.assertEquals( favoriteTask2.getDisplayName(), favoriteTask5.getDisplayName() );
        Assert.assertEquals( favoriteTask2.alwaysShowOutput(), favoriteTask5.alwaysShowOutput() );      
    }
View Full Code Here

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

    /**
     * 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(); //reset our favorites changed notification so we know we're getting another one (I don't want to just verify that we got 2 messages. I want to make sure they arrived at the correct time.
        }});

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

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

     * Tests removing a favorite. We add one, make sure its right, then remove it and make sure that it goes away as
     * well as that we're notified.
     */
    @Test
    public void testRemovingFavorites() {
        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 deletion.
        final FavoritesEditor.FavoriteTasksObserver observer = context.mock(
                FavoritesEditor.FavoriteTasksObserver.class);
        context.checking(new Expectations() {{
            one(observer).favoritesChanged();
        }});

        editor.addFavoriteTasksObserver(observer, false);

        //now remove the task
        List<FavoriteTask> tasks = new ArrayList<FavoriteTask>();
        tasks.add(favoriteTask);
        editor.removeFavorites(tasks);

        //make sure we were notified
        context.assertIsSatisfied();

        //there shouldn't be any more favorites.
        Assert.assertTrue(editor.getFavoriteTasks().isEmpty());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.