Skip to content

Commit cdabd35

Browse files
committed
ADAP-98 added two more unit test cases.
1 parent e4184dc commit cdabd35

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/java/com/openfin/desktop/ApplicationTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.concurrent.CountDownLatch;
77
import java.util.concurrent.TimeUnit;
8+
import java.util.concurrent.atomic.AtomicInteger;
89

910
import org.junit.AfterClass;
1011
import org.junit.BeforeClass;
@@ -288,4 +289,52 @@ public void onError(Ack ack) {
288289

289290
TestUtils.closeApplication(application);
290291
}
292+
293+
@Test
294+
public void getWindow() throws Exception {
295+
ApplicationOptions options = TestUtils.getAppOptions(null);
296+
String mainWindowName = options.getName();
297+
Application application = TestUtils.createApplication(options, desktopConnection);
298+
TestUtils.runApplication(application, true);
299+
Window window = application.getWindow();
300+
assertEquals(window.getName(), mainWindowName);
301+
TestUtils.closeApplication(application);
302+
}
303+
304+
@Test
305+
public void removeEventListener() throws Exception {
306+
ApplicationOptions options = TestUtils.getAppOptions(null);
307+
Application application = TestUtils.createApplication(options, desktopConnection);
308+
309+
int cnt = 10;
310+
CountDownLatch latch = new CountDownLatch(cnt);
311+
AtomicInteger invokeCnt = new AtomicInteger(0);
312+
EventListener[] listeners = new EventListener[cnt];
313+
for (int i=0; i<cnt; i++) {
314+
listeners[i] = new EventListener(){
315+
@Override
316+
public void eventReceived(ActionEvent actionEvent) {
317+
invokeCnt.incrementAndGet();
318+
latch.countDown();
319+
}
320+
};
321+
}
322+
323+
for (int i=0; i<cnt; i++) {
324+
TestUtils.addEventListener(application, "window-closed", listeners[i]);
325+
}
326+
TestUtils.runApplication(application, true);
327+
328+
for (int i=0; i<cnt/2; i++) {
329+
application.removeEventListener("window-closed", listeners[i*2], null);
330+
}
331+
332+
Window window = application.getWindow();
333+
window.close();
334+
335+
latch.await(5, TimeUnit.SECONDS);
336+
337+
assertEquals(cnt/2, latch.getCount());
338+
assertEquals(cnt/2, invokeCnt.get());
339+
}
291340
}

0 commit comments

Comments
 (0)