001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.vendor.service;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import org.kuali.core.web.format.FormatException;
021: import org.kuali.kfs.context.KualiTestBase;
022: import org.kuali.kfs.context.SpringContext;
023: import org.kuali.test.ConfigureContext;
024:
025: @ConfigureContext(session=KHUNTLEY)
026: public class PhoneNumberServiceTest extends KualiTestBase {
027:
028: private PhoneNumberService phoneNumberService;
029:
030: private final String phoneGenericFormat1 = "888-888-8888";
031: private final String phoneGenericFormat2 = "(888) 888-8888";
032: private final String phoneGenericFormat3 = "888 888 8888";
033: private final String phoneGenericFaxFormat1 = "888,888-8888";
034:
035: private final String phoneTooLong = "888-888-88888";
036: private final String phoneTooShort = "888-888-888";
037:
038: private final String phoneNonNumeric = "812-3EX-PRES";
039: private final String phoneAllTogether = "8888888888";
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043: phoneNumberService = SpringContext
044: .getBean(PhoneNumberService.class);
045: }
046:
047: protected void tearDown() throws Exception {
048: super .tearDown();
049: }
050:
051: public void testIsValidPhoneNumber_GenericFormat1() {
052: assertTrue(phoneNumberService
053: .isValidPhoneNumber(phoneGenericFormat1));
054: }
055:
056: public void testIsValidPhoneNumber_GenericFormat2() {
057: assertTrue(phoneNumberService
058: .isValidPhoneNumber(phoneGenericFormat2));
059: }
060:
061: public void testIsValidPhoneNumber_GenericFormat3() {
062: assertTrue(phoneNumberService
063: .isValidPhoneNumber(phoneGenericFormat3));
064: }
065:
066: public void testIsValidPhoneNumber_GenericFaxFormat1() {
067: assertFalse(phoneNumberService
068: .isValidPhoneNumber(phoneGenericFaxFormat1));
069: }
070:
071: public void testIsValidPhoneNumber_TooLong() {
072: assertFalse(phoneNumberService.isValidPhoneNumber(phoneTooLong));
073: }
074:
075: public void testIsValidPhoneNumber_TooShort() {
076: assertFalse(phoneNumberService
077: .isValidPhoneNumber(phoneTooShort));
078: }
079:
080: public void testIsValidPhoneNumber_NonNumeric() {
081: assertFalse(phoneNumberService
082: .isValidPhoneNumber(phoneNonNumeric));
083: }
084:
085: public void testIsValidPhoneNumber_AllTogether() {
086: assertFalse(phoneNumberService
087: .isValidPhoneNumber(phoneAllTogether));
088: }
089:
090: public void testIsDefaultFormatPhoneNumber_GenericFormat1() {
091: assertTrue(phoneNumberService
092: .isDefaultFormatPhoneNumber(phoneGenericFormat1));
093: }
094:
095: public void testIsDefaultFormatPhoneNumber_GenericFormat3() {
096: assertFalse(phoneNumberService
097: .isDefaultFormatPhoneNumber(phoneGenericFormat3));
098: }
099:
100: public void testFormatToDefaultGeneric_GenericFormat1() {
101: assertEquals(phoneGenericFormat1, phoneNumberService
102: .formatNumberIfPossible(phoneGenericFormat1));
103: }
104:
105: public void testFormatToDefaultGeneric_GenericFormat2() {
106: assertEquals(phoneGenericFormat1, phoneNumberService
107: .formatNumberIfPossible(phoneGenericFormat2));
108: }
109:
110: public void testFormatToDefaultGeneric_GenericFormat3() {
111: assertEquals(phoneGenericFormat1, phoneNumberService
112: .formatNumberIfPossible(phoneGenericFormat3));
113: }
114:
115: public void testFormatToDefaultGeneric_GenericFaxFormat1() {
116: assertEquals(phoneGenericFormat1, phoneNumberService
117: .formatNumberIfPossible(phoneGenericFaxFormat1));
118: }
119:
120: public void testFormatToDefaultGeneric_phoneTooShort() {
121: boolean b = true;
122: try {
123: b = phoneGenericFormat1.equals(phoneNumberService
124: .formatNumberIfPossible(phoneTooShort));
125: } catch (FormatException fe) {
126: if (fe.getMessage().indexOf("fewer than") > 0) {
127: b = false;
128: }
129: } finally {
130: assertEquals(b, false);
131: }
132: }
133:
134: public void testFormatToDefaultGeneric_phoneTooLong() {
135: boolean b = true;
136: try {
137: b = phoneGenericFormat1.equals(phoneNumberService
138: .formatNumberIfPossible(phoneTooLong));
139: } catch (FormatException fe) {
140: if (fe.getMessage().indexOf("more than") > 0) {
141: b = false;
142: }
143: } finally {
144: assertEquals(b, false);
145: }
146: }
147:
148: public void testFormatToDefaultGeneric_phoneNonNumeric() {
149: boolean b = true;
150: try {
151: b = phoneNumberService
152: .isDefaultFormatPhoneNumber(phoneNumberService
153: .formatNumberIfPossible(phoneNonNumeric));
154: } catch (FormatException fe) {
155: if (fe.getMessage().indexOf("fewer than") > 0) {
156: b = false;
157: }
158: } finally {
159: assertEquals(b, false);
160: }
161: }
162: }
|