blob: ba989d56fcbdbdafe9ee19535532e74cec3967b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package com.gitblit.tests;
import org.junit.Test;
import com.gitblit.AvatarGenerator;
import com.gitblit.GravatarGenerator;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.guice.AvatarGeneratorProvider;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.utils.ActivityUtils;
import com.gitblit.utils.XssFilter;
import com.gitblit.utils.XssFilter.AllowXssFilter;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class GravatarTest extends GitblitUnitTest {
public static class AvatarModule extends AbstractModule {
private final IStoredSettings settings;
AvatarModule(IStoredSettings settings) {
this.settings = settings;
}
@Override
protected void configure() {
bind(IStoredSettings.class).toInstance(settings);
bind(XssFilter.class).to(AllowXssFilter.class);
bind(IRuntimeManager.class).to(RuntimeManager.class);
bind(AvatarGenerator.class).toProvider(AvatarGeneratorProvider.class);
}
}
@Test
public void gravatarIdenticonTest() {
IStoredSettings settings = new MemorySettings();
settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
Injector injector = Guice.createInjector(new AvatarModule(settings));
AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
String username = "username";
String emailAddress = "emailAddress";
int width = 10;
String url = avatarGenerator.getURL(username, emailAddress, true, width);
assertNotNull(url);
assertEquals(ActivityUtils.getGravatarIdenticonUrl(emailAddress, width), url);
}
@Test
public void gravatarThumbnailTest() {
IStoredSettings settings = new MemorySettings();
settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
Injector injector = Guice.createInjector(new AvatarModule(settings));
AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
String username = "username";
String emailAddress = "emailAddress";
int width = 10;
String url = avatarGenerator.getURL(username, emailAddress, false, width);
assertNotNull(url);
assertEquals(ActivityUtils.getGravatarThumbnailUrl(emailAddress, width), url);
}
}
|