test/unit/util/StringTemplateTest.java
author cli
Thu Aug 20 14:31:19 2009 +0200 (2009-08-20)
changeset 12 bb6990c0dd1a
permissions -rw-r--r--
Merging fixes from sonews/1.0.3
     1 /*
     2  *   SONEWS News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package test.unit.util;
    20 
    21 import junit.framework.TestCase;
    22 import org.sonews.util.StringTemplate;
    23 
    24 /**
    25  * Unit test for class org.sonews.util.StringTemplate.
    26  * @author Christian Lins 
    27  * @see org.sonews.util.StringTemplate
    28  * @since sonews/0.5.0
    29  */
    30 public class StringTemplateTest extends TestCase
    31 {
    32 
    33   private static final String template = "Hello %WORLD and others!";
    34   
    35   public StringTemplateTest()
    36   {
    37     super("StringTemplateTest");
    38   }
    39 
    40   public void testCtor()
    41   {
    42     StringTemplate st;
    43     
    44     try
    45     {
    46       st = new StringTemplate(null);
    47       fail("Should have raised an IllegalArgumentException");
    48     }
    49     catch(IllegalArgumentException ex) {}
    50       
    51     st = new StringTemplate(template);
    52     assertNotNull(st);
    53     
    54     try
    55     {
    56       st = new StringTemplate(template, null);
    57       fail("Should have raised an IllegalArgumentException");
    58     }
    59     catch(IllegalArgumentException ex) {}
    60     
    61     st = new StringTemplate(template, "?");
    62     assertNotNull(st);
    63 
    64     st = new StringTemplate(template, "%");
    65     assertNotNull(st);
    66   }
    67   
    68   public void testSetter()
    69   {
    70     StringTemplate st = new StringTemplate(template);
    71     
    72     try
    73     {
    74       st.set("WORLD", null);
    75       fail("Should have raised an IllegalArgumentException");
    76     }
    77     catch(IllegalArgumentException ex){}
    78     
    79     st.set("WORLD", "Universe");
    80   }
    81   
    82   public void testToString()
    83   {
    84     StringTemplate st = new StringTemplate(template);
    85     st.set("WORLD", "Universe");
    86     
    87     String result = st.toString();
    88     assertNotNull(result);
    89   }
    90   
    91 }