samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 09 Nov 2008 16:20:01 +0100
changeset 291 9cbb8364c4ae
parent 154 0fd5e9c500b9
permissions -rw-r--r--
Renaming arguments
     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.NameProvider np = p;
    28         AServerInfo.URLProvider up = p;
    29         AServerInfo.ResetHandler res = p;
    30         AServerInfo inf;
    31         
    32         // BEGIN: aserverinfo.cumulative.creation
    33         inf = AServerInfo.empty().nameProvider(np).urlProvider(up).reset(res);
    34         // END: aserverinfo.cumulative.creation
    35         
    36         assertEquals("API Design Server", inf.getName());
    37         assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
    38         inf.reset();
    39         assertEquals("Once reset", 1, p.resets);
    40         
    41     }
    42     
    43     @Test
    44     public void showVerboseUseOfCumulativeFactory() throws Exception {
    45         Prov prov = new Prov();
    46         AServerInfo info;
    47         
    48         // BEGIN: aserverinfo.cumulative.creation.verbose
    49         AServerInfo empty = AServerInfo.empty();
    50         AServerInfo name = empty.nameProvider(prov);
    51         AServerInfo urlAndName = name.urlProvider(prov);
    52         info = urlAndName.reset(prov);
    53         // END: aserverinfo.cumulative.creation.verbose
    54         
    55         assertEquals("API Design Server", info.getName());
    56         assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
    57         info.reset();
    58         assertEquals("Once reset", 1, prov.resets);
    59         
    60     }
    61     
    62     
    63     private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
    64         int resets;
    65 
    66         public String getName() {
    67             return "API Design Server";
    68         }
    69 
    70         public URL getURL() {
    71             try {
    72                 return new URL("http://www.apidesign.org");
    73             } catch (MalformedURLException ex) {
    74                 Exceptions.printStackTrace(ex);
    75                 return null;
    76             }
    77         }
    78 
    79         public void reset() {
    80             resets++;
    81         }
    82 
    83     }
    84         
    85 }