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