EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.sync.test.util]

COVERAGE SUMMARY FOR SOURCE FILE [AccountHolder.java]

nameclass, %method, %block, %line, %
AccountHolder.java67%  (2/3)50%  (13/26)48%  (128/266)50%  (26.3/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountHolder100% (1/1)47%  (8/17)38%  (72/190)43%  (14.3/33)
copy (): AccountHolder$Builder 0%   (0/1)0%   (0/17)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/16)0%   (0/1)
getPassword (): String 0%   (0/1)0%   (0/3)0%   (0/1)
removeAuthToken (String): boolean 0%   (0/1)0%   (0/36)0%   (0/9)
withAlwaysAccept (boolean): AccountHolder 0%   (0/1)0%   (0/6)0%   (0/1)
withAuthToken (String, String): AccountHolder 0%   (0/1)0%   (0/7)0%   (0/1)
withAuthTokens (Map): AccountHolder 0%   (0/1)0%   (0/6)0%   (0/1)
withHasBeenAccepted (String, boolean): AccountHolder 0%   (0/1)0%   (0/7)0%   (0/1)
withPassword (String): AccountHolder 0%   (0/1)0%   (0/6)0%   (0/1)
AccountHolder (Account, String, Map, Map, boolean): void 100% (1/1)65%  (24/37)82%  (7.4/9)
hasBeenAccepted (String): boolean 100% (1/1)95%  (18/19)94%  (0.9/1)
AccountHolder (Account, String, Map, Map, boolean, AccountHolder$1): void 100% (1/1)100% (8/8)100% (1/1)
create (): AccountHolder$Builder 100% (1/1)100% (4/4)100% (1/1)
getAccount (): Account 100% (1/1)100% (3/3)100% (1/1)
getAuthToken (String): String 100% (1/1)100% (6/6)100% (1/1)
hasAuthTokenRegistered (String): boolean 100% (1/1)100% (5/5)100% (1/1)
hashCode (): int 100% (1/1)100% (4/4)100% (1/1)
     
class AccountHolder$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class AccountHolder$Builder100% (1/1)56%  (5/9)74%  (56/76)60%  (12/20)
alwaysAccept (boolean): AccountHolder$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
authTokens (Map): AccountHolder$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
hasBeenAcceptedMap (Map): AccountHolder$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
password (String): AccountHolder$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
AccountHolder$Builder (): void 100% (1/1)100% (3/3)100% (1/1)
account (Account): AccountHolder$Builder 100% (1/1)100% (5/5)100% (2/2)
authToken (String, String): AccountHolder$Builder 100% (1/1)100% (16/16)100% (4/4)
build (): AccountHolder 100% (1/1)100% (15/15)100% (1/1)
hasBeenAccepted (String, boolean): AccountHolder$Builder 100% (1/1)100% (17/17)100% (4/4)

