Skip to content
Permalink
Browse files

[JENKINS-25682] #17 refinement: NameWith.priority is intended to be c…

…ompared amongst also interfaces implemented closer in the superclass chain than others.
  • Loading branch information...
jglick committed Dec 19, 2014
1 parent c64a608 commit c1470db23f2ecde3f8cf1a96120a3920452bb5f0
@@ -25,6 +25,9 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
@@ -87,16 +90,15 @@ public static String name(@NonNull Credentials credentials) {
// ignore
}
}
List<Class<?>> supertypes = new ArrayList<Class<?>>();
Class<?> supe = clazz.getSuperclass();
Result result = null;
if (supe != null) {
result = name(credentials, supe);
if (result != null) {
return result;
}
supertypes.add(supe);
}
for (Class<?> xface : clazz.getInterfaces()) {
Result _result = name(credentials, xface);
supertypes.addAll(Arrays.asList(clazz.getInterfaces()));
Result result = null;
for (Class<?> supertype : supertypes) {
Result _result = name(credentials, supertype);
if (_result != null && (result == null || result.priority < _result.priority)) {
result = _result;
}
@@ -108,6 +108,19 @@
private static class C11 extends TestCredentials implements I6, I7 {}
private static class C12 extends TestCredentials implements I7, I6 {}

@Test public void interfaceViaSuperclassPriorities() {
assertEquals("I9N", CredentialsNameProvider.name(new C14()));
}
@NameWith(value=I8N.class, priority=1)
private interface I8 extends Credentials {}
public static class I8N extends TestCredentialsNameProvider {}
private static class C13 extends TestCredentials implements I8 {}
@NameWith(value=I9N.class, priority=2)
private interface I9 extends Credentials {}
public static class I9N extends TestCredentialsNameProvider {}
private interface I10 extends I9 {}
private static class C14 extends C13 implements I10 {}

private static abstract class TestCredentials implements Credentials {
@Override public CredentialsScope getScope() {
return CredentialsScope.GLOBAL;
@@ -0,0 +1,41 @@
/*
* The MIT License
*
* Copyright 2014 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.cloudbees.plugins.credentials.impl;

import com.cloudbees.plugins.credentials.CredentialsNameProvider;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;

public class UsernamePasswordCredentialsImplTest {

@Rule public JenkinsRule r = new JenkinsRule(); // needed for Secret.fromString to work

@Test public void displayName() {
assertEquals("bob/****** (Bob’s laptop)", CredentialsNameProvider.name(new UsernamePasswordCredentialsImpl(null, "abc123", "Bob’s laptop", "bob", "s3cr3t")));
}

}

0 comments on commit c1470db

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