RevisionIT: Make patch() unit test pass on non US locale

GetPatch.formatDate() method is using US locale for date formating:

  new SimpleDateFormat(
      "EEE, dd MMM yyyy HH:mm:ss Z",
      Locale.US);

Unit test missed to specify the locale and thus relies on the system
locale making the test flaky on non US locale. Particularly, with
German locale set the day of the week specifier used: "EEE" is get
translated to two characters day of the week names:

  So, Mo, Di, Mi, Do, Fr, Sa

whereas on US locale it's get translated to three characters day of
the week names:

  Sun, Mon, Tue, Wed, Thu, Fri, Sat

Fix the flaky test to use the same locale and not depend on system
locale to be the same as specified in GetPatch.formatDate() method.

Change-Id: Ib346887248a5a43ca682ca03ac8f280708981261
This commit is contained in:
David Ostrovsky
2015-09-12 22:12:07 +02:00
parent 85279183ec
commit 2c7d9ed1cf

View File

@@ -60,6 +60,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@NoHttpd
@@ -555,10 +556,12 @@ public class RevisionIT extends AbstractDaemonTest {
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String res = new String(os.toByteArray(), StandardCharsets.UTF_8);
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
ChangeInfo change = changeApi.get();
RevisionInfo rev = change.revisions.get(change.currentRevision);
String date = dateFormat.format(rev.commit.author.date);
DateFormat df = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z",
Locale.US);
String date = df.format(rev.commit.author.date);
assertThat(res).isEqualTo(
String.format(PATCH, r.getCommitId().name(), date, r.getChangeId()));
}