javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClientTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.bck2brwsr.demo.twitter;
20 import java.util.List;
21 import static org.testng.Assert.*;
22 import org.testng.annotations.BeforeMethod;
23 import org.testng.annotations.Test;
25 /** We can unit test the TwitterModel smoothly.
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class TwitterClientTest {
30 private TwitterModel model;
34 public void initModel() {
35 model = new TwitterModel().applyBindings();
38 @Test public void testIsValidToAdd() {
39 model.setUserNameToAdd("Joe");
40 Tweeters t = new Tweeters();
42 model.getSavedLists().add(t);
43 model.setActiveTweetersName("test");
45 assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
46 TwitterClient.addUser(model);
47 assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
48 assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
50 List<String> mod = model.getActiveTweeters();
51 assertTrue(model.isHasUnsavedChanges(), "We have modifications");
52 assertEquals(mod.size(), 1, "One element in the list");
53 assertEquals(mod.get(0), "Joe", "Its name is Joe");
55 assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
57 TwitterClient.saveChanges(model);
58 assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
60 assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
63 @Test public void httpAtTheEnd() {
64 String res = TwitterClient.Twt.html("Ahoj http://kuk");
65 assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");