samples/singletons/test/org/apidesign/singletons/usage/MainTest.java
changeset 343 8e220093e4bf
child 344 3ba131907351
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/singletons/test/org/apidesign/singletons/usage/MainTest.java	Wed Jan 27 18:30:57 2010 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +package org.apidesign.singletons.usage;
     1.5 +
     1.6 +import org.apidesign.singletons.api.DialogDisplayer;
     1.7 +import org.junit.AfterClass;
     1.8 +import org.junit.BeforeClass;
     1.9 +import org.junit.Test;
    1.10 +import org.netbeans.junit.MockServices;
    1.11 +import static org.junit.Assert.*;
    1.12 +
    1.13 +public class MainTest {
    1.14 +
    1.15 +    public MainTest() {
    1.16 +    }
    1.17 +
    1.18 +    @BeforeClass
    1.19 +    public static void setUpClass() throws Exception {
    1.20 +        MockServices.setServices(MockDialogDisplayer.class);
    1.21 +    }
    1.22 +
    1.23 +    @Test
    1.24 +    public void testMainAsksAQuestion() {
    1.25 +        assertNull("No question asked yet", MockDialogDisplayer.askedQuery);
    1.26 +        Main.main(new String[0]);
    1.27 +        assertNotNull("main code asked our Mock displayer", MockDialogDisplayer.askedQuery);
    1.28 +    }
    1.29 +
    1.30 +    public static final class MockDialogDisplayer extends DialogDisplayer {
    1.31 +        static String askedQuery;
    1.32 +        
    1.33 +        @Override
    1.34 +        public boolean yesOrNo(String query) {
    1.35 +            askedQuery = query;
    1.36 +            return false;
    1.37 +        }
    1.38 +
    1.39 +    }
    1.40 +}
    1.41 \ No newline at end of file