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() {
			private final long timeInMillis = System.currentTimeMillis();

			@Override
			public long getSystemTime() {
				return this.timeInMillis;
			}
		});

		Date timestamp = SystemTime.getAsDate();
		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());
	}

}

@@ -147,16 +147,41 @@
 .After;%0A
+import org.junit.Before;%0A
 import o
@@ -302,16 +302,226 @@
 Test %7B%0A%0A
+%09@Before%0A%09public void setup() %7B%0A%09%09SystemTime.setTimeSource(new TimeSource() %7B%0A%09%09%09private final long timeInMillis = 0;%0A%0A%09%09%09@Override%0A%09%09%09public long getSystemTime() %7B%0A%09%09%09%09return this.timeInMillis;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A
 %09@After%0A
@@ -747,208 +747,8 @@
 );%0A%0A
-%09%09SystemTime.setTimeSource(new TimeSource() %7B%0A%09%09%09private final long timeInMillis = System.currentTimeMillis();%0A%0A%09%09%09@Override%0A%09%09%09public long getSystemTime() %7B%0A%09%09%09%09return this.timeInMillis;%0A%09%09%09%7D%0A%09%09%7D);%0A%0A
 %09%09Da

Fix test setup