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 8692 2012-10-01 14:16:57Z schulte $
033 */
034public class TaskEventSourceTest extends TestCase
035{
036    //--TaskEventSourceTest-----------------------------------------------------
037
038    /** Implementation to test. */
039    private TaskEventSource source;
040
041    /**
042     * Gets the {@code TaskEventSource} implementation tests are performed with.
043     *
044     * @return the {@code TaskEventSource} implementation tests are performed
045     * with.
046     */
047    public TaskEventSource getTaskEventSource()
048    {
049        return this.source;
050    }
051
052    /**
053     * Sets the {@code TaskEventSource} implementation tests are performed with.
054     *
055     * @param value the {@code TaskEventSource} implementation to perform tests
056     * with.
057     */
058    public final void setTaskEventSource( final TaskEventSource value )
059    {
060        this.source = value;
061    }
062
063    //-----------------------------------------------------TaskEventSourceTest--
064    //--Tests-------------------------------------------------------------------
065
066    /**
067     * Tests the {@link TaskEventSource#addTaskListener(TaskListener)} method to
068     * handle {@code null} listener values correctly by throwing a corresponding
069     * {@code NullPointerException}.
070     */
071    public void testAddTaskListener() throws Exception
072    {
073        assert this.getTaskEventSource() != null;
074
075        try
076        {
077            this.getTaskEventSource().addTaskListener( null );
078            throw new AssertionError();
079        }
080        catch ( NullPointerException e )
081        {
082            Assert.assertNotNull( e.getMessage() );
083            System.out.println( e.toString() );
084        }
085
086    }
087
088    /**
089     * Tests the {@link TaskEventSource#removeTaskListener(TaskListener)} method
090     * to handle {@code null} listener values correctly by throwing a
091     * corresponding {@code NullPointerException}.
092     */
093    public void testRemoveTaskListener() throws Exception
094    {
095        assert this.getTaskEventSource() != null;
096
097        try
098        {
099            this.getTaskEventSource().removeTaskListener( null );
100            throw new AssertionError();
101        }
102        catch ( NullPointerException e )
103        {
104            Assert.assertNotNull( e.getMessage() );
105            System.out.println( e.toString() );
106        }
107
108    }
109
110    /**
111     * Tests the {@link TaskEventSource#getTaskListeners()} method to not
112     * return a {@code null} value instead of an empty array when no listeners
113     * are registered.
114     */
115    public void testGetTaskListeners() throws Exception
116    {
117        assert this.getTaskEventSource() != null;
118
119        Assert.assertNotNull( this.getTaskEventSource().getTaskListeners() );
120    }
121
122    //-------------------------------------------------------------------Tests--
123}