View Javadoc

1   /*
2    * Jour - bytecode instrumentation library
3    *
4    * Copyright (C) 2007 Vlad Skarzhevskyy
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   * 
21   * @version $Id: APICompareChangeHelper.java 111 2008-03-05 07:28:30Z vlads $
22   * 
23   */
24  package net.sf.jour.signature;
25  
26  import java.util.List;
27  import java.util.Vector;
28  
29  /**
30   * @author vlads
31   * 
32   */
33  class APICompareChangeHelper {
34  
35  	List changes;
36  
37  	APICompareChangeHelper() {
38  		changes = new Vector();
39  	}
40  
41  	public void fail(String message) {
42  		changes.add(message);
43  	}
44  
45  	public boolean assertTrue(String message, boolean condition) {
46  		if (!condition) {
47  			fail(message);
48  			return true;
49  		} else {
50  			return false;
51  		}
52  	}
53  
54  	public boolean assertFalse(String message, boolean condition) {
55  		if (condition) {
56  			fail(message);
57  			return true;
58  		} else {
59  			return false;
60  		}
61  	}
62  
63  	public boolean assertNull(String message, Object object) {
64  		return assertTrue(message, object == null);
65  	}
66  
67  	public boolean assertNotNull(String message, Object object) {
68  		return assertTrue(message, object != null);
69  	}
70  
71  	public boolean assertEquals(String message, int expected, int actual) {
72  		return assertEquals(message, new Integer(expected), new Integer(actual));
73  	}
74  
75  	public boolean assertEquals(String message, boolean expected, boolean actual) {
76  		return assertEquals(message, new Boolean(expected), new Boolean(actual));
77  	}
78  
79  	public boolean assertEquals(String message, Object expected, Object actual) {
80  		if (expected == null && actual == null) {
81  			return false;
82  		}
83  		if (expected != null && expected.equals(actual)) {
84  			return false;
85  		}
86  		failNotEquals(message, expected, actual);
87  		return true;
88  	}
89  
90  	private void failNotEquals(String message, Object expected, Object actual) {
91  		fail(format(message, expected, actual));
92  	}
93  
94  	String format(String message, Object expected, Object actual) {
95  		String formatted = "";
96  		if (message != null) {
97  			formatted = message + " ";
98  		}
99  		return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
100 	}
101 }