1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  @test
  26  @summary A simple reflection testcase
  27  @summary com.apple.junit.java.lang.String;
  28  @run junit q0001BasicString
  29  */
  30 
  31 import junit.framework.*;
  32 
  33 public class q0001BasicString extends TestCase {
  34     protected String stringUninitialized;
  35     protected String stringNull;
  36     protected String stringEmpty;
  37     protected String stringOne;
  38     protected String stringTwo;
  39     protected String     stringOneTwo;
  40 
  41     protected void setUp() {
  42           stringNull = null;
  43         stringEmpty = "";
  44         stringOne = "one";
  45          stringTwo = "Two";
  46          stringOneTwo = "oneTwo";
  47      }
  48 
  49     public void testUninitializedString() throws Exception {
  50         assertEquals("Uninitialized string is not null", null, stringUninitialized);
  51     }
  52 
  53     public void testNullString() throws Exception {
  54         assertEquals("Null string not null", null, stringNull);
  55     }
  56 
  57     public void testEmptyString() throws Exception {
  58         assertTrue("Empty string is null", (stringEmpty != null));
  59     }
  60 
  61     public void testSimpleConcatenate() throws Exception {
  62         assertEquals("Concatenating two strings did not give expected string", stringOneTwo, (stringOne + stringTwo));
  63     }
  64 
  65     public void testConcatenateWithEmpty() throws Exception {
  66         assertEquals("Concatenating stringOne with empty string should give original string", stringOne, stringOne + stringEmpty);
  67         assertEquals("Concatenating stringTwo with empty string should give original string", stringTwo, stringTwo + stringEmpty);
  68     }
  69 
  70     protected void tearDown() {
  71     }
  72 
  73     public static Test suite() {
  74         return new TestSuite(q0001BasicString.class);
  75     }
  76 
  77     public static void main (String[] args) throws RuntimeException {
  78         TestResult tr = junit.textui.TestRunner.run(suite());
  79         if((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
  80             throw new RuntimeException("### Unexpected JUnit errors or failures.");
  81         }
  82     }
  83 }