environment.setEmail("test@example.com");
Key minutesKey = MinutesService.put(" テスト用議事録");
for (int i = 0; i < 5; i++) {
MemoService.put(minutesKey, "memo" + i);
}
Minutes minutes = Datastore.get(Minutes.class, minutesKey);
// メール送信API をフックするApiProxy.Delegate を適用しておく。
@SuppressWarnings("rawtypes")
Delegate parentDelegate = ApiProxy.getDelegate();
MailDelegate mailDelegate = new MailDelegate();
ApiProxy.setDelegate(mailDelegate);
tester.param("delete", Datastore.keyToString(minutesKey));
tester.start(PATH);
assertThat(
"MinutesController のインスタンスが使用される",
tester.getController(),
instanceOf(MinutesController.class));
assertThat(
" レスポンスコードが204",
tester.response.getStatus(),
is(HttpServletResponse.SC_NO_CONTENT));
assertThat(" メールが送信される", mailDelegate.messages.size(), is(1));
MailMessage mail = mailDelegate.messages.get(0);
assertThat(
"From",
mail.getSender(),
is("minutes@yourappid.appspotmail.com"));
assertThat("To", mail.getTo(0), is("test@example.com"));
assertThat(
"Subject",
mail.getSubject(),
is(" 議事録[" + minutes.getTitle() + "] がTSV に変換されました"));
assertThat(
"Body",
mail.getTextBody(Charset.forName("utf-8")),
containsString("http://localhost/minutes?download="));
// ApiProxy.Delegate をもとに戻す。