Search in sources :

Example 31 with Expectations

use of org.jmock.Expectations in project gradle by gradle.

the class FavoritesTest method testChangingFullNameToNonExistantTask.

/**
     * This edits a favorite, but specifically, we change the task's full name to something that doesn't exist. We don't
     * want this to be an error. Maybe the task is temporarily unavailable because of a compile error. We shouldn't stop
     * 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";
            //change the task's full name
            favoriteTask.fullCommandLine = "nonexistanttask";
            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";
            //change the task's full name
            favoriteTask.fullCommandLine = "mysubproject1:compile";
            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());
}
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 32 with Expectations

use of org.jmock.Expectations in project gradle by gradle.

the class FavoritesTest method testRemovingFavorites.

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

Example 33 with Expectations

use of org.jmock.Expectations 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 34 with Expectations

use of org.jmock.Expectations in project gradle by gradle.

the class AbstractReportTaskTest method passesEachProjectToRenderer.

@Test
public void passesEachProjectToRenderer() throws IOException {
    final Project child1 = createChildProject(project, "child1");
    final Project child2 = createChildProject(project, "child2");
    task.setProjects(project.getAllprojects());
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("seq");
            one(renderer).setClientMetaData((BuildClientMetaData) with(notNullValue()));
            inSequence(sequence);
            one(renderer).setOutput((StyledTextOutput) with(notNullValue()));
            inSequence(sequence);
            one(renderer).startProject(project);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(project);
            inSequence(sequence);
            one(renderer).startProject(child1);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(child1);
            inSequence(sequence);
            one(renderer).startProject(child2);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(child2);
            inSequence(sequence);
            one(renderer).complete();
            inSequence(sequence);
        }
    });
    task.generate();
}
Also used : Expectations(org.jmock.Expectations) BuildClientMetaData(org.gradle.initialization.BuildClientMetaData) Project(org.gradle.api.Project) TestUtil.createChildProject(org.gradle.util.TestUtil.createChildProject) Sequence(org.jmock.Sequence) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) Test(org.junit.Test)

Example 35 with Expectations

use of org.jmock.Expectations in project gradle by gradle.

the class AbstractReportTaskTest method setsOutputFileNameOnRendererBeforeGeneration.

@Test
public void setsOutputFileNameOnRendererBeforeGeneration() throws IOException {
    final File file = tmpDir.getTestDirectory().file("report.txt");
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("sequence");
            one(renderer).setClientMetaData((BuildClientMetaData) with(notNullValue()));
            inSequence(sequence);
            one(renderer).setOutputFile(file);
            inSequence(sequence);
            one(renderer).startProject(project);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(project);
            inSequence(sequence);
            one(renderer).complete();
            inSequence(sequence);
        }
    });
    task.setOutputFile(file);
    task.generate();
}
Also used : Expectations(org.jmock.Expectations) BuildClientMetaData(org.gradle.initialization.BuildClientMetaData) Sequence(org.jmock.Sequence) File(java.io.File) Test(org.junit.Test)

Aggregations

Expectations (org.jmock.Expectations)651 Test (org.junit.Test)443 UnitTest (org.apache.geode.test.junit.categories.UnitTest)109 File (java.io.File)41 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)41 InternalCache (org.apache.geode.internal.cache.InternalCache)35 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)33 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)32 Resource (org.apache.sling.api.resource.Resource)31 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)31 ArrayList (java.util.ArrayList)27 DiskStore (org.apache.geode.cache.DiskStore)23 ValueMap (org.apache.sling.api.resource.ValueMap)21 Before (org.junit.Before)20 CertificateGetOptions (org.nhindirect.config.service.impl.CertificateGetOptions)20 Sequence (org.jmock.Sequence)19 Cache (org.apache.geode.cache.Cache)18 Region (org.apache.geode.cache.Region)18 DistributedMember (org.apache.geode.distributed.DistributedMember)18 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)17