samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:11 +0200
changeset 154 0fd5e9c500b9
parent 153 b5cbb797ec0a
child 291 9cbb8364c4ae
permissions -rw-r--r--
Merge: Geertjan's changs up to 2000
     1 package org.apidesign.aserverinfo;
     2 
     3 import java.net.MalformedURLException;
     4 import java.net.URL;
     5 import org.junit.After;
     6 import org.junit.Before;
     7 import org.junit.Test;
     8 import static org.junit.Assert.*;
     9 import org.openide.util.Exceptions;
    10 
    11 public class AServerInfoTest {
    12 
    13     public AServerInfoTest() {
    14     }
    15 
    16     @Before
    17     public void setUp() {
    18     }
    19 
    20     @After
    21     public void tearDown() {
    22     }
    23 
    24     @Test
    25     public void showUseOfCumulativeFactory() throws Exception {
    26         Prov p = new Prov();
    27         AServerInfo inf;
    28         
    29         // BEGIN: aserverinfo.cumulative.creation
    30         inf = AServerInfo.empty().nameProvider(p).urlProvider(p).reset(p);
    31         // END: aserverinfo.cumulative.creation
    32         
    33         assertEquals("API Design Server", inf.getName());
    34         assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
    35         inf.reset();
    36         assertEquals("Once reset", 1, p.resets);
    37         
    38     }
    39     
    40     @Test
    41     public void showVerboseUseOfCumulativeFactory() throws Exception {
    42         Prov prov = new Prov();
    43         AServerInfo info;
    44         
    45         // BEGIN: aserverinfo.cumulative.creation.verbose
    46         AServerInfo empty = AServerInfo.empty();
    47         AServerInfo name = empty.nameProvider(prov);
    48         AServerInfo urlAndName = name.urlProvider(prov);
    49         info = urlAndName.reset(prov);
    50         // END: aserverinfo.cumulative.creation.verbose
    51         
    52         assertEquals("API Design Server", info.getName());
    53         assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
    54         info.reset();
    55         assertEquals("Once reset", 1, prov.resets);
    56         
    57     }
    58     
    59     
    60     private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
    61         int resets;
    62 
    63         public String getName() {
    64             return "API Design Server";
    65         }
    66 
    67         public URL getURL() {
    68             try {
    69                 return new URL("http://www.apidesign.org");
    70             } catch (MalformedURLException ex) {
    71                 Exceptions.printStackTrace(ex);
    72                 return null;
    73             }
    74         }
    75 
    76         public void reset() {
    77             resets++;
    78         }
    79 
    80     }
    81         
    82 }