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