001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: *
017: * Based on code generated by Agitar build: Agitator Version 1.0.2.000071 (Build date: Jan 12, 2007) [1.0.2.000071]
018: */package org.jamwiki.utils;
019:
020: import junit.framework.TestCase;
021:
022: /**
023: *
024: */
025: public class LinkUtilTest extends TestCase {
026:
027: /**
028: *
029: */
030: public void testAppendQueryParam() throws Throwable {
031: String result = LinkUtil.appendQueryParam("", " ",
032: "testLinkUtilValue");
033: assertSame("result", "", result);
034: }
035:
036: /**
037: *
038: */
039: public void testAppendQueryParam1() throws Throwable {
040: String result = LinkUtil.appendQueryParam("testLinkUtilQuery",
041: "testLinkUtilParam", "");
042: assertEquals("result",
043: "?testLinkUtilQuery&testLinkUtilParam=", result);
044: }
045:
046: /**
047: *
048: */
049: public void testAppendQueryParam2() throws Throwable {
050: String result = LinkUtil.appendQueryParam("",
051: "testLinkUtilParam", "testLinkUtilValue");
052: assertEquals("result", "?testLinkUtilParam=testLinkUtilValue",
053: result);
054: }
055:
056: /**
057: *
058: */
059: public void testAppendQueryParam3() throws Throwable {
060: String result = LinkUtil.appendQueryParam("testLinkUtilQuery",
061: "", "testLinkUtilValue");
062: assertEquals("result", "?testLinkUtilQuery", result);
063: }
064:
065: /**
066: *
067: */
068: public void testAppendQueryParam4() throws Throwable {
069: String result = LinkUtil.appendQueryParam("?",
070: "testLinkUtilParam", "testLinkUtilValue");
071: assertEquals("result",
072: "?&testLinkUtilParam=testLinkUtilValue", result);
073: }
074:
075: /**
076: *
077: */
078: public void testAppendQueryParam5() throws Throwable {
079: String result = LinkUtil.appendQueryParam("testLinkUtilQuery",
080: "testLinkUtilParam", "testLinkUtilValue");
081: assertEquals(
082: "result",
083: "?testLinkUtilQuery&testLinkUtilParam=testLinkUtilValue",
084: result);
085: }
086:
087: /**
088: *
089: */
090: public void testAppendQueryParam6() throws Throwable {
091: String result = LinkUtil.appendQueryParam("",
092: "testLinkUtilParam", " ");
093: assertEquals("result", "?testLinkUtilParam=", result);
094: }
095:
096: /**
097: *
098: */
099: public void testAppendQueryParam7() throws Throwable {
100: String result = LinkUtil.appendQueryParam(null, "",
101: "testLinkUtilValue");
102: assertNull("result", result);
103: }
104:
105: /**
106: *
107: */
108: public void testBuildInternalLinkUrl() throws Throwable {
109: String result = LinkUtil.buildInternalLinkUrl(
110: "testLinkUtilContext", "testLinkUtilVirtualWiki", "");
111: assertNull("result", result);
112: }
113:
114: /**
115: *
116: */
117: public void testParseWikiLink() throws Throwable {
118: WikiLink result = LinkUtil.parseWikiLink("testLinkUtilRaw");
119: assertEquals("result.getArticle()", "testLinkUtilRaw", result
120: .getArticle());
121: }
122:
123: /**
124: *
125: */
126: public void testParseWikiLink1() throws Throwable {
127: WikiLink result = LinkUtil.parseWikiLink("");
128: assertNull("result.getArticle()", result.getArticle());
129: }
130:
131: /**
132: *
133: */
134: public void testInterWikiThrowsNullPointerException()
135: throws Throwable {
136: try {
137: LinkUtil.interWiki(null);
138: fail("Expected NullPointerException to be thrown");
139: } catch (NullPointerException ex) {
140: assertNull("ex.getMessage()", ex.getMessage());
141: }
142: }
143:
144: /**
145: *
146: */
147: public void testInterWikiThrowsStringIndexOutOfBoundsException()
148: throws Throwable {
149: WikiLink wikiLink = new WikiLink();
150: wikiLink.setNamespace("testLinkUtilNamespace");
151: wikiLink.setDestination("");
152: try {
153: LinkUtil.interWiki(wikiLink);
154: fail("Expected StringIndexOutOfBoundsException to be thrown");
155: } catch (StringIndexOutOfBoundsException ex) {
156: assertEquals("ex.getMessage()",
157: "String index out of range: -22", ex.getMessage());
158: }
159: }
160: }
|