twitter/src/test/java/org/apidesign/html/demo/twitter/TwitterClientTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Tue, 13 Aug 2013 21:11:28 +0200
changeset 44 e3305312184c
parent 0 6fe609b8f0fb
permissions -rw-r--r--
Simplified, rewritten to 0.4 and made compilable on JDK8
jtulach@0
     1
/**
jtulach@0
     2
 * The MIT License (MIT)
jtulach@0
     3
 *
jtulach@0
     4
 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@0
     5
 *
jtulach@0
     6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
jtulach@0
     7
 * of this software and associated documentation files (the "Software"), to deal
jtulach@0
     8
 * in the Software without restriction, including without limitation the rights
jtulach@0
     9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jtulach@0
    10
 * copies of the Software, and to permit persons to whom the Software is
jtulach@0
    11
 * furnished to do so, subject to the following conditions:
jtulach@0
    12
 *
jtulach@0
    13
 * The above copyright notice and this permission notice shall be included in
jtulach@0
    14
 * all copies or substantial portions of the Software.
jtulach@0
    15
 *
jtulach@0
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jtulach@0
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jtulach@0
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jtulach@0
    19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jtulach@0
    20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jtulach@0
    21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jtulach@0
    22
 * THE SOFTWARE.
jtulach@0
    23
 */
jtulach@0
    24
package org.apidesign.html.demo.twitter;
jtulach@0
    25
jtulach@0
    26
import java.util.List;
jtulach@0
    27
import static org.testng.Assert.*;
jtulach@0
    28
import org.testng.annotations.BeforeMethod;
jtulach@0
    29
import org.testng.annotations.Test;
jtulach@0
    30
jtulach@0
    31
/** We can unit test the TwitterModel smoothly.
jtulach@0
    32
 *
jtulach@0
    33
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@0
    34
 */
jtulach@0
    35
public class TwitterClientTest {
jtulach@0
    36
    private TwitterModel model;
jtulach@0
    37
    
jtulach@0
    38
jtulach@0
    39
    @BeforeMethod
jtulach@0
    40
    public void initModel() {
jtulach@44
    41
        model = new TwitterModel();
jtulach@0
    42
    }
jtulach@0
    43
jtulach@0
    44
    @Test public void testIsValidToAdd() {
jtulach@0
    45
        model.setUserNameToAdd("Joe");
jtulach@44
    46
        Tweeters t = new Tweeters();
jtulach@0
    47
        t.setName("test");
jtulach@0
    48
        model.getSavedLists().add(t);
jtulach@0
    49
        model.setActiveTweetersName("test");
jtulach@0
    50
        
jtulach@0
    51
        assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
jtulach@0
    52
        TwitterClient.addUser(model);
jtulach@0
    53
        assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
jtulach@0
    54
        assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
jtulach@0
    55
        
jtulach@0
    56
        List<String> mod = model.getActiveTweeters();
jtulach@0
    57
        assertTrue(model.isHasUnsavedChanges(), "We have modifications");
jtulach@0
    58
        assertEquals(mod.size(), 1, "One element in the list");
jtulach@0
    59
        assertEquals(mod.get(0), "Joe", "Its name is Joe");
jtulach@0
    60
        
jtulach@0
    61
        assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
jtulach@0
    62
        
jtulach@0
    63
        TwitterClient.saveChanges(model);
jtulach@0
    64
        assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
jtulach@0
    65
        
jtulach@0
    66
        assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
jtulach@0
    67
    }
jtulach@0
    68
    
jtulach@0
    69
    @Test public void httpAtTheEnd() {
jtulach@0
    70
        String res = TwitterClient.Twt.html("Ahoj http://kuk");
jtulach@0
    71
        assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");
jtulach@0
    72
    }
jtulach@0
    73
}