Skip to content
Permalink
Browse files

JENKINS-50603: Adds test-cases.

  • Loading branch information
deepy committed Apr 24, 2018
1 parent 030b2af commit 32df7bb7a4ed4cc0e83a6a7bfdc5d4d402c91a8b
Showing with 46 additions and 0 deletions.
  1. +46 −0 src/test/java/hudson/plugins/favorite/user/FavoriteListenerTest.java
@@ -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 32df7bb

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