| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.zipcodewilmington;
-
- import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
- import com.zipcodewilmington.phone.PhoneNumber;
- import com.zipcodewilmington.phone.PhoneNumberFactory;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
-
- import java.util.logging.Level;
- import java.util.logging.Logger;
-
- /**
- * Created by leon on 5/9/17.
- */
- public class PhoneNumberFactoryTest {
-
- @Test(expected = InvalidPhoneNumberFormatException.class)
- public void testInvalidPhoneNumberFormatException() throws InvalidPhoneNumberFormatException {
- PhoneNumberFactory.createPhoneNumber("-1");
- }
-
- @Test
- public void testCreatePhoneNumberSafely() throws InvalidPhoneNumberFormatException {
- // : Given
- int areaCode = 0;
- int centralOfficeCode = 0;
- int phoneLineCode = 0;
-
- // : When
- PhoneNumber phoneNumber = null;
- phoneNumber = PhoneNumberFactory.createPhoneNumberSafely(areaCode, centralOfficeCode, phoneLineCode);
-
- // : Then
- Assert.assertEquals(null, phoneNumber);
- }
-
- @Test
- public void testGetAreaCode() throws InvalidPhoneNumberFormatException {
- // : Given
- Integer areaCode = 302;
- int centralOfficeCode = 312;
- int phoneLineCode = 5555;
-
- // : When
- PhoneNumber phoneNumber = null;
- phoneNumber = PhoneNumberFactory.createPhoneNumberSafely(areaCode, centralOfficeCode, phoneLineCode);
-
- // : Then
- Assert.assertEquals(phoneNumber.getAreaCode(), areaCode.toString());
- }
-
- @Test
- public void testGetCentralOfficeCode() throws InvalidPhoneNumberFormatException {
- // : Given
- int areaCode = 302;
- Integer centralOfficeCode = 312;
- int phoneLineCode = 5555;
-
- // : When
- PhoneNumber phoneNumber = null;
- phoneNumber = PhoneNumberFactory.createPhoneNumberSafely(areaCode, centralOfficeCode, phoneLineCode);
-
- // : Then
- Assert.assertEquals(phoneNumber.getCentralOfficeCode(), centralOfficeCode.toString());
- }
-
-
- @Test
- public void testPhoneLineCode() throws InvalidPhoneNumberFormatException {
- // : Given
- int areaCode = 302;
- int centralOfficeCode = 312;
- Integer phoneLineCode = 5555;
-
- // : When
- PhoneNumber phoneNumber = null;
- phoneNumber = PhoneNumberFactory.createPhoneNumberSafely(areaCode, centralOfficeCode, phoneLineCode);
-
- // : Then
- Assert.assertEquals(phoneNumber.getPhoneLineCode(), phoneLineCode.toString());
- }
-
- @Test
- public void testCreateRandomPhoneNumber() throws InvalidPhoneNumberFormatException {
- for (int i = 0; i < 999; i++) {
- // : Given
- // : When
- PhoneNumber phoneNumber = null;
- phoneNumber = PhoneNumberFactory.createRandomPhoneNumber();
-
- // : Then
- Assert.assertTrue(phoneNumber != null);
- }
- }
- }
|