/*
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.jasig.cas.support.spnego.authentication.principal;

import org.jasig.cas.authentication.principal.DefaultPrincipalFactory;
import org.jasig.cas.authentication.principal.Principal;
import org.junit.Test;

import static org.junit.Assert.*;


/**
 * @author Misagh Moayyed
 * @since 3.0.0
 */
public class SpnegoCredentialsTests {

    @Test
    public void verifyToStringWithNoPrincipal() {
        final SpnegoCredential credentials = new SpnegoCredential(new byte[] {});

        assertTrue(credentials.toString().contains("unknown"));
    }

    @Test
    public void verifyToStringWithPrincipal() {
        final SpnegoCredential credentials = new SpnegoCredential(new byte[] {});
        final Principal principal = new DefaultPrincipalFactory().createPrincipal("test");
        credentials.setPrincipal(principal);
        assertEquals("test", credentials.toString());
    }
}

@@ -1682,11 +1682,1004 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Important for SPNEGO in particular as the credential will be hashed prior to Principal resolution%0A     */%0A    @Test%0A    public void verifyCredentialsHashSafelyWithoutPrincipal() %7B%0A        final SpnegoCredential credential = new SpnegoCredential(new byte%5B%5D %7B%7D);%0A        try %7B%0A            final int hash = credential.hashCode();%0A            assertNotNull(hash);%0A        %7D%0A        catch(final Exception e) %7B%0A            fail(e.getMessage());%0A        %7D%0A    %7D%0A%0A    /**%0A     * Make sure that when the Principal becomes populated / changes we return a new hash%0A     */%0A    @Test%0A    public void verifyPrincipalAffectsHash()%7B%0A        final SpnegoCredential credential = new SpnegoCredential(new byte%5B%5D %7B%7D);%0A        final int hash1 = credential.hashCode();%0A        final Principal principal = new DefaultPrincipalFactory().createPrincipal(%22test%22);%0A        credential.setPrincipal(principal);%0A        final int hash2 = credential.hashCode();%0A        assertNotEquals(hash1, hash2);%0A    %7D
 %0A%7D%0A

Add unit tests per @mmoayyed