OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
6 | 6 |
7 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | |
8 | |
9 import org.junit.Assert; | 7 import org.junit.Assert; |
10 import org.junit.Test; | 8 import org.junit.Test; |
11 import org.junit.runner.RunWith; | 9 import org.junit.runner.RunWith; |
12 import org.junit.runners.Parameterized; | 10 import org.junit.runners.Parameterized; |
13 import org.junit.runners.Parameterized.Parameters; | 11 import org.junit.runners.Parameterized.Parameters; |
14 | 12 |
| 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 14 |
15 import java.util.Arrays; | 15 import java.util.Arrays; |
16 import java.util.Collection; | 16 import java.util.Collection; |
17 | 17 |
18 /** | 18 /** |
19 * Unit tests for the AutofillContact class. | 19 * Unit tests for the AutofillContact class. |
20 */ | 20 */ |
21 @RunWith(Parameterized.class) | 21 @RunWith(Parameterized.class) |
22 public class AutofillContactTest { | 22 public class AutofillContactTest { |
23 @Parameters | 23 @Parameters |
24 public static Collection<Object[]> data() { | 24 public static Collection<Object[]> data() { |
25 return Arrays.asList(new Object[][] { | 25 return Arrays.asList(new Object[][] { |
26 {"555-5555", "j@d.co", true, "555-5555", "j@d.co", "j@d.co", "555-55
55"}, | 26 {"Jon Doe", "555-5555", "j@d.co", true, |
27 {null, "j@d.co", true, "j@d.co", null, "j@d.co", null}, | 27 "Jon Doe", "555-5555", "j@d.co", |
28 {"", "j@d.co", true, "j@d.co", null, "j@d.co", null}, | 28 "Jon Doe", "555-5555", "j@d.co"}, |
29 {"555-5555", null, true, "555-5555", null, null, "555-5555"}, | 29 {null, "555-5555", "j@d.co", true, |
30 {"555-5555", "", false, "555-5555", null, null, "555-5555"}, | 30 "555-5555", "j@d.co", null, |
| 31 null, "555-5555", "j@d.co"}, |
| 32 {"", "555-5555", "j@d.co", true, |
| 33 "555-5555", "j@d.co", null, |
| 34 null, "555-5555", "j@d.co"}, |
| 35 {"Jon Doe", null, "j@d.co", true, |
| 36 "Jon Doe", "j@d.co", null, |
| 37 "Jon Doe", null, "j@d.co"}, |
| 38 {"Jon Doe", "", "j@d.co", true, |
| 39 "Jon Doe", "j@d.co", null, |
| 40 "Jon Doe", null, "j@d.co"}, |
| 41 {"Jon Doe", "555-5555", null, true, |
| 42 "Jon Doe", "555-5555", null, |
| 43 "Jon Doe", "555-5555", null}, |
| 44 {"Jon Doe", "555-5555", "", true, |
| 45 "Jon Doe", "555-5555", null, |
| 46 "Jon Doe", "555-5555", null}, |
| 47 {null, "555-5555", null, true, |
| 48 "555-5555", null, null, |
| 49 null, "555-5555", null}, |
| 50 {"", "555-5555", "", true, |
| 51 "555-5555", null, null, |
| 52 null, "555-5555", null}, |
| 53 {null, null, "j@d.co", true, |
| 54 "j@d.co", null, null, |
| 55 null, null, "j@d.co"}, |
| 56 {"", "", "j@d.co", true, |
| 57 "j@d.co", null, null, |
| 58 null, null, "j@d.co"}, |
| 59 {"", "555-5555", "", false, |
| 60 "555-5555", null, null, |
| 61 null, "555-5555", null} |
31 }); | 62 }); |
32 } | 63 } |
33 | 64 |
| 65 private final String mPayerName; |
34 private final String mPayerPhone; | 66 private final String mPayerPhone; |
35 private final String mPayerEmail; | 67 private final String mPayerEmail; |
36 private final boolean mIsComplete; | 68 private final boolean mIsComplete; |
37 private final String mExpectedLabel; | 69 private final String mExpectedLabel; |
38 private final String mExpectedSublabel; | 70 private final String mExpectedSublabel; |
| 71 private final String mExpectedTertiaryLabel; |
| 72 private final String mExpectedPayerName; |
39 private final String mExpectedPayerEmail; | 73 private final String mExpectedPayerEmail; |
40 private final String mExpectedPayerPhone; | 74 private final String mExpectedPayerPhone; |
41 | 75 |
42 public AutofillContactTest(String payerPhone, String payerEmail, boolean isC
omplete, | 76 public AutofillContactTest(String payerName, String payerPhone, String payer
Email, |
43 String expectedLabel, String expectedSublabel, String expectedPayerE
mail, | 77 boolean isComplete, String expectedLabel, String expectedSublabel, |
44 String expectedPayerPhone) { | 78 String expectedTertiaryLabel, String expectedPayerName, String expec
tedPayerPhone, |
| 79 String expectedPayerEmail) { |
| 80 mPayerName = payerName; |
45 mPayerPhone = payerPhone; | 81 mPayerPhone = payerPhone; |
46 mPayerEmail = payerEmail; | 82 mPayerEmail = payerEmail; |
47 mIsComplete = isComplete; | 83 mIsComplete = isComplete; |
48 mExpectedLabel = expectedLabel; | 84 mExpectedLabel = expectedLabel; |
49 mExpectedSublabel = expectedSublabel; | 85 mExpectedSublabel = expectedSublabel; |
| 86 mExpectedTertiaryLabel = expectedTertiaryLabel; |
| 87 mExpectedPayerName = expectedPayerName; |
| 88 mExpectedPayerPhone = expectedPayerPhone; |
50 mExpectedPayerEmail = expectedPayerEmail; | 89 mExpectedPayerEmail = expectedPayerEmail; |
51 mExpectedPayerPhone = expectedPayerPhone; | |
52 } | 90 } |
53 | 91 |
54 @Test | 92 @Test |
55 public void test() { | 93 public void test() { |
56 AutofillProfile profile = new AutofillProfile(); | 94 AutofillProfile profile = new AutofillProfile(); |
57 AutofillContact contact = | 95 AutofillContact contact = |
58 new AutofillContact(profile, mPayerPhone, mPayerEmail, mIsComple
te); | 96 new AutofillContact(profile, mPayerName, mPayerPhone, mPayerEmai
l, mIsComplete); |
59 | 97 |
60 Assert.assertEquals( | 98 Assert.assertEquals( |
61 mIsComplete ? "Contact should be complete" : "Contact should be
incomplete", | 99 mIsComplete ? "Contact should be complete" : "Contact should be
incomplete", |
62 mIsComplete, contact.isComplete()); | 100 mIsComplete, contact.isComplete()); |
63 Assert.assertEquals("Contact's profile should be the same as passed into
the constructor", | 101 Assert.assertEquals("Contact's profile should be the same as passed into
the constructor", |
64 profile, contact.getProfile()); | 102 profile, contact.getProfile()); |
65 assertIdPhoneEmailLabelSublabel(profile.getGUID(), mExpectedPayerPhone,
mExpectedPayerEmail, | 103 assertContact(profile.getGUID(), mExpectedPayerName, mExpectedPayerPhone
, |
66 mExpectedLabel, mExpectedSublabel, contact); | 104 mExpectedPayerEmail, mExpectedLabel, mExpectedSublabel, mExpecte
dTertiaryLabel, |
| 105 contact); |
67 | 106 |
68 contact.completeContact("some-guid-here", "999-9999", "a@b.com"); | 107 contact.completeContact("some-guid-here", "Jon Doe", "999-9999", "a@b.co
m"); |
69 Assert.assertTrue("Contact should be complete", contact.isComplete()); | 108 Assert.assertTrue("Contact should be complete", contact.isComplete()); |
70 assertIdPhoneEmailLabelSublabel("some-guid-here", "999-9999", "a@b.com",
"999-9999", | 109 assertContact("some-guid-here", "Jon Doe", "999-9999", "a@b.com", |
71 "a@b.com", contact); | 110 "Jon Doe", "999-9999", "a@b.com", contact); |
72 } | 111 } |
73 | 112 |
74 private void assertIdPhoneEmailLabelSublabel(String id, String expectedPhone
, | 113 private void assertContact(String id, String expectedName, String expectedPh
one, |
75 String expectedEmail, String expectedLabel, String expectedSublabel, | 114 String expectedEmail, String expectedLabel, String expectedSublabel, |
76 AutofillContact actual) { | 115 String expectedTertiaryLabel, AutofillContact actual) { |
77 Assert.assertEquals("Identifier should be " + id, id, actual.getIdentifi
er()); | 116 Assert.assertEquals("Identifier should be " + id, id, actual.getIdentifi
er()); |
| 117 Assert.assertEquals("Name should be " + expectedName, expectedName, actu
al.getPayerName()); |
78 Assert.assertEquals( | 118 Assert.assertEquals( |
79 "Phone should be " + expectedPhone, expectedPhone, actual.getPay
erPhone()); | 119 "Phone should be " + expectedPhone, expectedPhone, actual.getPay
erPhone()); |
80 Assert.assertEquals( | 120 Assert.assertEquals( |
81 "Email should be " + expectedEmail, expectedEmail, actual.getPay
erEmail()); | 121 "Email should be " + expectedEmail, expectedEmail, actual.getPay
erEmail()); |
82 Assert.assertEquals("Label should be " + expectedLabel, expectedLabel, a
ctual.getLabel()); | 122 Assert.assertEquals("Label should be " + expectedLabel, expectedLabel, a
ctual.getLabel()); |
83 Assert.assertEquals( | 123 Assert.assertEquals( |
84 "Sublabel should be " + expectedSublabel, expectedSublabel, actu
al.getSublabel()); | 124 "Sublabel should be " + expectedSublabel, expectedSublabel, actu
al.getSublabel()); |
| 125 Assert.assertEquals("TertiaryLabel should be " + expectedTertiaryLabel, |
| 126 expectedTertiaryLabel, actual.getTertiaryLabel()); |
85 } | 127 } |
86 } | 128 } |
OLD | NEW |