Skip to content

Commit

Permalink
Ensure execution report has a date
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoeben committed Feb 18, 2024
1 parent ca540b0 commit edfe3b5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/fitnesse/reporting/history/ExecutionReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fitnesse.FitNesseVersion;
import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.TestSummary;
import fitnesse.util.Clock;
import fitnesse.util.DateTimeUtil;
import fitnesse.util.TimeMeasurement;
import fitnesse.util.XmlUtil;
Expand Down Expand Up @@ -33,12 +34,13 @@ public abstract class ExecutionReport {
private List<ExecutionLogReport> executionLogs = new ArrayList<>();

protected ExecutionReport() {
version = new FitNesseVersion().toString();
this(new FitNesseVersion(), null);
}

public ExecutionReport(FitNesseVersion version, String rootPath) {
this.version = version == null ? "null" : version.toString();
this.rootPath = rootPath;
this.date = Clock.currentDate();
}

public void tallyPageCounts(ExecutionResult result) {
Expand Down
69 changes: 53 additions & 16 deletions test/fitnesse/reporting/history/ExecutionReportTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package fitnesse.reporting.history;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.StringWriter;

import fitnesse.FitNesseContext;
import fitnesse.FitNesseVersion;
import fitnesse.testsystems.TestSummary;
import fitnesse.testutil.FitNesseUtil;
import fitnesse.util.Clock;
import fitnesse.util.DateTimeUtil;
import fitnesse.util.TimeMeasurement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import fitnesse.util.DateTimeUtil;
import fitnesse.util.TimeMeasurement;
import fitnesse.FitNesseContext;
import fitnesse.testsystems.TestSummary;
import fitnesse.testutil.FitNesseUtil;
import java.io.StringWriter;
import java.util.TimeZone;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ExecutionReportTest {
private FitNesseContext context;
Expand All @@ -30,6 +33,11 @@ public void setup() throws Exception {
context = FitNesseUtil.makeTestContext();
}

@After
public void tearDown() {
Clock.restoreDefaultClock();
}

@Test
public void canReadTestExecutionReport() throws Exception {
TestExecutionReport original = new TestExecutionReport(new FitNesseVersion("version"), "rootPath");
Expand All @@ -39,8 +47,11 @@ public void canReadTestExecutionReport() throws Exception {
original.toXml(writer, context.pageFactory.getVelocityEngine());
ExecutionReport report = ExecutionReport.makeReport(writer.toString());
assertTrue(report instanceof TestExecutionReport);
assertEquals(original, report);
assertEquals(42, report.getTotalRunTimeInMillis());
// report creation date is not present in XML so this is the only difference between the two
assertNotEquals(original, report);
report.date = original.date;
assertEquals(original, report);
}

private TimeMeasurement totalTimeMeasurementWithElapsedMillis(final long millis) {
Expand Down Expand Up @@ -113,8 +124,34 @@ public void readsExecutionLog() throws Exception {

@Test
public void testHashCode() {
setupFixedTimeClock();
TestExecutionReport original = new TestExecutionReport(new FitNesseVersion("version"), "rootPath");

assertEquals(-836274316, original.hashCode());
assertEquals(-836264316, original.hashCode());
}

@Test
public void defaultsDateOnTestSystemStartFailure() throws Exception {
setupFixedTimeClock();

SuiteExecutionReport original = new SuiteExecutionReport(new FitNesseVersion("version"), "rootPath");
assertEquals(Clock.currentDate(), original.getDate());
assertEquals("1970-01-01T08:00:10+08:00", original.getDateString());
assertEquals("19700101080010", original.getResultDate());
assertEquals(-1, original.getTotalRunTimeInMillis());
}

private static void setupFixedTimeClock() {
new Clock(true) {
@Override
public long currentClockTimeInMillis() {
return 10000L;
}

@Override
protected TimeZone getTimeZone() {
return TimeZone.getTimeZone("Antarctica/Casey");
}
};
}
}

0 comments on commit edfe3b5

Please sign in to comment.