Testing DateTime Formatting Utilities in Alibaba Arthas
This test suite validates the DateUtils class functionality in Arthas, focusing on datetime formatting operations. The tests verify both valid and invalid date format patterns to ensure robust date handling capabilities.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java
package com.taobao.arthas.core.util;
import org.junit.Assert;
import org.junit.Test;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
*
* @author brijeshprasad89
*
*/
public class DateUtilsTest {
@Test
public void testFormatDateTimeWithCorrectFormat() {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); // supported date format
LocalDateTime dateTime = LocalDateTime.now();
Assert.assertEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime));
}
@Test
public void testFormatDateTimeWithInCorrectFormat() {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); // Not supported Date format
LocalDateTime dateTime = LocalDateTime.now();
Assert.assertNotEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime));
}
}