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.2 2006/06/08 17:45:41 chalin 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( /*@ non_null */ String expected,
035 /*@ non_null */ String actual,
036 boolean detailed )
037 {
038 if( detailed ) {
039 assertDiff( expected, actual );
040 } else {
041 assertEquals( expected, actual );
042 }
043 }
044
045 protected void assertDiff(/*@ non_null */ String expected, /*@ non_null */ String actual ) {
046 Diff diff = new Diff( "expected", expected, "actual", actual );
047 if (diff.areDifferent()) {
048 fail( diff.result() );
049 }
050 }
051
052 protected static final String NEWLINE =
053 System.getProperty( "line.separator" );
054 }