001    /*
002     * Copyright (C) 2000-2001 Iowa State University
003     *
004     * This file is part of mjc, the MultiJava Compiler.
005     *
006     * $Id: TestCase.java,v 1.1 2003/06/30 00:49:07 cok Exp $
007     */
008    package junitutils;
009    
010    /**
011     * Some utility methods for test cases */
012    public class TestCase extends junit.framework.TestCase {
013    
014        //---------------------------------------------------------------------
015        // CONSTRUCTORS
016        //---------------------------------------------------------------------
017    
018        public TestCase( String name ) {
019            super( name );
020        }
021    
022        //---------------------------------------------------------------------
023        // PROTECTED MEMBERS
024        //---------------------------------------------------------------------
025    
026        /**
027         * Compare Strings for equality with better difference reporting. 
028         * @param expected  the expected string
029         * @param actual    the actual string
030         * @param detailed if true then report first position of
031         *                  difference along with Unicode values of the
032         *                  two characters, otherwise just compare strings
033         *                  for equality */
034        protected void assertEquals( String expected, String actual, 
035                                     boolean detailed )
036        {
037            if( detailed ) {
038                assertDiff( expected, actual );
039            } else {
040                assertEquals( expected, actual );
041            }
042        }
043    
044        protected void assertDiff( String expected, String actual ) {
045            Diff diff = new Diff( "expected", expected, "actual", actual );
046            if (diff.areDifferent()) {
047                fail( diff.result() );
048            }
049        }
050        
051        protected static final String NEWLINE = 
052            System.getProperty( "line.separator" );
053    }