Package com.philip.journal.login.service.util

Source Code of com.philip.journal.login.service.util.PasswordUtilTest

/**
* @Created May 15, 2012 11:21:46 AM
* @author cry30
*/
package com.philip.journal.login.service.util;

import static org.junit.Assert.assertTrue;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import com.philip.journal.AbstractTestCase;
import com.philip.journal.core.JournalTestCommon;
import com.philip.journal.core.bean.User;
import com.philip.journal.core.exception.JournalException;

/**
*
*/
public class PasswordUtilTest extends AbstractTestCase<PasswordUtil> {

    /** RTFC. */
    private transient User testUser;

    @Override
    @Before
    public void setUp()
    {
        super.setUp();
        testUser = new User();
    }

    /**
     * Too simple to test. <br/>
     * Case 1: Encrypt changes the password.
     *
     * {@link com.philip.journal.login.service.util.PasswordUtil#encrypt(com.philip.journal.core.bean.User, java.lang.String)}
     * .
     */
    @Test
    public final void testEncryptCase1()
    {
        assertTrue(
                "Case 1: Encrypt changes the password.",
                !JournalTestCommon.TEST_PASSWORD.equals(getTestInstance().encrypt(testUser,
                        JournalTestCommon.TEST_PASSWORD)));
    }

    /**
     * Case 1: Too simple to test.
     * {@link com.philip.journal.login.service.util.PasswordUtil#checkPassword(com.philip.journal.core.bean.User, java.lang.String)}
     * .
     */
    @Test
    public final void testCheckPasswordCase1()
    {
        getTestInstance().checkPassword(testUser, JournalTestCommon.TEST_PASSWORD);
    }

    /**
     * Case 1: Null first parameter.
     *
     * Test method for
     * {@link com.philip.journal.login.service.util.PasswordUtil#sha512Encrypt(com.philip.journal.core.bean.User, java.lang.String)}
     * .
     */
    @Test(expected = JournalException.class)
    public final void testSha512EncryptCase1()
    {
        getTestInstance().sha512Encrypt(null, JournalTestCommon.TEST_PASSWORD);
    }

    /** Case 2: Null password is equivalent to empty String. */
    @Test
    public final void testSha512EncryptCase2()
    {
        Assert.assertEquals("Case 2: Null password is equivalent to empty String.",
                getTestInstance().sha512Encrypt(testUser, null), getTestInstance().sha512Encrypt(testUser, ""));
    }

    /*
     * (non-Javadoc)
     * @see com.philip.journal.AbstractTestCase#getTestInstanceClass()
     */
    @Override
    protected Class<PasswordUtil> getTestInstanceClass()
    {
        return PasswordUtil.class;
    }

}
TOP

Related Classes of com.philip.journal.login.service.util.PasswordUtilTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.