package hu.advancedweb.scott;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

import org.junit.Test;

import hu.advancedweb.scott.helper.TestHelper;

public class FieldRecordingInitialValuesTest {
	
	int a = 10;
	int b = 11;
	static int A = 12;
	static int B = 13;
	
	
	@Test
	public void recordFieldAccess() throws Exception {
		// track initial states of accessed fields
		assertThat(TestHelper.getLastRecordedStateForField("this.a"), equalTo("10"));
		assertThat(TestHelper.getLastRecordedStateForField("this.b"), equalTo("11"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.A"), equalTo("12"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.B"), equalTo("13"));
		
		@SuppressWarnings("unused")
		String accessed = "" + a + b + A + B;
	}
	
	@Test
	public void recordFieldSubsetAccess() throws Exception {
		// track initial states of accessed fields
		assertThat(TestHelper.getLastRecordedStateForField("this.a"), equalTo("10"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.A"), equalTo("12"));
		
		// don't record not accessed fields
		assertThat(TestHelper.getLastRecordedStateForField("b"), equalTo(null));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.B"), equalTo(null));
		
		@SuppressWarnings("unused")
		String accessed = "" + a + A;
	}
	
	@Test
	public void recordWrite() throws Exception {
		// initial value match
		assertThat(TestHelper.getLastRecordedStateForField("this.a"), equalTo("10"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.A"), equalTo("12"));
		
		a = 20;
		A = 22;
		
		// values after write match
		assertThat(TestHelper.getLastRecordedStateForField("this.a"), equalTo("20"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.A"), equalTo("22"));
	}
	
	@Test
	public void recordReadAndWrite() throws Exception {
		// initial modified values match
		assertThat(TestHelper.getLastRecordedStateForField("this.b"), equalTo("11"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.B"), equalTo("13"));
		
		@SuppressWarnings("unused")
		String accessed = "" + b + B;
		
		// no change after reading
		assertThat(TestHelper.getLastRecordedStateForField("this.b"), equalTo("11"));
		assertThat(TestHelper.getLastRecordedStateForField("FieldRecordingInitialValuesTest.B"), equalTo("13"));
	}
	
}

@@ -1132,33 +1132,33 @@
 itialValuesTest.
-A
+B
 %22), equalTo(%2212%22
@@ -1147,33 +1147,33 @@
 .B%22), equalTo(%221
-2
+3
 %22));%0A%09%09%0A%09%09// don
@@ -1355,33 +1355,33 @@
 itialValuesTest.
-B
+A
 %22), equalTo(null
@@ -1446,17 +1446,17 @@
 %22 + a + 
-A
+B
 ;%0A%09%7D%0A%09%0A%09

Fix test