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