Skip to content

Commit 690b964

Browse files
authored
Fix user profile picture URL (#3571)
1 parent d120329 commit 690b964

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

plugins/com.google.cloud.tools.eclipse.login.test/src/com/google/cloud/tools/eclipse/login/ui/AccountsPanelTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,34 @@
1717
package com.google.cloud.tools.eclipse.login.ui;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertThat;
2021
import static org.junit.Assert.assertTrue;
22+
import static org.mockito.Matchers.any;
23+
import static org.mockito.Mockito.verify;
2124
import static org.mockito.Mockito.when;
2225

2326
import com.google.cloud.tools.eclipse.login.IGoogleLoginService;
2427
import com.google.cloud.tools.eclipse.test.util.ui.ShellTestResource;
2528
import com.google.cloud.tools.login.Account;
29+
import java.net.MalformedURLException;
2630
import java.util.ArrayList;
2731
import java.util.Arrays;
2832
import java.util.HashSet;
2933
import java.util.List;
34+
import java.util.regex.Matcher;
35+
import java.util.regex.Pattern;
3036
import org.eclipse.swt.SWT;
3137
import org.eclipse.swt.widgets.Button;
3238
import org.eclipse.swt.widgets.Composite;
3339
import org.eclipse.swt.widgets.Control;
3440
import org.eclipse.swt.widgets.Label;
3541
import org.eclipse.swt.widgets.Shell;
42+
import org.hamcrest.Matchers;
3643
import org.junit.Before;
3744
import org.junit.Rule;
3845
import org.junit.Test;
3946
import org.junit.runner.RunWith;
47+
import org.mockito.ArgumentCaptor;
4048
import org.mockito.Mock;
4149
import org.mockito.runners.MockitoJUnitRunner;
4250

@@ -61,6 +69,7 @@ public void setUp() {
6169
when(account1.getName()).thenReturn("Alice");
6270
when(account2.getName()).thenReturn(null);
6371
when(account3.getName()).thenReturn("Charlie");
72+
when(account1.getAvatarUrl()).thenReturn("https://avatar.url/account1");
6473
}
6574

6675
@Test
@@ -125,6 +134,23 @@ public void testAccountsArea_accountWithNullName() {
125134
assertTrue(namesEmails.names.get(0).isEmpty());
126135
}
127136

137+
@Test
138+
public void testAccountsArea_avatarImageUrl() throws MalformedURLException {
139+
setUpLoginService(Arrays.asList(account1));
140+
141+
AccountsPanel panel = new AccountsPanel(null, loginService, imageLoader);
142+
panel.createDialogArea(shell);
143+
144+
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
145+
verify(imageLoader).loadImage(captor.capture(), any());
146+
assertEquals(1, captor.getAllValues().size());
147+
148+
Pattern urlPattern = Pattern.compile("^https://avatar.url/account1=s([0-9]+)$");
149+
Matcher matcher = urlPattern.matcher(captor.getValue());
150+
assertTrue(matcher.find());
151+
assertThat(Integer.valueOf(matcher.group(1)), Matchers.greaterThan(0));
152+
}
153+
128154
@Test
129155
public void testAccountsArea_threeAccounts() {
130156
setUpLoginService(Arrays.asList(account1, account2, account3));

plugins/com.google.cloud.tools.eclipse.login/src/com/google/cloud/tools/eclipse/login/ui/AccountsPanel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public AccountsPanel(Shell parent, IGoogleLoginService loginService) {
6666
this.imageLoader = imageLoader;
6767
}
6868

69-
7069
@Override
7170
protected Color getBackground() {
7271
return getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
@@ -113,7 +112,7 @@ void createAccountsPane(Composite accountArea) {
113112

114113
if (account.getAvatarUrl() != null) {
115114
try {
116-
imageLoader.loadImage(account.getAvatarUrl() + "?sz=" + avatarSize, avatar);
115+
imageLoader.loadImage(account.getAvatarUrl() + "=s" + avatarSize, avatar);
117116
} catch (MalformedURLException ex) {
118117
logger.log(Level.WARNING, "malformed avatar image URL", ex);
119118
}

plugins/com.google.cloud.tools.eclipse.login/src/com/google/cloud/tools/eclipse/login/ui/LabelImageLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public class LabelImageLoader {
4242
*
4343
* Must be called in the UI context.
4444
*/
45-
void loadImage(String imageUrl, Label label) throws MalformedURLException {
45+
@VisibleForTesting
46+
public void loadImage(String imageUrl, Label label) throws MalformedURLException {
4647
Preconditions.checkNotNull(imageUrl);
4748

4849
ImageData imageData = cache.get(imageUrl);

0 commit comments

Comments
 (0)