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; | 7 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
8 | 8 |
9 import org.junit.Assert; | 9 import org.junit.Assert; |
10 import org.junit.Test; | 10 import org.junit.Test; |
11 import org.junit.runner.RunWith; | 11 import org.junit.runner.RunWith; |
12 import org.junit.runners.Parameterized; | 12 import org.junit.runners.Parameterized; |
13 import org.junit.runners.Parameterized.Parameters; | 13 import org.junit.runners.Parameterized.Parameters; |
14 | 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 AutofillPayerInfo class. |
20 */ | 20 */ |
21 @RunWith(Parameterized.class) | 21 @RunWith(Parameterized.class) |
22 public class AutofillContactTest { | 22 public class AutofillPayerInfoTest { |
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 {"555-5555", "j@d.co", true, "555-5555", "j@d.co", "j@d.co", "555-55
55"}, |
27 {null, "j@d.co", true, "j@d.co", null, "j@d.co", null}, | 27 {null, "j@d.co", true, "j@d.co", null, "j@d.co", null}, |
28 {"", "j@d.co", true, "j@d.co", null, "j@d.co", null}, | 28 {"", "j@d.co", true, "j@d.co", null, "j@d.co", null}, |
29 {"555-5555", null, true, "555-5555", null, null, "555-5555"}, | 29 {"555-5555", null, true, "555-5555", null, null, "555-5555"}, |
30 {"555-5555", "", false, "555-5555", null, null, "555-5555"}, | 30 {"555-5555", "", false, "555-5555", null, null, "555-5555"}, |
31 }); | 31 }); |
32 } | 32 } |
33 | 33 |
34 private final String mPayerPhone; | 34 private final String mPayerPhone; |
35 private final String mPayerEmail; | 35 private final String mPayerEmail; |
36 private final boolean mIsComplete; | 36 private final boolean mIsComplete; |
37 private final String mExpectedLabel; | 37 private final String mExpectedLabel; |
38 private final String mExpectedSublabel; | 38 private final String mExpectedSublabel; |
39 private final String mExpectedPayerEmail; | 39 private final String mExpectedPayerEmail; |
40 private final String mExpectedPayerPhone; | 40 private final String mExpectedPayerPhone; |
41 | 41 |
42 public AutofillContactTest(String payerPhone, String payerEmail, boolean isC
omplete, | 42 public AutofillPayerInfoTest(String payerPhone, String payerEmail, boolean i
sComplete, |
43 String expectedLabel, String expectedSublabel, String expectedPayerE
mail, | 43 String expectedLabel, String expectedSublabel, String expectedPayerE
mail, |
44 String expectedPayerPhone) { | 44 String expectedPayerPhone) { |
45 mPayerPhone = payerPhone; | 45 mPayerPhone = payerPhone; |
46 mPayerEmail = payerEmail; | 46 mPayerEmail = payerEmail; |
47 mIsComplete = isComplete; | 47 mIsComplete = isComplete; |
48 mExpectedLabel = expectedLabel; | 48 mExpectedLabel = expectedLabel; |
49 mExpectedSublabel = expectedSublabel; | 49 mExpectedSublabel = expectedSublabel; |
50 mExpectedPayerEmail = expectedPayerEmail; | 50 mExpectedPayerEmail = expectedPayerEmail; |
51 mExpectedPayerPhone = expectedPayerPhone; | 51 mExpectedPayerPhone = expectedPayerPhone; |
52 } | 52 } |
53 | 53 |
54 @Test | 54 @Test |
55 public void test() { | 55 public void test() { |
56 AutofillProfile profile = new AutofillProfile(); | 56 AutofillProfile profile = new AutofillProfile(); |
57 AutofillContact contact = | 57 AutofillPayerInfo payerInfo = |
58 new AutofillContact(profile, mPayerPhone, mPayerEmail, mIsComple
te); | 58 new AutofillPayerInfo(profile, mPayerPhone, mPayerEmail, mIsComp
lete); |
59 | 59 |
60 Assert.assertEquals( | 60 Assert.assertEquals( |
61 mIsComplete ? "Contact should be complete" : "Contact should be
incomplete", | 61 mIsComplete ? "Payer info should be complete" : "Payer info shou
ld be incomplete", |
62 mIsComplete, contact.isComplete()); | 62 mIsComplete, payerInfo.isComplete()); |
63 Assert.assertEquals("Contact's profile should be the same as passed into
the constructor", | 63 Assert.assertEquals("PayerInfo's profile should be the same as passed in
to the constructor", |
64 profile, contact.getProfile()); | 64 profile, payerInfo.getProfile()); |
65 assertIdPhoneEmailLabelSublabel(profile.getGUID(), mExpectedPayerPhone,
mExpectedPayerEmail, | 65 assertIdPhoneEmailLabelSublabel(profile.getGUID(), mExpectedPayerPhone,
mExpectedPayerEmail, |
66 mExpectedLabel, mExpectedSublabel, contact); | 66 mExpectedLabel, mExpectedSublabel, payerInfo); |
67 | 67 |
68 contact.completeContact("some-guid-here", "999-9999", "a@b.com"); | 68 payerInfo.completePayerInfo("some-guid-here", "999-9999", "a@b.com"); |
69 Assert.assertTrue("Contact should be complete", contact.isComplete()); | 69 Assert.assertTrue("Payer info should be complete", payerInfo.isComplete(
)); |
70 assertIdPhoneEmailLabelSublabel("some-guid-here", "999-9999", "a@b.com",
"999-9999", | 70 assertIdPhoneEmailLabelSublabel("some-guid-here", "999-9999", "a@b.com",
"999-9999", |
71 "a@b.com", contact); | 71 "a@b.com", payerInfo); |
72 } | 72 } |
73 | 73 |
74 private void assertIdPhoneEmailLabelSublabel(String id, String expectedPhone
, | 74 private void assertIdPhoneEmailLabelSublabel(String id, String expectedPhone
, |
75 String expectedEmail, String expectedLabel, String expectedSublabel, | 75 String expectedEmail, String expectedLabel, String expectedSublabel, |
76 AutofillContact actual) { | 76 AutofillPayerInfo actual) { |
77 Assert.assertEquals("Identifier should be " + id, id, actual.getIdentifi
er()); | 77 Assert.assertEquals("Identifier should be " + id, id, actual.getIdentifi
er()); |
78 Assert.assertEquals( | 78 Assert.assertEquals( |
79 "Phone should be " + expectedPhone, expectedPhone, actual.getPay
erPhone()); | 79 "Phone should be " + expectedPhone, expectedPhone, actual.getPay
erPhone()); |
80 Assert.assertEquals( | 80 Assert.assertEquals( |
81 "Email should be " + expectedEmail, expectedEmail, actual.getPay
erEmail()); | 81 "Email should be " + expectedEmail, expectedEmail, actual.getPay
erEmail()); |
82 Assert.assertEquals("Label should be " + expectedLabel, expectedLabel, a
ctual.getLabel()); | 82 Assert.assertEquals("Label should be " + expectedLabel, expectedLabel, a
ctual.getLabel()); |
83 Assert.assertEquals( | 83 Assert.assertEquals( |
84 "Sublabel should be " + expectedSublabel, expectedSublabel, actu
al.getSublabel()); | 84 "Sublabel should be " + expectedSublabel, expectedSublabel, actu
al.getSublabel()); |
85 } | 85 } |
86 } | 86 } |
OLD | NEW |