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