001: package org.springunit.framework.samples.jpetstore.domain;
002:
003: import org.springunit.framework.SpringUnitContext;
004: import org.springunit.framework.SpringUnitTest;
005:
006: /**
007: * Test for the Account domain object in the JPetStore sample application.
008: * This test reveals a SpringUnit anti-pattern:
009: * if testing of a method does not require variation of the data,
010: * then moving the test data into a separate XML file
011: * introduces unnecessary overhead.
012: * For the Account class, only two methods fall into this
013: * category: getListOptionAsInt and getBannerOptionAsInt.
014: * If tested at all, only these two methods require testing.
015: * There exists a strong argument for not testing the class
016: * at all, since there is nothing that could possibly break
017: * (that could not be identified easily by code inspection).
018: * @author <a href="mailto:ted@velkoff.com">Ted Velkoff</a>
019: *
020: */
021: public class AccountTest extends SpringUnitTest {
022:
023: public void testUsername() throws Exception {
024: Account subject = getObject("subject");
025: String username = getObject("username");
026: String expected = getObject("expected");
027: subject.setUsername(username);
028: String actual = subject.getUsername();
029: assertTrue(expected.equals(actual));
030: }
031:
032: public void testPassword() throws Exception {
033: Account subject = getObject("subject");
034: String password = getObject("password");
035: String expected = getObject("expected");
036: subject.setPassword(password);
037: String actual = subject.getPassword();
038: assertTrue(expected.equals(actual));
039: }
040:
041: public void testEmail() throws Exception {
042: Account subject = getObject("subject");
043: String email = getObject("email");
044: String expected = getObject("expected");
045: subject.setEmail(email);
046: String actual = subject.getEmail();
047: assertTrue(expected.equals(actual));
048: }
049:
050: public void testFirstName() throws Exception {
051: Account subject = getObject("subject");
052: String firstName = getObject("firstName");
053: String expected = getObject("expected");
054: subject.setFirstName(firstName);
055: String actual = subject.getFirstName();
056: assertTrue(expected.equals(actual));
057: }
058:
059: public void testLastName() throws Exception {
060: Account subject = getObject("subject");
061: String lastName = getObject("lastName");
062: String expected = getObject("expected");
063: subject.setLastName(lastName);
064: String actual = subject.getLastName();
065: assertTrue(expected.equals(actual));
066: }
067:
068: public void testStatus() throws Exception {
069: Account subject = getObject("subject");
070: String status = getObject("status");
071: String expected = getObject("expected");
072: subject.setStatus(status);
073: String actual = subject.getStatus();
074: assertTrue(expected.equals(actual));
075: }
076:
077: public void testAddress1() throws Exception {
078: Account subject = getObject("subject");
079: String address1 = getObject("address1");
080: String expected = getObject("expected");
081: subject.setAddress1(address1);
082: String actual = subject.getAddress1();
083: assertTrue(expected.equals(actual));
084: }
085:
086: public void testAddress2() throws Exception {
087: Account subject = getObject("subject");
088: String address2 = getObject("address2");
089: String expected = getObject("expected");
090: subject.setAddress2(address2);
091: String actual = subject.getAddress2();
092: assertTrue(expected.equals(actual));
093: }
094:
095: public void testCity() throws Exception {
096: Account subject = getObject("subject");
097: String city = getObject("city");
098: String expected = getObject("expected");
099: subject.setCity(city);
100: String actual = subject.getCity();
101: assertTrue(expected.equals(actual));
102: }
103:
104: public void testState() throws Exception {
105: Account subject = getObject("subject");
106: String state = getObject("state");
107: String expected = getObject("expected");
108: subject.setState(state);
109: String actual = subject.getState();
110: assertTrue(expected.equals(actual));
111: }
112:
113: public void testZip() throws Exception {
114: Account subject = getObject("subject");
115: String zip = getObject("zip");
116: String expected = getObject("expected");
117: subject.setZip(zip);
118: String actual = subject.getZip();
119: assertTrue(expected.equals(actual));
120: }
121:
122: public void testCountry() throws Exception {
123: Account subject = getObject("subject");
124: String country = getObject("country");
125: String expected = getObject("expected");
126: subject.setCountry(country);
127: String actual = subject.getCountry();
128: assertTrue(expected.equals(actual));
129: }
130:
131: public void testPhone() throws Exception {
132: Account subject = getObject("subject");
133: String phone = getObject("phone");
134: String expected = getObject("expected");
135: subject.setPhone(phone);
136: String actual = subject.getPhone();
137: assertTrue(expected.equals(actual));
138: }
139:
140: public void testFavouriteCategory() throws Exception {
141: Account subject = getObject("subject");
142: Category favouriteCategory = getObject("favouriteCategory");
143: Category expected = getObject("expected");
144: subject.setFavouriteCategory(favouriteCategory);
145: Category actual = subject.getFavouriteCategory();
146: assertTrue(expected.equals(actual));
147: }
148:
149: public void testLanguagePreference() throws Exception {
150: Account subject = getObject("subject");
151: String languagePreference = getObject("languagePreference");
152: String expected = getObject("expected");
153: subject.setLanguagePreference(languagePreference);
154: String actual = subject.getLanguagePreference();
155: assertTrue(expected.equals(actual));
156: }
157:
158: public void testBannerName() throws Exception {
159: Account subject = getObject("subject");
160: String bannerName = getObject("bannerName");
161: String expected = getObject("expected");
162: subject.setBannerName(bannerName);
163: String actual = subject.getBannerName();
164: assertTrue(expected.equals(actual));
165: }
166:
167: public void testIsListOption() throws Exception {
168: Account subject = getObject("subject");
169: Integer isListOption = getObject("isListOption");
170: Integer expected = getObject("expected");
171: subject.setListOption(isListOption);
172: int actual = subject.isListOption();
173: assertTrue(expected.equals(actual));
174: }
175:
176: public void testIsBannerOption() throws Exception {
177: Account subject = getObject("subject");
178: Integer isBannerOption = getObject("isBannerOption");
179: Integer expected = getObject("expected");
180: subject.setBannerOption(isBannerOption);
181: int actual = subject.isBannerOption();
182: assertTrue(expected.equals(actual));
183: }
184:
185: public void testEqualsSame() throws Exception {
186: Account subject = getObject("subject");
187: Account other = getObject("other");
188: assertTrue(subject == other);
189: assertTrue(subject.equals(other));
190: }
191:
192: public void testEqualsNotSame() throws Exception {
193: Account subject = getObject("subject");
194: Account other = getObject("other");
195: assertFalse(subject == other);
196: assertTrue(subject.equals(other));
197: }
198:
199: public void testEqualsTypeMismatch() throws Exception {
200: Account subject = getObject("subject");
201: Integer other = getObject("other");
202: assertTrue(!subject.equals(other));
203: }
204:
205: public void testCompareToLessThan() throws Exception {
206: Account subject = getObject("subject");
207: Account other = getObject("other");
208: assertTrue(subject.compareTo(other) < 0);
209: }
210:
211: public void testCompareToGreaterThan() throws Exception {
212: Account subject = getObject("subject");
213: Account other = getObject("other");
214: assertTrue(subject.compareTo(other) > 0);
215: }
216:
217: public void testCompareToEquals() throws Exception {
218: Account subject = getObject("subject");
219: Account other = getObject("other");
220: assertTrue(subject.compareTo(other) == 0);
221: }
222:
223: public void testHashCodeSame() throws Exception {
224: Account subject = getObject("subject");
225: Account other = getObject("other");
226: assertTrue(subject.hashCode() == other.hashCode());
227: }
228:
229: public void testHashCodeDifferent() throws Exception {
230: Account subject = getObject("subject");
231: Account other = getObject("other");
232: assertTrue(subject.hashCode() != other.hashCode());
233: }
234:
235: public void testToString() throws Exception {
236: Account subject = getObject("subject");
237: String s = subject.toString();
238: }
239:
240: public SpringUnitContext getAccountTest() {
241: return accountTest;
242: }
243:
244: public void setAccountTest(SpringUnitContext accountTest) {
245: this .accountTest = accountTest;
246: }
247:
248: private SpringUnitContext accountTest;
249:
250: }
|