-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
package com.zegoggles.smssync.mail; | ||
|
||
import com.zegoggles.smssync.preferences.AddressStyle; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
import static com.zegoggles.smssync.preferences.AddressStyle.NAME; | ||
import static com.zegoggles.smssync.preferences.AddressStyle.NAME_AND_NUMBER; | ||
import static com.zegoggles.smssync.preferences.AddressStyle.NUMBER; | ||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class PersonRecordTest { | ||
|
||
@Test public void shouldSanitizeInputData() throws Exception { | ||
@Test public void shouldSanitizeInputDataEmail() throws Exception { | ||
PersonRecord r = new PersonRecord(1, "foo\n\r\n", "foo\n@gmail.com", "\r\r1234"); | ||
|
||
assertThat(r.getEmail()).isEqualTo("[email protected]"); | ||
} | ||
|
||
@Test public void shouldSanitizeInputDataName() throws Exception { | ||
PersonRecord r = new PersonRecord(1, "foo\n\r\n", "foo\n@gmail.com", "\r\r1234"); | ||
assertThat(r.getName()).isEqualTo("foo"); | ||
} | ||
|
||
@Test public void shouldSanitizeInputDataNumber() throws Exception { | ||
PersonRecord r = new PersonRecord(1, "foo\n\r\n", "foo\n@gmail.com", "\r\r1234"); | ||
assertThat(r.getNumber()).isEqualTo("1234"); | ||
} | ||
|
||
|
@@ -38,53 +47,105 @@ public class PersonRecordTest { | |
assertThat(record.getEmail()).isEqualTo("[email protected]"); | ||
} | ||
|
||
@Test public void shouldGetAddress() throws Exception { | ||
// all fields present | ||
|
||
@Test public void shouldGetAddressNameAndNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(NAME_AND_NUMBER).toString()).isEqualTo( | ||
"\"John Appleseed (+141543432)\" <[email protected]>"); | ||
} | ||
|
||
@Test public void shouldGetAddressName() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(AddressStyle.NAME_AND_NUMBER).toString()).isEqualTo( | ||
"\"John Appleseed (+141543432)\" <[email protected]>"); | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME).toString()).isEqualTo( | ||
assertThat(record.getAddress(NAME).toString()).isEqualTo( | ||
"John Appleseed <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NUMBER).toString()).isEqualTo( | ||
@Test public void shouldGetAddressNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(NUMBER).toString()).isEqualTo( | ||
"+141543432 <[email protected]>"); | ||
} | ||
|
||
@Test public void shouldGetAddressMissingEmail() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", null, "+141543432"); | ||
// email missing | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME_AND_NUMBER).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingEmail_NameAndNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", null, "+141543432"); | ||
assertThat(record.getAddress(NAME_AND_NUMBER).toString()).isEqualTo( | ||
"\"John Appleseed (+141543432)\" <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingEmail_Name() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", null, "+141543432"); | ||
assertThat(record.getAddress(NAME).toString()).isEqualTo( | ||
"John Appleseed <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NUMBER).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingEmail_Number() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", null, "+141543432"); | ||
assertThat(record.getAddress(NUMBER).toString()).isEqualTo( | ||
"+141543432 <[email protected]>"); | ||
} | ||
|
||
@Test public void shouldGetAddressMissingName() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, "[email protected]", "+141543432"); | ||
// name is missing | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME_AND_NUMBER).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingName_Name() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(NAME).toString()).isEqualTo( | ||
"+141543432 <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingName_NameAndNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(NAME_AND_NUMBER).toString()).isEqualTo( | ||
"+141543432 <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NUMBER).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingName_Number() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, "[email protected]", "+141543432"); | ||
assertThat(record.getAddress(NUMBER).toString()).isEqualTo( | ||
"+141543432 <[email protected]>"); | ||
} | ||
|
||
@Test public void shouldGetAddressMissingNumber() throws Exception { | ||
// number is missing | ||
|
||
@Test public void shouldGetAddressMissingNumber_Number() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", null); | ||
assertThat(record.getAddress(AddressStyle.NAME_AND_NUMBER).toString()).isEqualTo( | ||
"\"John Appleseed (Unknown)\" <[email protected]>"); | ||
assertThat(record.getAddress(NUMBER).toString()).isEqualTo( | ||
"Unknown <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NAME).toString()).isEqualTo( | ||
@Test public void shouldGetAddressMissingNumber_Name() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", null); | ||
assertThat(record.getAddress(NAME).toString()).isEqualTo( | ||
"John Appleseed <[email protected]>"); | ||
} | ||
|
||
assertThat(record.getAddress(AddressStyle.NUMBER).toString()).isEqualTo( | ||
"Unknown <[email protected]>"); | ||
@Test public void shouldGetAddressMissingNumber_NameAndNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, "John Appleseed", "[email protected]", null); | ||
|
||
assertThat(record.getAddress(NAME_AND_NUMBER).toString()).isEqualTo( | ||
"\"John Appleseed (Unknown)\" <[email protected]>"); | ||
} | ||
|
||
// local part quote (#595) | ||
|
||
@Test public void shouldQuoteLocalPart_NameAndNumber() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, null, "name with space"); | ||
assertThat(record.getAddress(NAME_AND_NUMBER).toString()).isEqualTo( | ||
"name with space <\"name with space\"@unknown.email>"); | ||
} | ||
|
||
@Test public void shouldQuoteLocalPart_Name() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, null, "name with space"); | ||
assertThat(record.getAddress(NAME).toString()).isEqualTo( | ||
"name with space <\"name with space\"@unknown.email>"); | ||
} | ||
|
||
@Test public void shouldQuoteLocalPart_Number() throws Exception { | ||
PersonRecord record = new PersonRecord(1, null, null, "name with space"); | ||
assertThat(record.getAddress(NUMBER).toString()).isEqualTo( | ||
"name with space <\"name with space\"@unknown.email>"); | ||
} | ||
} |