001/*
002 *  jDTAUS Core Test Suite
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.monitor.it;
022
023import junit.framework.Assert;
024import junit.framework.TestCase;
025import org.jdtaus.core.monitor.TaskEventSource;
026import org.jdtaus.core.monitor.TaskListener;
027
028/**
029 * Testcase for {@code TaskEventSource} implementations.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: TaskEventSourceTest.java 8743 2012-10-07 03:06:20Z schulte $
033 */
034public class TaskEventSourceTest extends TestCase
035{
036    //--TaskEventSourceTest-----------------------------------------------------
037
038    /** Implementation to test. */
039    private TaskEventSource source;
040
041    /** Creates a new {@code TaskEventSourceTest} instance. */
042    public TaskEventSourceTest()
043    {
044        super();
045    }
046
047    /**
048     * Gets the {@code TaskEventSource} implementation tests are performed with.
049     *
050     * @return the {@code TaskEventSource} implementation tests are performed
051     * with.
052     */
053    public TaskEventSource getTaskEventSource()
054    {
055        return this.source;
056    }
057
058    /**
059     * Sets the {@code TaskEventSource} implementation tests are performed with.
060     *
061     * @param value the {@code TaskEventSource} implementation to perform tests
062     * with.
063     */
064    public final void setTaskEventSource( final TaskEventSource value )
065    {
066        this.source = value;
067    }
068
069    //-----------------------------------------------------TaskEventSourceTest--
070    //--Tests-------------------------------------------------------------------
071
072    /**
073     * Tests the {@link TaskEventSource#addTaskListener(TaskListener)} method to
074     * handle {@code null} listener values correctly by throwing a corresponding
075     * {@code NullPointerException}.
076     */
077    public void testAddTaskListener() throws Exception
078    {
079        assert this.getTaskEventSource() != null;
080
081        try
082        {
083            this.getTaskEventSource().addTaskListener( null );
084            throw new AssertionError();
085        }
086        catch ( final NullPointerException e )
087        {
088            Assert.assertNotNull( e.getMessage() );
089            System.out.println( e.toString() );
090        }
091
092    }
093
094    /**
095     * Tests the {@link TaskEventSource#removeTaskListener(TaskListener)} method
096     * to handle {@code null} listener values correctly by throwing a
097     * corresponding {@code NullPointerException}.
098     */
099    public void testRemoveTaskListener() throws Exception
100    {
101        assert this.getTaskEventSource() != null;
102
103        try
104        {
105            this.getTaskEventSource().removeTaskListener( null );
106            throw new AssertionError();
107        }
108        catch ( final NullPointerException e )
109        {
110            Assert.assertNotNull( e.getMessage() );
111            System.out.println( e.toString() );
112        }
113
114    }
115
116    /**
117     * Tests the {@link TaskEventSource#getTaskListeners()} method to not
118     * return a {@code null} value instead of an empty array when no listeners
119     * are registered.
120     */
121    public void testGetTaskListeners() throws Exception
122    {
123        assert this.getTaskEventSource() != null;
124
125        Assert.assertNotNull( this.getTaskEventSource().getTaskListeners() );
126    }
127
128    //-------------------------------------------------------------------Tests--
129}