Package de.timefinder.data

Source Code of de.timefinder.data.PersonTest

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  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.
*  under the License.
*/
package de.timefinder.data;

import de.timefinder.data.Role;
import de.timefinder.data.Event;
import de.timefinder.data.TimeFinderTester;
import de.timefinder.data.Person;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class PersonTest extends TimeFinderTester {

    private Person instance;

    public PersonTest() {
    }

    @Before
    @Override
    public void setUp() {
        super.setUp();
        instance = new Person();
    }

    /**
     * Test of setLastName method, of class Person.
     */
    @Test
    public void testSetProperties() {
        System.out.println("setProperties");

        assertNull(instance.getId());
        int oldHash = instance.hashCode();
        assertTrue(instance.hashCode() != 0);
        instance.setId(4L);
        assertEquals(oldHash, instance.hashCode());
        instance.setId(6L);
        assertEquals(oldHash, instance.hashCode());

        instance.setLastName("last");
        assertEquals("last", instance.getLastName());

        instance.setFirstName("first");
        assertEquals("first", instance.getFirstName());

        assertNotNull(instance.toString());
    }

    @Test
    public void testEqualsProperties() {
        instance.setLastName("test");
        instance.setFirstName("test2");
        Person instance2 = new Person();
        instance2.setLastName("test");
        instance2.setFirstName("test2");

        assertTrue(instance.equalsProperties(instance2));
    }

    @Test
    public void testSetRelations() {
        System.out.println("setRelations");

        instance.getEventsMap();
        Event ev = new Event();
        ev.setName("testEvent");
        instance.addEvent(ev, true);
        assertTrue(instance.getEventsMap().containsKey(ev));
        assertTrue(ev.getPersonsMap().containsKey(instance));
        assertTrue(instance.removeEvent(ev, true));
        assertFalse(instance.getEventsMap().containsKey(ev));
        assertFalse(ev.getPersonsMap().containsKey(instance));

        instance = new Person();
        instance.addEvent(ev, false);
        assertTrue(instance.getEventsMap().containsKey(ev));
        assertFalse(ev.getPersonsMap().containsKey(instance));
        assertTrue(instance.removeEvent(ev, true));
        assertFalse(instance.getEventsMap().containsKey(ev));
        assertFalse(ev.getPersonsMap().containsKey(instance));

        instance = new Person();
        instance.addEvent(ev, false);
        assertTrue(instance.getEventsMap().containsKey(ev));
        assertFalse(ev.getPersonsMap().containsKey(instance));
        assertTrue(instance.removeEvent(ev, false));
        assertFalse(instance.getEventsMap().containsKey(ev));
        assertFalse(ev.getPersonsMap().containsKey(instance));

        instance.addEvent(ev, Role.TEACHER, true);
        assertEquals(Role.TEACHER, instance.getRole(ev));
    }

    @Test
    public void testGetSubjects() {
        System.out.println("getSubjects");

        Event s = newEvent(0, 1);

        Object oldId = instance.getId();
        instance.addEvent(s, true);
        Collection<? extends Event> result = instance.getEventsMap().keySet();
        assertEquals(oldId, instance.getId());
        assertEquals(1, result.size());
        assertEquals(s, result.iterator().next());

        instance.removeEvent(s, true);
        result = instance.getEventsMap().keySet();
        assertEquals(0, result.size());
    }

    @Test
    public void addEvent() {
        Event ev = newEvent("test");
        instance.addEvent(ev, true);
        instance.addEvent(ev, true);

        assertEquals(1, instance.getEventsMap().size());
    }
}
TOP

Related Classes of de.timefinder.data.PersonTest

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.