diff --git a/src/test/scala/view/AvatarImageProviderSpec.scala b/src/test/scala/view/AvatarImageProviderSpec.scala
new file mode 100644
index 0000000..5ba1a09
--- /dev/null
+++ b/src/test/scala/view/AvatarImageProviderSpec.scala
@@ -0,0 +1,101 @@
+package view
+
+import java.util.Date
+
+import org.specs2.mutable._
+import service.RequestCache
+import model.Account
+import service.SystemSettingsService.SystemSettings
+import twirl.api.Html
+
+class AvatarImageProviderSpec extends Specification {
+
+ implicit val context = app.Context("", None, "", null)
+
+ "getAvatarImageHtml" should {
+ "show Gravatar image for no image account if gravatar integration is enabled" in {
+ val provider = new AvatarImageProviderImpl(Some(createAccount(None)), createSystemSettings(true))
+
+ provider.toHtml("user", 20).toString mustEqual
+ "
"
+ }
+
+ "show uploaded image even if gravatar integration is enabled" in {
+ val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))), createSystemSettings(true))
+
+ provider.toHtml("user", 20).toString mustEqual
+ "
"
+ }
+
+ "show local image for no image account if gravatar integration is disabled" in {
+ val provider = new AvatarImageProviderImpl(Some(createAccount(None)), createSystemSettings(false))
+
+ provider.toHtml("user", 20).toString mustEqual
+ "
"
+ }
+
+ "show Gravatar image for specified mail address if gravatar integration is enabled" in {
+ val provider = new AvatarImageProviderImpl(None, createSystemSettings(true))
+
+ provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
+ "
"
+ }
+
+ "show local image for unknown user if gravatar integration is enabled" in {
+ val provider = new AvatarImageProviderImpl(None, createSystemSettings(true))
+
+ provider.toHtml("user", 20).toString mustEqual
+ "
"
+ }
+
+ "show local image for specified mail address if gravatar integration is disabled" in {
+ val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
+
+ provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
+ "
"
+ }
+
+ "add tooltip if it's enabled" in {
+ val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
+
+ provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
+ "
"
+ }
+ }
+
+ private def createAccount(image: Option[String]) =
+ Account(
+ userName = "",
+ mailAddress = "",
+ password = "",
+ isAdmin = false,
+ url = None,
+ registeredDate = new Date(),
+ updatedDate = new Date(),
+ lastLoginDate = None,
+ image = image,
+ isGroupAccount = false)
+
+ private def createSystemSettings(useGravatar: Boolean) =
+ SystemSettings(
+ allowAccountRegistration = false,
+ gravatar = useGravatar,
+ notification = false,
+ smtp = None,
+ ldapAuthentication = false,
+ ldap = None)
+
+ /**
+ * Adapter to test AvatarImageProviderImpl.
+ */
+ class AvatarImageProviderImpl(account: Option[Account], settings: SystemSettings)
+ extends AvatarImageProvider with RequestCache {
+
+ def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)
+ (implicit context: app.Context): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
+
+ override def getAccountByUserName(userName: String)(implicit context: app.Context): Option[Account] = account
+ override def getSystemSettings()(implicit context: app.Context): SystemSettings = settings
+ }
+
+}