package com.mars.rover;

import static org.junit.Assert.fail;

import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.junit.Test;

public class AccelerometerTests extends TestsWithMokingClasses {

	@Mock
	private AccelerationObserver observer;

	@Test
	public void testAccelerometerCanReportRapidAcceleration() throws Exception {
		Accelerometer accelerometer = new Accelerometer();
		accelerometer.add_observer(observer);
		context.checking(new Expectations() {
			{
				oneOf(observer).handle_acceleration_report(-50);
			}
		});

		accelerometer.report_acceleration(-50);
	}

	@Test
	public void //
	testAccelerometerCanRespondToFailureWhenReportingAcceleration() throws Exception {
		Accelerometer accelerometer = new Accelerometer();
		accelerometer.add_observer(observer);
		context.checking(new Expectations() {
			{
				allowing(observer).handle_acceleration_report(-50);
				will(throwException(new Exception()));
			}
		});

		try {
			accelerometer.report_acceleration(-50);
			fail("No threw exception");
		} catch (Exception e) {
		}
	}
}

@@ -115,16 +115,41 @@
 o.Mock;%0A
+import org.junit.Before;%0A
 import o
@@ -281,186 +281,246 @@
 er;%0A
-%0A%09@Test%0A%09public void testAccelerometerCanReportRapidAcceleration() throws Exception %7B%0A%09%09Accelerometer accelerometer = new Accelerometer();%0A%09%09accelerometer.add_observer(observer);
+%09private Accelerometer accelerometer;%0A%0A%09@Before%0A%09public void setup() %7B%0A%09%09accelerometer = new Accelerometer();%0A%09%09accelerometer.add_observer(observer);%0A%09%7D%0A%0A%09@Test%0A%09public void testAccelerometerCanReportRapidAcceleration() throws Exception %7B
 %0A%09%09c
@@ -783,101 +783,8 @@
 n %7B%0A
-%09%09Accelerometer accelerometer = new Accelerometer();%0A%09%09accelerometer.add_observer(observer);%0A
 %09%09co

refactor tests