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 ParachuteTests extends TestsWithMokingClasses {

	@Mock
	private Lander lander;

	@Test
	public void testOpenParachute() {
		Parachute parachute = new Parachute(lander);
		context.checking(new Expectations() {

			{
				oneOf(lander).decelerate();
			}
		});

		parachute.open();
	}

	@Test
	public void testDetachingWhileLanded() {
		Parachute parachute = new Parachute(lander);
		context.checking(new Expectations() {
			{
				oneOf(lander).has_landed();
				will(returnValue(true));
			}
		});

		try {
			parachute.detach();
		} catch (Exception e) {
			fail();
		}
	}

	@Test
	public void testDetachingWhileNotLanded() {
		Parachute parachute = new Parachute(lander);
		context.checking(new Expectations() {
			{
				oneOf(lander).has_landed();
				will(returnValue(false));
			}
		});

		try {
			parachute.detach();
			fail();
		} catch (Exception e) {
		}
	}

}

@@ -18,16 +18,103 @@
 rover;%0A%0A
+import static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A
 import s
@@ -733,33 +733,24 @@
 %09%09%09%7D%0A%09%09%7D);%0A%0A
-%09%09try %7B%0A%09
 %09%09parachute.
@@ -763,49 +763,8 @@
 ();%0A
-%09%09%7D catch (Exception e) %7B%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1020,16 +1020,36 @@
 %09%09%09fail(
+%22No threw exception%22
 );%0A%09%09%7D c
@@ -1069,16 +1069,83 @@
 on e) %7B%0A
+%09%09%09assertThat(e.getMessage(), is(%22You broke the lander, idiot.%22));%0A
 %09%09%7D%0A%09%7D%0A%0A

refactor tests