import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.freenet.wot.Trust;
-import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage;
+import net.pterodactylus.sone.text.TimeTextConverter;
import net.pterodactylus.util.template.Accessor;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.TemplateContext;
/** The core. */
private final Core core;
+ private final TimeTextConverter timeTextConverter;
/**
* Creates a new Sone accessor.
* @param core
* The Sone core
*/
- public SoneAccessor(Core core) {
+ public SoneAccessor(Core core, TimeTextConverter timeTextConverter) {
this.core = core;
+ this.timeTextConverter = timeTextConverter;
}
/**
} else if (member.equals("locked")) {
return core.isLocked(sone);
} else if (member.equals("lastUpdatedText")) {
- return GetTimesAjaxPage.getTime((WebInterface) templateContext.get("webInterface"), sone.getTime());
+ return timeTextConverter.getTimeText(sone.getTime()).getL10nText();
} else if (member.equals("trust")) {
Sone currentSone = (Sone) templateContext.get("currentSone");
if (currentSone == null) {
import net.pterodactylus.sone.text.Part;
import net.pterodactylus.sone.text.SonePart;
import net.pterodactylus.sone.text.SoneTextParser;
+import net.pterodactylus.sone.text.TimeTextConverter;
import net.pterodactylus.sone.web.ajax.BookmarkAjaxPage;
import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
private final PostVisibilityFilter postVisibilityFilter;
private final ReplyVisibilityFilter replyVisibilityFilter;
+ private final TimeTextConverter timeTextConverter = new TimeTextConverter();
+ private final L10nFilter l10nFilter = new L10nFilter(this);
+
/** The “new Sone” notification. */
private final ListNotification<Sone> newSoneNotification;
templateContextFactory = new TemplateContextFactory();
templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
templateContextFactory.addAccessor(Collection.class, new CollectionAccessor());
- templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
+ templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore(), new TimeTextConverter()));
templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore()));
templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
templateContextFactory.addAccessor(Album.class, new AlbumAccessor());
pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage<FreenetRequest>("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this, timeTextConverter, l10nFilter)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this, timeTextConverter, l10nFilter)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.notify.PostVisibilityFilter;
-import net.pterodactylus.sone.notify.ReplyVisibilityFilter;
+import net.pterodactylus.sone.freenet.L10nFilter;
import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.text.TimeText;
+import net.pterodactylus.sone.text.TimeTextConverter;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.notify.Notification;
/** Date formatter. */
private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss");
+ private final TimeTextConverter timeTextConverter;
+ private final L10nFilter l10nFilter;
/**
* Creates a new “get status” AJAX handler.
* @param webInterface
* The Sone web interface
*/
- public GetStatusAjaxPage(WebInterface webInterface) {
+ public GetStatusAjaxPage(WebInterface webInterface, TimeTextConverter timeTextConverter, L10nFilter l10nFilter) {
super("getStatus.ajax", webInterface);
+ this.timeTextConverter = timeTextConverter;
+ this.l10nFilter = l10nFilter;
}
/**
synchronized (dateFormat) {
jsonSone.put("lastUpdated", dateFormat.format(new Date(sone.getTime())));
}
- jsonSone.put("lastUpdatedText", GetTimesAjaxPage.getTime(webInterface, sone.getTime()).getText());
+ TimeText timeText = timeTextConverter.getTimeText(sone.getTime());
+ jsonSone.put("lastUpdatedText", l10nFilter.format(null, timeText.getL10nText(), Collections.<String, Object>emptyMap()));
return jsonSone;
}
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Collections;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.freenet.L10nFilter;
+import net.pterodactylus.sone.text.TimeText;
+import net.pterodactylus.sone.text.TimeTextConverter;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
/** Formatter for tooltips. */
private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss");
+ private final TimeTextConverter timeTextConverter;
+ private final L10nFilter l10nFilter;
/**
* Creates a new get times AJAX page.
* @param webInterface
* The Sone web interface
*/
- public GetTimesAjaxPage(WebInterface webInterface) {
+ public GetTimesAjaxPage(WebInterface webInterface, TimeTextConverter timeTextConverter, L10nFilter l10nFilter) {
super("getTimes.ajax", webInterface);
+ this.timeTextConverter = timeTextConverter;
+ this.l10nFilter = l10nFilter;
}
/**
* @return The formatted age
*/
private Time getTime(long time) {
- return getTime(webInterface, time);
- }
-
- //
- // STATIC METHODS
- //
-
- /**
- * Returns the formatted relative time for a given time.
- *
- * @param webInterface
- * The Sone web interface (for l10n access)
- * @param time
- * The time to format the difference from (in milliseconds)
- * @return The formatted age
- */
- public static Time getTime(WebInterface webInterface, long time) {
- if (time == 0) {
- return new Time(webInterface.getL10n().getString("View.Sone.Text.UnknownDate"), TimeUnit.HOURS.toMillis(12));
- }
- long age = System.currentTimeMillis() - time;
- String text;
- long refresh;
- if (age < 0) {
- text = webInterface.getL10n().getString("View.Time.InTheFuture");
- refresh = TimeUnit.MINUTES.toMillis(5);
- } else if (age < TimeUnit.SECONDS.toMillis(20)) {
- text = webInterface.getL10n().getString("View.Time.AFewSecondsAgo");
- refresh = TimeUnit.SECONDS.toMillis(10);
- } else if (age < TimeUnit.SECONDS.toMillis(45)) {
- text = webInterface.getL10n().getString("View.Time.HalfAMinuteAgo");
- refresh = TimeUnit.SECONDS.toMillis(20);
- } else if (age < TimeUnit.SECONDS.toMillis(90)) {
- text = webInterface.getL10n().getString("View.Time.AMinuteAgo");
- refresh = TimeUnit.MINUTES.toMillis(1);
- } else if (age < TimeUnit.MINUTES.toMillis(30)) {
- text = webInterface.getL10n().getString("View.Time.XMinutesAgo", "min", String.valueOf(TimeUnit.MILLISECONDS.toMinutes(age + TimeUnit.SECONDS.toMillis(30))));
- refresh = TimeUnit.MINUTES.toMillis(1);
- } else if (age < TimeUnit.MINUTES.toMillis(45)) {
- text = webInterface.getL10n().getString("View.Time.HalfAnHourAgo");
- refresh = TimeUnit.MINUTES.toMillis(10);
- } else if (age < TimeUnit.MINUTES.toMillis(90)) {
- text = webInterface.getL10n().getString("View.Time.AnHourAgo");
- refresh = TimeUnit.HOURS.toMillis(1);
- } else if (age < TimeUnit.HOURS.toMillis(21)) {
- text = webInterface.getL10n().getString("View.Time.XHoursAgo", "hour", String.valueOf(TimeUnit.MILLISECONDS.toHours(age + TimeUnit.MINUTES.toMillis(30))));
- refresh = TimeUnit.HOURS.toMillis(1);
- } else if (age < TimeUnit.HOURS.toMillis(42)) {
- text = webInterface.getL10n().getString("View.Time.ADayAgo");
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(6)) {
- text = webInterface.getL10n().getString("View.Time.XDaysAgo", "day", String.valueOf(TimeUnit.MILLISECONDS.toDays(age + TimeUnit.HOURS.toMillis(12))));
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(11)) {
- text = webInterface.getL10n().getString("View.Time.AWeekAgo");
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(28)) {
- text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / (7 * 24)));
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(42)) {
- text = webInterface.getL10n().getString("View.Time.AMonthAgo");
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(330)) {
- text = webInterface.getL10n().getString("View.Time.XMonthsAgo", "month", String.valueOf((TimeUnit.MILLISECONDS.toDays(age) + 15) / 30));
- refresh = TimeUnit.DAYS.toMillis(1);
- } else if (age < TimeUnit.DAYS.toMillis(540)) {
- text = webInterface.getL10n().getString("View.Time.AYearAgo");
- refresh = TimeUnit.DAYS.toMillis(7);
- } else {
- text = webInterface.getL10n().getString("View.Time.XYearsAgo", "year", String.valueOf((long) ((TimeUnit.MILLISECONDS.toDays(age) + 182.64) / 365.28)));
- refresh = TimeUnit.DAYS.toMillis(7);
- }
- return new Time(text, refresh);
+ TimeText timeText = timeTextConverter.getTimeText(time);
+ return new Time(l10nFilter.format(null, timeText.getL10nText(), Collections.<String, Object>emptyMap()), timeText.getRefreshTime());
}
/**
View.Time.AFewSecondsAgo=vor ein paar Sekunden
View.Time.HalfAMinuteAgo=vor einer halben Minute
View.Time.AMinuteAgo=vor ungefähr einer Minute
-View.Time.XMinutesAgo=vor ${min} Minuten
+View.Time.XMinutesAgo=vor {0} Minuten
View.Time.HalfAnHourAgo=vor einer halben Stunde
View.Time.AnHourAgo=vor ungefähr einer Stunde
-View.Time.XHoursAgo=vor ${hour} Stunden
+View.Time.XHoursAgo=vor {0} Stunden
View.Time.ADayAgo=vor ungefähr einem Tag
-View.Time.XDaysAgo=vor ${day} Tagen
+View.Time.XDaysAgo=vor {0} Tagen
View.Time.AWeekAgo=vor ungefähr einer Woche
-View.Time.XWeeksAgo=vor ${week} Wochen
+View.Time.XWeeksAgo=vor {0} Wochen
View.Time.AMonthAgo=vor ungefähr einem Monat
-View.Time.XMonthsAgo=vor ${month} Monaten
+View.Time.XMonthsAgo=vor {0} Monaten
View.Time.AYearAgo=vor ungefähr einem Jahr
-View.Time.XYearsAgo=vor ${year} Jahren
+View.Time.XYearsAgo=vor {0} Jahren
WebInterface.DefaultText.StatusUpdate=Was beschäftigt Sie gerade?
WebInterface.DefaultText.Message=Schreiben Sie eine Nachricht…
View.Time.AFewSecondsAgo=a few seconds ago
View.Time.HalfAMinuteAgo=about half a minute ago
View.Time.AMinuteAgo=about a minute ago
-View.Time.XMinutesAgo=${min} minutes ago
+View.Time.XMinutesAgo={0} minutes ago
View.Time.HalfAnHourAgo=half an hour ago
View.Time.AnHourAgo=about an hour ago
-View.Time.XHoursAgo=${hour} hours ago
+View.Time.XHoursAgo={0} hours ago
View.Time.ADayAgo=about a day ago
-View.Time.XDaysAgo=${day} days ago
+View.Time.XDaysAgo={0} days ago
View.Time.AWeekAgo=about a week ago
-View.Time.XWeeksAgo=${week} weeks ago
+View.Time.XWeeksAgo={0} weeks ago
View.Time.AMonthAgo=about a month ago
-View.Time.XMonthsAgo=${month} months ago
+View.Time.XMonthsAgo={0} months ago
View.Time.AYearAgo=about a year ago
-View.Time.XYearsAgo=${year} years ago
+View.Time.XYearsAgo={0} years ago
WebInterface.DefaultText.StatusUpdate=What’s on your mind?
WebInterface.DefaultText.Message=Write a Message…
View.Time.AFewSecondsAgo=hace unos segundos
View.Time.HalfAMinuteAgo=hace medio minuto
View.Time.AMinuteAgo=hace un minuto
-View.Time.XMinutesAgo=hace ${min} minutos
+View.Time.XMinutesAgo=hace {0} minutos
View.Time.HalfAnHourAgo=hace media hora
View.Time.AnHourAgo=hace una hora
-View.Time.XHoursAgo=hace ${hour} horas
+View.Time.XHoursAgo=hace {0} horas
View.Time.ADayAgo=hace un día
-View.Time.XDaysAgo=hace ${day} días
+View.Time.XDaysAgo=hace {0} días
View.Time.AWeekAgo=hace una semana
-View.Time.XWeeksAgo=hace ${week} semanas
+View.Time.XWeeksAgo=hace {0} semanas
View.Time.AMonthAgo=hace un mes
-View.Time.XMonthsAgo=hace ${month} meses
+View.Time.XMonthsAgo=hace {0} meses
View.Time.AYearAgo=hace un año
-View.Time.XYearsAgo=hace ${year} años
+View.Time.XYearsAgo=hace {0} años
WebInterface.DefaultText.StatusUpdate=Qué estás pensando?
WebInterface.DefaultText.Message=Escribir un mensaje…
View.Time.AFewSecondsAgo=au cours des dernières secondes passées
View.Time.HalfAMinuteAgo=au cours des 30 dernières secondes
View.Time.AMinuteAgo=au cours de la dernière minute
-View.Time.XMinutesAgo=il y a environs ${min} minutes
+View.Time.XMinutesAgo=il y a environs {0} minutes
View.Time.HalfAnHourAgo=au cours de la dernière demi heure
View.Time.AnHourAgo=il y a environ une heure
-View.Time.XHoursAgo=Il y a environ ${hour} heures
+View.Time.XHoursAgo=Il y a environ {0} heures
View.Time.ADayAgo=il y a environ un jour
-View.Time.XDaysAgo=il y a plus ou moins ${day} jours
+View.Time.XDaysAgo=il y a plus ou moins {0} jours
View.Time.AWeekAgo=il y a environ une semaine
-View.Time.XWeeksAgo=au cours des dernières ${week}semaines
+View.Time.XWeeksAgo=au cours des dernières {0} semaines
View.Time.AMonthAgo=au cours du dernier mois
-View.Time.XMonthsAgo=au cours des derniers ${month} mois
+View.Time.XMonthsAgo=au cours des derniers {0} mois
View.Time.AYearAgo=au cours de la dernière année
-View.Time.XYearsAgo=au cours des dernières ${year} années
+View.Time.XYearsAgo=au cours des dernières {0} années
WebInterface.DefaultText.StatusUpdate=Exprimez-vous
WebInterface.DefaultText.Message=Écrire un message...
View.Time.AFewSecondsAgo=およそ数秒前
View.Time.HalfAMinuteAgo=およそ30秒前
View.Time.AMinuteAgo=およそ1分前
-View.Time.XMinutesAgo=${min}分前
+View.Time.XMinutesAgo={0}分前
View.Time.HalfAnHourAgo=30分前
View.Time.AnHourAgo=およそ1時間前
-View.Time.XHoursAgo=${hour}時間前
+View.Time.XHoursAgo={0}時間前
View.Time.ADayAgo=およそ1日前
-View.Time.XDaysAgo=${day}日前
+View.Time.XDaysAgo={0}日前
View.Time.AWeekAgo=およそ1週前
-View.Time.XWeeksAgo=${week}週前
+View.Time.XWeeksAgo={0}週前
View.Time.AMonthAgo=およそ1月前
-View.Time.XMonthsAgo=${month}月前
+View.Time.XMonthsAgo={0}月前
View.Time.AYearAgo=およそ1年前
-View.Time.XYearsAgo=${year}年前
+View.Time.XYearsAgo={0}年前
WebInterface.DefaultText.StatusUpdate=何か投稿しますか?
WebInterface.DefaultText.Message=メッセージを書いてください…
View.Time.AFewSecondsAgo=noen få sekunder siden
View.Time.HalfAMinuteAgo=omtrent et halvt minutt siden
View.Time.AMinuteAgo=omtrent et minutt siden
-View.Time.XMinutesAgo=${min} minutter siden
+View.Time.XMinutesAgo={0} minutter siden
View.Time.HalfAnHourAgo=en halvtime siden
View.Time.AnHourAgo=omtrent en time siden
-View.Time.XHoursAgo=${hour} timer siden
+View.Time.XHoursAgo={0} timer siden
View.Time.ADayAgo=omtrent en dag siden
-View.Time.XDaysAgo=${day} dager siden
+View.Time.XDaysAgo={0} dager siden
View.Time.AWeekAgo=omtrent en uke siden
-View.Time.XWeeksAgo=${week} uker siden
+View.Time.XWeeksAgo={0} uker siden
View.Time.AMonthAgo=omtrent en måned siden
-View.Time.XMonthsAgo=${month} måneder siden
+View.Time.XMonthsAgo={0} måneder siden
View.Time.AYearAgo=omtrent et år siden
-View.Time.XYearsAgo=${year} år siden
+View.Time.XYearsAgo={0} år siden
WebInterface.DefaultText.StatusUpdate=Hva tenker du på?
WebInterface.DefaultText.Message=Skriv et innlegg…
View.Time.AFewSecondsAgo=kilka sekund temu
View.Time.HalfAMinuteAgo=około pół godziny temu
View.Time.AMinuteAgo=około minutę temu
-View.Time.XMinutesAgo=${min}minut temu
+View.Time.XMinutesAgo={0} minut temu
View.Time.HalfAnHourAgo=pół godziny temu
View.Time.AnHourAgo=około godzinę temu
-View.Time.XHoursAgo=${hour} godzin temu
+View.Time.XHoursAgo={0} godzin temu
View.Time.ADayAgo=około godzinę
-View.Time.XDaysAgo=${day} dni temu
+View.Time.XDaysAgo={0} dni temu
View.Time.AWeekAgo=około tydzień temu
-View.Time.XWeeksAgo=${week} tygodni temu
+View.Time.XWeeksAgo={0} tygodni temu
View.Time.AMonthAgo=około miesiąc temu
-View.Time.XMonthsAgo=${month} miesięcy
+View.Time.XMonthsAgo={0} miesięcy
View.Time.AYearAgo=około rok temu
-View.Time.XYearsAgo=${year} lat temu
+View.Time.XYearsAgo={0} lat temu
WebInterface.DefaultText.StatusUpdate=O czym teraz myślisz?
WebInterface.DefaultText.Message=Napisz Wiadomość…
View.Time.AFewSecondsAgo=несколько секунд назад
View.Time.HalfAMinuteAgo=около полминуты назад
View.Time.AMinuteAgo=около минуты назад
-View.Time.XMinutesAgo=${min} минут назад
+View.Time.XMinutesAgo={0} минут назад
View.Time.HalfAnHourAgo=полчаса назад
View.Time.AnHourAgo=около часа назад
-View.Time.XHoursAgo=${hour} часов назад
+View.Time.XHoursAgo={0} часов назад
View.Time.ADayAgo=около дня назад
-View.Time.XDaysAgo=${day} дней назад
+View.Time.XDaysAgo={0} дней назад
View.Time.AWeekAgo=около недели назад
-View.Time.XWeeksAgo=${week} недель назад
+View.Time.XWeeksAgo={0} недель назад
View.Time.AMonthAgo=около месяца назад
-View.Time.XMonthsAgo=${month} месяцев назад
+View.Time.XMonthsAgo={0} месяцев назад
View.Time.AYearAgo=около года назад
-View.Time.XYearsAgo=${year} лет назад
+View.Time.XYearsAgo={0} лет назад
WebInterface.DefaultText.StatusUpdate=Что у вас на уме?
WebInterface.DefaultText.Message=Написать сообщение…
<div class="download-marker" title="<%= View.Sone.Status.Downloading|l10n|html>">⬊</div>
<div class="insert-marker" title="<%= View.Sone.Status.Inserting|l10n|html>">⬈</div>
<div class="idle-marker" title="<%= View.Sone.Status.Idle|l10n|html>">✔</div>
- <div class="last-update"><%= View.Sone.Label.LastUpdate|l10n|html> <span class="time" title="<% sone.time|unknown|date format=="MMM d, yyyy, HH:mm:ss">"><%sone.lastUpdatedText|html></span></div>
+ <div class="last-update"><%= View.Sone.Label.LastUpdate|l10n|html> <span class="time" title="<% sone.time|unknown|date format=="MMM d, yyyy, HH:mm:ss">"><%sone.lastUpdatedText|l10n|html></span></div>
<div>
<div class="profile-link"><a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a></div>
<div class="sone-stats">(<%= View.Sone.Stats.Posts|l10n 0=sone.posts.size>, <%= View.Sone.Stats.Replies|l10n 0=sone.replies.size><%if ! sone.allImages.size|match value==0>, <%= View.Sone.Stats.Images|l10n 0=sone.allImages.size><%/if>)</div>
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.test.deepMock
-import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebInterface
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.equalTo
-import org.junit.Test
-import java.lang.System.currentTimeMillis
-
-/**
- * Unit test for [GetTimesAjaxPage].
- */
-class GetTimesAjaxPageTest {
-
- private val webInterface = deepMock<WebInterface>()
-
- @Test
- fun timestampInTheFutureIsTranslatedCorrectly() {
- whenever(webInterface.l10n.getString("View.Time.InTheFuture")).thenReturn("in the future")
- val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() + 1000)
- assertThat(time.text, equalTo("in the future"))
- }
-
- @Test
- fun timestampAFewSecondsAgoIsTranslatedCorrectly() {
- whenever(webInterface.l10n.getString("View.Time.AFewSecondsAgo")).thenReturn("a few seconds ago")
- val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() - 1000)
- assertThat(time.text, equalTo("a few seconds ago"))
- }
-
-}
import net.pterodactylus.sone.data.Sone.SoneStatus.idle
import net.pterodactylus.sone.data.Sone.SoneStatus.inserting
import net.pterodactylus.sone.data.Sone.SoneStatus.unknown
+import net.pterodactylus.sone.freenet.L10nText
import net.pterodactylus.sone.freenet.wot.Identity
import net.pterodactylus.sone.freenet.wot.OwnIdentity
import net.pterodactylus.sone.freenet.wot.Trust
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.text.TimeText
+import net.pterodactylus.sone.text.TimeTextConverter
import net.pterodactylus.util.template.TemplateContext
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
class SoneAccessorTest {
private val core = mock<Core>()
- private val accessor = SoneAccessor(core)
+ private val timeTextConverter = mock<TimeTextConverter>()
+ private val accessor = SoneAccessor(core, timeTextConverter)
private val templateContext = mock<TemplateContext>()
private val currentSone = mock<Sone>()
private val currentIdentity = mock<OwnIdentity>()
}
@Test
+ fun `accessor returns l10n text for last update time`() {
+ whenever(sone.time).thenReturn(12345)
+ whenever(timeTextConverter.getTimeText(12345L)).thenReturn(TimeText(L10nText("l10n.key", listOf(3L)), 23456))
+ assertAccessorReturnValue("lastUpdatedText", L10nText("l10n.key", listOf(3L)))
+ }
+
+ @Test
fun `accessor returns null trust if there is no current sone`() {
whenever(templateContext["currentSone"]).thenReturn(null)
assertAccessorReturnValue("trust", null)