001    /*
002     * $Id: StringTester.java,v 1.3 2012/03/22 18:12:00 oboehm Exp $
003     *
004     * Copyright (c) 2012 by Oliver Boehm
005     *
006     * Licensed under the Apache License, Version 2.0 (the "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     * 
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     * 
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     * 
018     * (c)reated 24.01.2012 by oliver (ob@oasd.de)
019     */
020    
021    package patterntesting.runtime.junit;
022    
023    import static org.junit.Assert.*;
024    
025    /**
026     * This tester provides some special assert methods for strings to simplify
027     * JUnit testing.
028     * 
029     * @author oboehm
030     * @since 1.2.10-YEARS (24.01.2012)
031     */
032    public final class StringTester {
033    
034        /** Utility class - no need to instantiate it. */
035        private StringTester() {}
036        
037        /**
038         * Check if the given string is not null and not empty.
039         *
040         * @param s the string
041         */
042        public static void assertNotEmpty(final String s) {
043            assertNotNull(s);
044            if (s.length() == 0) {
045                throw new AssertionError("String is empty");
046            }
047        }
048        
049        /**
050         * Check if the given string is null or empty.
051         * This method was introduced for symmetric reason to
052         * {@link #assertNotEmpty(String)}.
053         *
054         * @param s the s
055         */
056        public static void assertEmpty(final String s) {
057            if (s != null) {
058                assertEquals('"' + s + "\" is not empty", 0, s.length());
059            }
060        }
061    
062    }
063