author | Jaroslav Tulach <jtulach@netbeans.org> |
Sun, 06 Oct 2013 22:05:14 +0200 | |
changeset 407 | e1439046d96e |
parent 344 | 3ba131907351 |
permissions | -rw-r--r-- |
jtulach@343 | 1 |
package org.apidesign.singletons.usage; |
jtulach@343 | 2 |
|
jtulach@343 | 3 |
import org.apidesign.singletons.api.DialogDisplayer; |
jtulach@343 | 4 |
import org.junit.BeforeClass; |
jtulach@343 | 5 |
import org.junit.Test; |
jtulach@343 | 6 |
import org.netbeans.junit.MockServices; |
jtulach@343 | 7 |
import static org.junit.Assert.*; |
jtulach@343 | 8 |
|
jtulach@345 | 9 |
// BEGIN: singletons.injectable.test |
jtulach@343 | 10 |
public class MainTest { |
jtulach@343 | 11 |
@BeforeClass |
jtulach@343 | 12 |
public static void setUpClass() throws Exception { |
jtulach@343 | 13 |
MockServices.setServices(MockDialogDisplayer.class); |
jtulach@343 | 14 |
} |
jtulach@343 | 15 |
|
jtulach@343 | 16 |
@Test |
jtulach@343 | 17 |
public void testMainAsksAQuestion() { |
jtulach@345 | 18 |
assertNull( |
jtulach@345 | 19 |
"No question asked yet", MockDialogDisplayer.askedQuery |
jtulach@345 | 20 |
); |
jtulach@343 | 21 |
Main.main(new String[0]); |
jtulach@345 | 22 |
assertNotNull( |
jtulach@345 | 23 |
"main code asked our Mock displayer", |
jtulach@345 | 24 |
MockDialogDisplayer.askedQuery |
jtulach@345 | 25 |
); |
jtulach@343 | 26 |
} |
jtulach@343 | 27 |
|
jtulach@343 | 28 |
public static final class MockDialogDisplayer extends DialogDisplayer { |
jtulach@343 | 29 |
static String askedQuery; |
jtulach@343 | 30 |
|
jtulach@343 | 31 |
@Override |
jtulach@343 | 32 |
public boolean yesOrNo(String query) { |
jtulach@343 | 33 |
askedQuery = query; |
jtulach@343 | 34 |
return false; |
jtulach@343 | 35 |
} |
jtulach@343 | 36 |
} |
jtulach@345 | 37 |
} |
jtulach@345 | 38 |
// END: singletons.injectable.test |