@Before
public void setup() {
program = new Program();
- sut = new JobRuntime(null, program);
+ sut = new JobRuntime(null, program);
}
@Test
assertEquals(JobStatus.RUNABLE, sut.getStatus());
assertTrue(sut.getProgram() != null);
}
-
+
@Test(expected = NullPointerException.class)
public void testConstructor_NullProgram() throws Exception {
new JobRuntime(null, null);
- }
+ }
@Test
public void testHasNextInstruction() throws Exception {
sut.getNextInstruction();
assertFalse(sut.hasNextInstruction());
- }
-
+ }
+
@Test
public void testGetNextInstruction() throws Exception {
// Fixture
final IInstruction expected = new Instruction();
-
+
program.addInstruction(expected);
-
+
// Exercise
IInstruction instruction = sut.getNextInstruction();
// Verify
- assertEquals(expected, instruction);
- assertFalse(sut.hasNextInstruction());
+ assertEquals(expected, instruction);
+ assertFalse(sut.hasNextInstruction());
}
-
+
@Test(expected = NoSuchElementException.class)
public void testExecuteNextInstruction_NoMoreSteps() throws Exception {
// Exercise
sut.getNextInstruction();
- }
+ }
@Test(expected = NoSuchElementException.class)
public void testGetNextInstruction_NoMoreSteps() throws Exception {
// Exercise
sut.getNextInstruction();
- }
+ }
@Test(expected = NoSuchElementException.class)
public void testGetNextInstruction_NullParameter() throws Exception {
// Exercise
sut.getNextInstruction();
- }
+ }
@Test
public void testGetCurrentInstruction() throws Exception {
final IInstruction instruction2 = new Instruction();
program.addInstruction(instruction1);
program.addInstruction(instruction2);
-
+
// Exercise, Verify
assertEquals(instruction1, sut.getCurrentInstruction());
sut.getNextInstruction();
assertEquals(instruction2, sut.getCurrentInstruction());
}
-
@Test(expected = EmptyStackException.class)
public void testPop_Empty() throws Exception {
// Exercise
- sut.popFromStack();
+ sut.popFromStack();
}
@Test
sut.getNextInstruction();
sut.decrementInstructionPointer();
assertTrue(sut.hasNextInstruction());
- }
+ }
@Test(expected = IllegalStateException.class)
public void testIncrementInstructionPointer_AlreadyOnFirst() throws Exception {
// Verify
sut.decrementInstructionPointer();
- }
+ }
@Test
public void testSaveStack() throws Exception {
// Verify
assertEquals(value, sut.popFromStack());
- }
+ }
@Test
public void testSaveStatus() throws Exception {
// Verify
assertEquals(expected, sut.getSavedStatus());
- }
+ }
@Test
public void testArrangeStackInstruction() throws Exception {
sut.pushToStack(value1);
sut.pushToStack(value2);
sut.pushToStack(value3);
-
+
// Exercise
sut.arrangeStack();
-
+
// Verify
assertEquals(value1, sut.popFromStack());
assertEquals(var1, sut.popFromStack());
sut.pushToStack(value2);
sut.pushToStack(value3);
sut.pushToStack(3);
-
+
// Exercise
sut.swapStack();
-
+
// Verify
assertEquals(3, sut.popFromStack());
assertEquals(value1, sut.popFromStack());
// Fixture
final String name = "var1";
final Class<?> type = String.class;
-
+
// Exercise
sut.addVariable(name, type);
sut.addVariable(name, type);
}
-
+
@Test
public void testGetVariable() throws Exception {
// Fixture
final String name = "var1";
final Class<?> type = String.class;
sut.addVariable(name, type);
-
+
// Exercise
Object result = sut.getVariable(name);
-
+
// Verify
assertEquals(type, result);
}
@Test(expected = RuntimeException.class)
public void testGetVariable_WrongName() throws Exception {
// Exercise
- sut.getVariable("");
+ sut.getVariable("");
}
@Test(expected = NullPointerException.class)
public void testGetVariable_NullName() throws Exception {
// Exercise
- sut.getVariable(null);
+ sut.getVariable(null);
}
@Test
final Class<?> type = String.class;
final String value = "value1";
sut.addVariable(name, type);
-
+
// Exercise
sut.setVariable(name, value);
-
+
// Verify
assertEquals(value, sut.getVariable(name));
}
@Test(expected = RuntimeException.class)
public void testSetVariable_WrongName() throws Exception {
// Exercise
- sut.setVariable("", null);
+ sut.setVariable("", null);
}
@Test(expected = NullPointerException.class)
public void testSetVariable_NullName() throws Exception {
// Exercise
- sut.setVariable(null, null);
+ sut.setVariable(null, null);
}
@Test
final Map<String, Object> parameters = new LinkedHashMap<String, Object>();
parameters.put(name, value);
sut.setParameters(parameters);
-
+
// Exercise
Object result = sut.getParameter(name);
-
+
// Verify
assertEquals(value, result);
}
@Test(expected = RuntimeException.class)
public void testGetParameter_WrongName() throws Exception {
// Exercise
- sut.getParameter("");
+ sut.getParameter("");
}
@Test(expected = NullPointerException.class)
public void testGetParameter_NullName() throws Exception {
// Exercise
- sut.getParameter(null);
+ sut.getParameter(null);
}
@Test
statuses.add(event.getStatus());
}
});
-
+
// Exercise
sut.setStatus(JobStatus.WAIT_EXECUTOR);