JUnit assertEquals更改字符串

Kev*_*sox 6 java junit

我有一个JUnit测试,如下所示:

@Test
public void testToDatabaseString() {
  DateConvertor convertor = new DateConvertor();
  Date date = convertor.convert("20/07/1984:00:00:00:00");
  String convertedDate = convertor.toDatabaseString(date);

  assertEquals("to_date('20/07/1984:00:00:00:00', 'DD/MM/YYYY HH24:MI:SS')",convertedDate);
}
Run Code Online (Sandbox Code Playgroud)

测试失败说明:

org.junit.ComparisonFailure: expected:<to_date('20/07/1984[00:]00:00:00', 'DD/MM/YY...> but was:<to_date('20/07/1984[ ]00:00:00', 'DD/MM/YY...>
Run Code Online (Sandbox Code Playgroud)

特别感兴趣的是为什么预期值是:

to_date('20/07/1984[00:]00:00:00', 等等...

当我的测试中的字符串文字显然是:

"to_date('20/07/1984:00:00:00:00', 等等...

有谁能解释一下?为什么要添加"[00:]"?感谢帮助.

Luk*_*ard 11

方括号强调预期字符串和实际字符串之间的差异.

JUnit将方括号放在周围,:00以强调这是预期字符串中的内容,而不是实际字符串中的内容.出于同样的原因,实际字符串中的空格周围有方括号.