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 8692 2012-10-01 14:16:57Z schulte $ 33 */ 34 public class MessageEventSourceTest extends TestCase 35 { 36 //--MessageEventSourceTest-------------------------------------------------- 37 38 /** Implementation to test. */ 39 private MessageEventSource source; 40 41 /** 42 * Gets the {@code MessageEventSource} implementation tests are performed 43 * with. 44 * 45 * @return the {@code MessageEventSource} implementation tests are 46 * performed with. 47 */ 48 public MessageEventSource getMessageEventSource() 49 { 50 return this.source; 51 } 52 53 /** 54 * Sets the {@code MessageEventSource} implementation tests are performed 55 * with. 56 * 57 * @param value the {@code MessageEventSource} implementation to perform 58 * tests with. 59 */ 60 public void setMessageEventSource( final MessageEventSource value ) 61 { 62 this.source = value; 63 } 64 65 //--------------------------------------------------MessageEventSourceTest-- 66 //--Tests------------------------------------------------------------------- 67 68 /** 69 * Tests the {@link MessageEventSource#addMessageListener(MessageListener)} 70 * method to handle {@code null} listener values correctly by throwing a 71 * corresponding {@code NullPointerException}. 72 */ 73 public void testAddMessageListener() throws Exception 74 { 75 assert this.getMessageEventSource() != null; 76 77 try 78 { 79 this.getMessageEventSource().addMessageListener( null ); 80 throw new AssertionError(); 81 } 82 catch ( NullPointerException e ) 83 { 84 Assert.assertNotNull( e.getMessage() ); 85 System.out.println( e.toString() ); 86 } 87 88 } 89 90 /** 91 * Tests the 92 * {@link MessageEventSource#removeMessageListener(MessageListener)} 93 * method to handle {@code null} listener values correctly by throwing a 94 * corresponding {@code NullPointerException}. 95 */ 96 public void testRemoveMessageListener() throws Exception 97 { 98 assert this.getMessageEventSource() != null; 99 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 }