Package com.semagia.atomico.dm.impl

Source Code of com.semagia.atomico.dm.impl.TestAuthor

/*
* Copyright 2008 - 2010 Lars Heuer (heuer[at]semagia.com). All rights reserved.
*
* Licensed 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
*
*     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 com.semagia.atomico.dm.impl;

import com.semagia.atomico.dm.IAuthor;

import junit.framework.TestCase;

/**
* Tests against {@link Author}.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
*/
public class TestAuthor extends TestCase {

    public void testNotEquals() {
        final IAuthor author = new Author();
        assertFalse(author.equals(new Object()));
        assertFalse(author.equals(null));
    }

    public void testDefaultConstructor() {
        final String name = "[unknown]";
        final IAuthor author = new Author();
        assertEquals(name, author.getName());
        assertNull(author.getEmail());
        assertNull(author.getIRI());
        assertEquals(author, author);
    }

    public void testNameConstructor() {
        final String name = "name";
        final IAuthor author = new Author(name);
        assertEquals(name, author.getName());
        assertNull(author.getEmail());
        assertNull(author.getIRI());
        assertEquals(author.hashCode(), new Author(name).hashCode());
    }

    public void testIllegalNameConstructor() {
        try {
            new Author(null);
            fail("Author(null) should be illegal");
        }
        catch (IllegalArgumentException ex) {
            // noop.
        }
    }

    public void testIllegalNameConstructor2() {
        try {
            new Author("");
            fail("Author(\"\") should be illegal");
        }
        catch (IllegalArgumentException ex) {
            // noop.
        }
    }

    public void testNameEmailConstructor() {
        final String name = "name";
        final String email = "john@example.org";
        final IAuthor author = new Author(name, email);
        assertEquals(name, author.getName());
        assertEquals(email, author.getEmail());
        assertNull(author.getIRI());
        assertEquals(author, new Author(name, email));
        assertEquals(author.hashCode(), new Author(name, email).hashCode());
    }

    public void testNameEmailConstructor2() {
        final String name = "name";
        final String email = null;
        final IAuthor author = new Author(name, email);
        assertEquals(name, author.getName());
        assertEquals(email, author.getEmail());
        assertNull(author.getIRI());
    }

    public void testIllegalNameEmailConstructor() {
        final String name = "name";
        final String email = "";
        try {
            new Author(name, email);
            fail("DefaultAuthor(\"name\", \"\") should be illegal");
        }
        catch (IllegalArgumentException ex) {
            // noop.
        }
    }

    public void testNameEmailIRIConstructor() {
        final String name = "name";
        final String email = "john@example.org";
        final String iri = "http://www.semagia.com/";
        final IAuthor author = new Author(name, email, iri);
        assertEquals(name, author.getName());
        assertEquals(email, author.getEmail());
        assertEquals(iri, author.getIRI());
        final IAuthor author2 = new Author(name, email, iri);
        assertEquals(author, author2);
        assertEquals(author.hashCode(), author2.hashCode());
    }

    public void testNameEmailIRIConstructor2() {
        final String name = "name";
        final String email = null;
        final String iri = "http://www.semagia.com/";
        final IAuthor author = new Author(name, email, iri);
        assertEquals(name, author.getName());
        assertEquals(email, author.getEmail());
        assertEquals(iri, author.getIRI());
    }

    public void testIllegalNameEmailIRIConstructor() {
        try {
            new Author("name", "john@example.org", "");
            fail("Author(\"name\", \"john@example.org\", \"\") should be illegal");
        }
        catch (IllegalArgumentException ex) {
            // noop.
        }
    }

    public void testEquals() {
        final IAuthor author = new Author();
        assertEquals(author, author);
    }

    public void testEquals2() {
        final String name = "name";
        final IAuthor author = new Author(name);
        assertEquals(author, author);
    }

    public void testEquals3() {
        final String name = "name";
        final IAuthor author1 = new Author(name);
        final IAuthor author2 = new Author(name);
        assertEquals(author1, author2);
        assertEquals(author1.hashCode(), author2.hashCode());
    }

    public void testEquals4() {
        final IAuthor author1 = new Author("name1");
        final IAuthor author2 = new Author("name2");
        assertFalse(author1.equals(author2));
    }

}
TOP

Related Classes of com.semagia.atomico.dm.impl.TestAuthor

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.