package beaform.events;

import static org.junit.Assert.assertEquals;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.After;
import org.junit.Test;

import beaform.utilities.SystemTime;
import beaform.utilities.TimeSource;

public class StoreEventTest {

	@After
	public void destroy() {
		SystemTime.reset();
	}

	@Test
	public void testEventString() {
		// Create a 'create' event for a new formula
		String name = "TestFormula";
		Event createEvent = new FormulaCreatedEvent(name);

		SystemTime.setTimeSource(new TimeSource() {

			@Override
			public long getSystemTime() {
				return new Date().getTime();
			}
		});

		Date timestamp = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		// Check if the event converts to a string correctly
		// [timestamp] action properties
		assertEquals("[" + df.format(timestamp) + "] FormulaCreated " + name, createEvent.toEventString());
	}

}

@@ -553,16 +553,81 @@
 urce() %7B
+%0A%09%09%09private final long timeInMillis = System.currentTimeMillis();
 %0A%0A%09%09%09@Ov
@@ -681,28 +681,25 @@
 urn 
-new Date().getTime()
+this.timeInMillis
 ;%0A%09%09

Fix the unit test by making the returned time the same on all calls (which was the whole point)