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());
}
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());
}
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());
}
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();
}
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();
}
Aggregations