javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClientTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 26 Apr 2013 13:51:15 +0200
branchmodel
changeset 1024 9af5b2f49cb0
parent 956 7fc6b7e9c982
child 1055 0d7b63408a1e
permissions -rw-r--r--
Twitter demo rewritten to use net.java.html.json annotations
jaroslav@931
     1
/**
jaroslav@931
     2
 * Back 2 Browser Bytecode Translator
jaroslav@931
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@931
     4
 *
jaroslav@931
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@931
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@931
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@931
     8
 *
jaroslav@931
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@931
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@931
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@931
    12
 * GNU General Public License for more details.
jaroslav@931
    13
 *
jaroslav@931
    14
 * You should have received a copy of the GNU General Public License
jaroslav@931
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@931
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@931
    17
 */
jaroslav@931
    18
package org.apidesign.bck2brwsr.demo.twitter;
jaroslav@931
    19
jaroslav@956
    20
import java.util.List;
jaroslav@1024
    21
import net.java.html.json.Context;
jaroslav@931
    22
import static org.testng.Assert.*;
jaroslav@931
    23
import org.testng.annotations.BeforeMethod;
jaroslav@931
    24
import org.testng.annotations.Test;
jaroslav@931
    25
jaroslav@931
    26
/** We can unit test the TwitterModel smoothly.
jaroslav@931
    27
 *
jaroslav@931
    28
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@931
    29
 */
jaroslav@931
    30
public class TwitterClientTest {
jaroslav@931
    31
    private TwitterModel model;
jaroslav@931
    32
    
jaroslav@931
    33
jaroslav@931
    34
    @BeforeMethod
jaroslav@931
    35
    public void initModel() {
jaroslav@1024
    36
        model = new TwitterModel(Context.EMPTY);
jaroslav@931
    37
    }
jaroslav@931
    38
jaroslav@931
    39
    @Test public void testIsValidToAdd() {
jaroslav@931
    40
        model.setUserNameToAdd("Joe");
jaroslav@1024
    41
        Tweeters t = new Tweeters(Context.EMPTY);
jaroslav@931
    42
        t.setName("test");
jaroslav@931
    43
        model.getSavedLists().add(t);
jaroslav@931
    44
        model.setActiveTweetersName("test");
jaroslav@931
    45
        
jaroslav@931
    46
        assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
jaroslav@931
    47
        TwitterClient.addUser(model);
jaroslav@931
    48
        assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
jaroslav@931
    49
        assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
jaroslav@931
    50
        
jaroslav@956
    51
        List<String> mod = model.getActiveTweeters();
jaroslav@931
    52
        assertTrue(model.isHasUnsavedChanges(), "We have modifications");
jaroslav@956
    53
        assertEquals(mod.size(), 1, "One element in the list");
jaroslav@956
    54
        assertEquals(mod.get(0), "Joe", "Its name is Joe");
jaroslav@931
    55
        
jaroslav@931
    56
        assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
jaroslav@931
    57
        
jaroslav@931
    58
        TwitterClient.saveChanges(model);
jaroslav@931
    59
        assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
jaroslav@931
    60
        
jaroslav@931
    61
        assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
jaroslav@931
    62
    }
jaroslav@931
    63
    
jaroslav@956
    64
    @Test public void httpAtTheEnd() {
jaroslav@956
    65
        String res = TwitterClient.Twt.html("Ahoj http://kuk");
jaroslav@956
    66
        assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");
jaroslav@956
    67
    }
jaroslav@931
    68
}