1// Copyright 2013 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 
5package org.chromium.sync.test.util;
6 
7import android.accounts.Account;
8 
9import java.util.HashMap;
10import java.util.Map;
11 
12/**
13 * This class is used by the {@link MockAccountManager} to hold information about a given
14 * account, such as its password and set of granted auth tokens.
15 */
16public class AccountHolder {
17 
18    private final Account mAccount;
19 
20    private final String mPassword;
21 
22    private final Map<String, String> mAuthTokens;
23 
24    private final Map<String, Boolean> mHasBeenAccepted;
25 
26    private final boolean mAlwaysAccept;
27 
28    private AccountHolder(Account account, String password, Map<String, String> authTokens,
29            Map<String, Boolean> hasBeenAccepted, boolean alwaysAccept) {
30        mAlwaysAccept = alwaysAccept;
31        if (account == null) {
32            throw new IllegalArgumentException("Account can not be null");
33        }
34        mAccount = account;
35        mPassword = password;
36        mAuthTokens = authTokens == null ? new HashMap<String, String>() : authTokens;
37        mHasBeenAccepted = hasBeenAccepted == null ?
38                new HashMap<String, Boolean>() : hasBeenAccepted;
39    }
40 
41    public Account getAccount() {
42        return mAccount;
43    }
44 
45    public String getPassword() {
46        return mPassword;
47    }
48 
49    public boolean hasAuthTokenRegistered(String authTokenType) {
50        return mAuthTokens.containsKey(authTokenType);
51    }
52 
53    public String getAuthToken(String authTokenType) {
54        return mAuthTokens.get(authTokenType);
55    }
56 
57    public boolean hasBeenAccepted(String authTokenType) {
58        return mAlwaysAccept ||
59                mHasBeenAccepted.containsKey(authTokenType) && mHasBeenAccepted.get(authTokenType);
60    }
61 
62    /**
63     * Removes an auth token from the auth token map.
64     *
65     * @param authToken the auth token to remove
66     * @return true if the auth token was found
67     */
68    public boolean removeAuthToken(String authToken) {
69        String foundKey = null;
70        for (Map.Entry<String, String> tokenEntry : mAuthTokens.entrySet()) {
71            if (authToken.equals(tokenEntry.getValue())) {
72                foundKey = tokenEntry.getKey();
73                break;
74            }
75        }
76        if (foundKey == null) {
77            return false;
78        } else {
79            mAuthTokens.remove(foundKey);
80            return true;
81        }
82    }
83 
84    @Override
85    public int hashCode() {
86        return mAccount.hashCode();
87    }
88 
89    @Override
90    public boolean equals(Object that) {
91        return that != null && that instanceof AccountHolder && mAccount
92                .equals(((AccountHolder) that).getAccount());
93    }
94 
95    public static Builder create() {
96        return new Builder();
97    }
98 
99    public AccountHolder withPassword(String password) {
100        return copy().password(password).build();
101    }
102 
103    public AccountHolder withAuthTokens(Map<String, String> authTokens) {
104        return copy().authTokens(authTokens).build();
105    }
106 
107    public AccountHolder withAuthToken(String authTokenType, String authToken) {
108        return copy().authToken(authTokenType, authToken).build();
109    }
110 
111    public AccountHolder withHasBeenAccepted(String authTokenType, boolean hasBeenAccepted) {
112        return copy().hasBeenAccepted(authTokenType, hasBeenAccepted).build();
113    }
114 
115    public AccountHolder withAlwaysAccept(boolean alwaysAccept) {
116        return copy().alwaysAccept(alwaysAccept).build();
117    }
118 
119    private Builder copy() {
120        return create().account(mAccount).password(mPassword).authTokens(mAuthTokens).
121                hasBeenAcceptedMap(mHasBeenAccepted).alwaysAccept(mAlwaysAccept);
122    }
123 
124    public static class Builder {
125 
126        private Account mTempAccount;
127 
128        private String mTempPassword;
129 
130        private Map<String, String> mTempAuthTokens;
131 
132        private Map<String, Boolean> mTempHasBeenAccepted;
133 
134        private boolean mTempAlwaysAccept;
135 
136        public Builder account(Account account) {
137            mTempAccount = account;
138            return this;
139        }
140 
141        public Builder password(String password) {
142            mTempPassword = password;
143            return this;
144        }
145 
146        public Builder authToken(String authTokenType, String authToken) {
147            if (mTempAuthTokens == null) {
148                mTempAuthTokens = new HashMap<String, String>();
149            }
150            mTempAuthTokens.put(authTokenType, authToken);
151            return this;
152        }
153 
154        public Builder authTokens(Map<String, String> authTokens) {
155            mTempAuthTokens = authTokens;
156            return this;
157        }
158 
159        public Builder hasBeenAccepted(String authTokenType, boolean hasBeenAccepted) {
160            if (mTempHasBeenAccepted == null) {
161                mTempHasBeenAccepted = new HashMap<String, Boolean>();
162            }
163            mTempHasBeenAccepted.put(authTokenType, hasBeenAccepted);
164            return this;
165        }
166 
167        public Builder hasBeenAcceptedMap(Map<String, Boolean> hasBeenAcceptedMap) {
168            mTempHasBeenAccepted = hasBeenAcceptedMap;
169            return this;
170        }
171 
172        public Builder alwaysAccept(boolean alwaysAccept) {
173            mTempAlwaysAccept = alwaysAccept;
174            return this;
175        }
176 
177        public AccountHolder build() {
178            return new AccountHolder(mTempAccount, mTempPassword, mTempAuthTokens,
179                    mTempHasBeenAccepted, mTempAlwaysAccept);
180        }
181    }
182 
183}

[all classes][org.chromium.sync.test.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov