From b8ace7789acd9cf8dffd4eda1db9fe07665607ca Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 21 Oct 2013 15:34:58 -0400 Subject: [PATCH] Ensuring that getRelativeNameFrom actually inserts ../ sequences where it should. The implementation of the method is rather hard to follow so this certainly needs to be tested! --- core/src/test/java/hudson/FunctionsTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/hudson/FunctionsTest.java b/core/src/test/java/hudson/FunctionsTest.java index 84b03bc481..cafa59670c 100644 --- a/core/src/test/java/hudson/FunctionsTest.java +++ b/core/src/test/java/hudson/FunctionsTest.java @@ -203,16 +203,20 @@ public class FunctionsTest { when(i.getName()).thenReturn("jobName"); when(i.getDisplayName()).thenReturn("displayName"); TopLevelItemAndItemGroup ig = mock(TopLevelItemAndItemGroup.class); - Jenkins j = mock(Jenkins.class); + ItemGroup j = mock(Jenkins.class); when(ig.getName()).thenReturn("parent"); when(ig.getDisplayName()).thenReturn("parentDisplay"); - when(ig.getParent()).thenReturn((ItemGroup) j); + when(ig.getParent()).thenReturn(j); when(i.getParent()).thenReturn(ig); - + Item i2 = mock(Item.class); + when(i2.getDisplayName()).thenReturn("top"); + when(i2.getParent()).thenReturn(j); + assertEquals("displayName", Functions.getRelativeDisplayNameFrom(i, ig)); assertEquals("parentDisplay » displayName", Functions.getRelativeDisplayNameFrom(i, j)); + assertEquals(".. » top", Functions.getRelativeDisplayNameFrom(i2, ig)); } - + private void createMockAncestors(StaplerRequest req, Ancestor... ancestors) { List ancestorsList = Arrays.asList(ancestors); when(req.getAncestors()).thenReturn(ancestorsList);