samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java
changeset 114 c479228609ea
parent 91 3280450405a0
child 133 50bf1b976c0d
     1.1 --- a/samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java	Sat Jun 14 09:53:57 2008 +0200
     1.2 +++ b/samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java	Sat Jun 14 09:54:39 2008 +0200
     1.3 @@ -23,28 +23,6 @@
     1.4  
     1.5      @Test
     1.6      public void showUseOfCumulativeFactory() throws Exception {
     1.7 -        class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
     1.8 -            int resets;
     1.9 -            
    1.10 -            public String getName() {
    1.11 -                return "API Design Server";
    1.12 -            }
    1.13 -
    1.14 -            public URL getURL() {
    1.15 -                try {
    1.16 -                    return new URL("http://www.apidesign.org");
    1.17 -                } catch (MalformedURLException ex) {
    1.18 -                    Exceptions.printStackTrace(ex);
    1.19 -                    return null;
    1.20 -                }
    1.21 -            }
    1.22 -
    1.23 -            public void reset() {
    1.24 -                resets++;
    1.25 -            }
    1.26 -            
    1.27 -        }
    1.28 -        
    1.29          Prov prov = new Prov();
    1.30          AServerInfo info;
    1.31          
    1.32 @@ -58,4 +36,47 @@
    1.33          assertEquals("Once reset", 1, prov.resets);
    1.34          
    1.35      }
    1.36 +    
    1.37 +    @Test
    1.38 +    public void showVerboseUseOfCumulativeFactory() throws Exception {
    1.39 +        Prov prov = new Prov();
    1.40 +        AServerInfo info;
    1.41 +        
    1.42 +        // BEGIN: aserverinfo.cumulative.creation.verbose
    1.43 +        AServerInfo empty = AServerInfo.empty();
    1.44 +        AServerInfo name = empty.nameProvider(prov);
    1.45 +        AServerInfo urlAndName = name.urlProvider(prov);
    1.46 +        info = urlAndName.reset(prov);
    1.47 +        // END: aserverinfo.cumulative.creation.verbose
    1.48 +        
    1.49 +        assertEquals("API Design Server", info.getName());
    1.50 +        assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
    1.51 +        info.reset();
    1.52 +        assertEquals("Once reset", 1, prov.resets);
    1.53 +        
    1.54 +    }
    1.55 +    
    1.56 +    
    1.57 +    private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
    1.58 +        int resets;
    1.59 +
    1.60 +        public String getName() {
    1.61 +            return "API Design Server";
    1.62 +        }
    1.63 +
    1.64 +        public URL getURL() {
    1.65 +            try {
    1.66 +                return new URL("http://www.apidesign.org");
    1.67 +            } catch (MalformedURLException ex) {
    1.68 +                Exceptions.printStackTrace(ex);
    1.69 +                return null;
    1.70 +            }
    1.71 +        }
    1.72 +
    1.73 +        public void reset() {
    1.74 +            resets++;
    1.75 +        }
    1.76 +
    1.77 +    }
    1.78 +        
    1.79  }
    1.80 \ No newline at end of file