1 /* 2 * jDTAUS Core Test Suite 3 * Copyright (C) 2005 Christian Schulte 4 * <cs@schulte.it> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 package org.jdtaus.core.text.it; 22 23 import junit.framework.Assert; 24 import junit.framework.TestCase; 25 import org.jdtaus.core.text.MessageEventSource; 26 import org.jdtaus.core.text.MessageListener; 27 28 /** 29 * Testcase for {@code MessageEventSource} implementations. 30 * 31 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 32 * @version $JDTAUS: MessageEventSourceTest.java 8743 2012-10-07 03:06:20Z schulte $ 33 */ 34 public class MessageEventSourceTest extends TestCase 35 { 36 //--MessageEventSourceTest-------------------------------------------------- 37 38 /** Implementation to test. */ 39 private MessageEventSource source; 40 41 /** Creates a new {@code MessageEventSourceTest} instance. */ 42 public MessageEventSourceTest() 43 { 44 super(); 45 } 46 47 /** 48 * Gets the {@code MessageEventSource} implementation tests are performed 49 * with. 50 * 51 * @return the {@code MessageEventSource} implementation tests are 52 * performed with. 53 */ 54 public MessageEventSource getMessageEventSource() 55 { 56 return this.source; 57 } 58 59 /** 60 * Sets the {@code MessageEventSource} implementation tests are performed 61 * with. 62 * 63 * @param value the {@code MessageEventSource} implementation to perform 64 * tests with. 65 */ 66 public void setMessageEventSource( final MessageEventSource value ) 67 { 68 this.source = value; 69 } 70 71 //--------------------------------------------------MessageEventSourceTest-- 72 //--Tests------------------------------------------------------------------- 73 74 /** 75 * Tests the {@link MessageEventSource#addMessageListener(MessageListener)} 76 * method to handle {@code null} listener values correctly by throwing a 77 * corresponding {@code NullPointerException}. 78 */ 79 public void testAddMessageListener() throws Exception 80 { 81 assert this.getMessageEventSource() != null; 82 83 try 84 { 85 this.getMessageEventSource().addMessageListener( null ); 86 throw new AssertionError(); 87 } 88 catch ( final NullPointerException e ) 89 { 90 Assert.assertNotNull( e.getMessage() ); 91 System.out.println( e.toString() ); 92 } 93 94 } 95 96 /** 97 * Tests the 98 * {@link MessageEventSource#removeMessageListener(MessageListener)} 99 * 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 }