test/unit/util/ResourceTest.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 25 Oct 2011 10:16:13 +0200
changeset 107 b723308e1359
parent 12 bb6990c0dd1a
permissions -rwxr-xr-x
SMTP: dot escaping – imported GNU code.
     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.io.Resource;
    23 
    24 /**
    25  * Unit test for class org.sonews.util.io.Resource.
    26  * @author Christian Lins
    27  * @see org.sonews.util.io.Resource
    28  * @since sonews/0.5.0
    29  */
    30 public class ResourceTest extends TestCase
    31 {
    32 
    33   public void testGetAsURL()
    34   {
    35     Object url;
    36     
    37     url = Resource.getAsURL(null);
    38     assertNull(url);
    39     
    40     url = Resource.getAsURL("this is absolutely bullshit");
    41     assertNull(url);
    42     
    43     // This file should exist
    44     url = Resource.getAsURL("org/sonews/Main.class");
    45     assertNotNull(url);
    46   }
    47   
    48   public void testGetAsStream()
    49   {
    50     Object stream;
    51     
    52     stream = Resource.getAsStream(null);
    53     assertNull(stream);
    54     
    55     stream = Resource.getAsStream("this is bullshit");
    56     assertNull(stream);
    57     
    58     stream = Resource.getAsStream("org/sonews/Main.class");
    59     assertNotNull(stream);
    60   }
    61   
    62   public void testGetAsString()
    63   {
    64     String str;
    65     
    66     str = Resource.getAsString(null, true);
    67     assertNull(str);
    68     
    69     str = Resource.getAsString("this is bullshit", true);
    70     assertNull(str);
    71     
    72     str = Resource.getAsString("org/sonews/Main.class", true);
    73     assertNotNull(str);
    74     
    75     str = Resource.getAsString("org/sonews/Main.class", false);
    76     assertNotNull(str);
    77     assertEquals(str.indexOf("\n"), -1);
    78   }
    79   
    80 }