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.text.it;
022
023import junit.framework.Assert;
024import junit.framework.TestCase;
025import org.jdtaus.core.text.MessageEventSource;
026import org.jdtaus.core.text.MessageListener;
027
028/**
029 * Testcase for {@code MessageEventSource} implementations.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: MessageEventSourceTest.java 8743 2012-10-07 03:06:20Z schulte $
033 */
034public class MessageEventSourceTest extends TestCase
035{
036    //--MessageEventSourceTest--------------------------------------------------
037
038    /** Implementation to test. */
039    private MessageEventSource source;
040
041    /** Creates a new {@code MessageEventSourceTest} instance. */
042    public MessageEventSourceTest()
043    {
044        super();
045    }
046
047    /**
048     * Gets the {@code MessageEventSource} implementation tests are performed
049     * with.
050     *
051     * @return the {@code MessageEventSource} implementation tests are
052     * performed with.
053     */
054    public MessageEventSource getMessageEventSource()
055    {
056        return this.source;
057    }
058
059    /**
060     * Sets the {@code MessageEventSource} implementation tests are performed
061     * with.
062     *
063     * @param value the {@code MessageEventSource} implementation to perform
064     * tests with.
065     */
066    public void setMessageEventSource( final MessageEventSource value )
067    {
068        this.source = value;
069    }
070
071    //--------------------------------------------------MessageEventSourceTest--
072    //--Tests-------------------------------------------------------------------
073
074    /**
075     * Tests the {@link MessageEventSource#addMessageListener(MessageListener)}
076     * method to handle {@code null} listener values correctly by throwing a
077     * corresponding {@code NullPointerException}.
078     */
079    public void testAddMessageListener() throws Exception
080    {
081        assert this.getMessageEventSource() != null;
082
083        try
084        {
085            this.getMessageEventSource().addMessageListener( null );
086            throw new AssertionError();
087        }
088        catch ( final NullPointerException e )
089        {
090            Assert.assertNotNull( e.getMessage() );
091            System.out.println( e.toString() );
092        }
093
094    }
095
096    /**
097     * Tests the
098     * {@link MessageEventSource#removeMessageListener(MessageListener)}
099     * method to handle {@code null} listener values correctly by throwing a
100     * corresponding {@code NullPointerException}.
101     */
102    public void testRemoveMessageListener() throws Exception
103    {
104        assert this.getMessageEventSource() != null;
105
106        try
107        {
108            this.getMessageEventSource().removeMessageListener( null );
109            throw new AssertionError();
110        }
111        catch ( final NullPointerException e )
112        {
113            Assert.assertNotNull( e.getMessage() );
114            System.out.println( e.toString() );
115        }
116
117    }
118
119    /**
120     * Tests the {@link MessageEventSource#getMessageListeners()} method to not
121     * return a {@code null} value instead of an empty array when no listeners
122     * are registered.
123     */
124    public void testGetMessageListeners() throws Exception
125    {
126        assert this.getMessageEventSource() != null;
127
128        Assert.assertNotNull(
129            this.getMessageEventSource().getMessageListeners() );
130
131    }
132
133    //-------------------------------------------------------------------Tests--
134}