Skip to content
Permalink
Browse files

Merge pull request #22 from deepy/JENKINS-50603

JENKINS-50603: Verify that the job was a favorite before adding it again
  • Loading branch information
michaelneale committed May 16, 2018
2 parents 983893f + 32df7bb commit c004c8c408b0a52271225e9d702124c691213e41
@@ -21,7 +21,7 @@ public void onRenamed(Item item, String oldName, String newName) {
for (User user : User.getAll()) {
FavoriteUserProperty fup = user.getProperty(FavoriteUserProperty.class);
try {
if (fup != null) {
if (fup != null && fup.isJobFavorite(oldName)) {
fup.deleteFavourite(oldName);
fup.addFavorite(newName);
}
@@ -17,8 +17,10 @@

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@@ -48,6 +50,50 @@ public void testListener() throws IOException, FavoriteException {
assertEquals(item, listener.removeFavorites.get(user));
}

@Test
public void testRenameNoFavorite() throws Exception {
// GIVEN
FreeStyleProject old = rule.createFreeStyleProject("Old project");
User user = User.get("bob");

FavoriteUserProperty property = user.getProperty(FavoriteUserProperty.class);
Set<String> favorites = property.getAllFavorites();

FavoriteJobListener listener = new FavoriteJobListener();
assertFalse("Should not contain 'New project'", favorites.contains("New project"));
assertFalse("Should contain 'Old project'", favorites.contains("Old project"));

// WHEN
listener.onRenamed(old, "Old project", "New project");

// THEN
assertFalse("Should contain 'New project'", favorites.contains("New project"));
assertFalse("Should not contain 'Old project'", favorites.contains("Old project"));
}

@Test
public void testRenameFavorite() throws Exception {
// GIVEN
FreeStyleProject old = rule.createFreeStyleProject("Old project");
User user = User.get("bob");

FavoriteUserProperty property = user.getProperty(FavoriteUserProperty.class);
Set<String> favorites = property.getAllFavorites();

Favorites.addFavorite(user, old);

FavoriteJobListener listener = new FavoriteJobListener();
assertFalse("Should not contain 'New project'", favorites.contains("New project"));
assertTrue("Should contain 'Old project'", favorites.contains("Old project"));

// WHEN
listener.onRenamed(old, "Old project", "New project");

// THEN
assertTrue("Should contain 'New project'", favorites.contains("New project"));
assertFalse("Should not contain 'Old project'", favorites.contains("Old project"));
}

@Extension
public static class TestFavoriteJobListener extends FavoriteListener {

0 comments on commit c004c8c

Please sign in to comment.
You can’t perform that action at this time.