My favorites | Sign in
Project Home Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package pl.fones.blog.asynctest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* Sample Engine Tests.
*
* @author Wojciech Grzeskowiak
* @date 2010/05/11
* @version 1.0
* @link http://blog.fones.pl
*/
public class EngineTest extends AsyncBaseTestCase {

// How many methods have this interface.
private static final int NOTIFICTION_METHODS_COUNT = 1;

// Mapping numbers and names of methods.
private static class NotificationsMethods {
public static final int ENGINESTART = 0;
}

// Implementation of notification interface.
private class EngineNotifier implements EngineNotifications {

@Override
public void engineStart(boolean success) {

// Notify waiting method.
notifyCallback(NotificationsMethods.ENGINESTART, success);
}
}

// Called before each test method.
@Before
protected void setUp() throws Exception {
super.setUp();

// Setup callbacks.
setupCallbacks(NOTIFICTION_METHODS_COUNT);
}

// Test engine start. Waiting for callback.
@Test
public void testEngineStartTest() throws Exception {

// Creating engine.
Engine sampleEngine = new Engine();

// Setting notification interface.
sampleEngine.setNotifier(new EngineNotifier());

boolean expected = true;
boolean actual;

// Start engine.
actual = sampleEngine.start();

assertEquals("Cannot triger engine to start", expected, actual);

// Waiting for callback.
// If callback not appears in AsyncBaseTestCase.MAX_TIME_FOR_CALLBACK time, internal assert will fail.
waitForCallback(NotificationsMethods.ENGINESTART);

// Getting callback result. Value of argument passed to callback method.
expected = true;
actual = getCallbackResult(NotificationsMethods.ENGINESTART);

assertEquals("Engine cannot start properly.", expected, actual);
}

// Called after each method.
@After
protected void tearDown() throws Exception {
super.tearDown();

// Nothing to do.
}
}

Change log

r7 by w.grzeskowiak on Sep 20, 2010   Diff
Move Java project
Go to: 

Older revisions

All revisions of this file

File info

Size: 2366 bytes, 81 lines
Powered by Google Project Hosting