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