javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClientTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 08 Apr 2013 18:26:11 +0200
branchmodel
changeset 955 dad881565d0a
parent 931 9a7df12648b9
child 956 7fc6b7e9c982
permissions -rw-r--r--
Simplifying code by using @OnPropertyChange a bit more
     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 static org.testng.Assert.*;
    21 import org.testng.annotations.BeforeMethod;
    22 import org.testng.annotations.Test;
    23 
    24 /** We can unit test the TwitterModel smoothly.
    25  *
    26  * @author Jaroslav Tulach <jtulach@netbeans.org>
    27  */
    28 public class TwitterClientTest {
    29     private TwitterModel model;
    30     
    31 
    32     @BeforeMethod
    33     public void initModel() {
    34         model = new TwitterModel().applyBindings();
    35     }
    36 
    37     @Test public void testIsValidToAdd() {
    38         model.setUserNameToAdd("Joe");
    39         Tweeters t = new Tweeters();
    40         t.setName("test");
    41         model.getSavedLists().add(t);
    42         model.setActiveTweetersName("test");
    43         
    44         assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
    45         TwitterClient.addUser(model);
    46         assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
    47         assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
    48         
    49         Tweeters mod = model.getActiveTweeters();
    50         assertNotNull(mod, "Modified list is not filled in");
    51         assertTrue(model.isHasUnsavedChanges(), "We have modifications");
    52         assertEquals(mod.getUserNames().size(), 1, "One element in the list");
    53         assertEquals(mod.getUserNames().get(0), "Joe", "Its name is Joe");
    54         
    55         assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
    56         
    57         TwitterClient.saveChanges(model);
    58         assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
    59         
    60         assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
    61         
    62         assertFalse(model.getSavedLists().contains(t), "No longer contains old list");
    63     }
    64     
    65 }