Completed test migration to junit4, easymock updated to version 3.2

Change-Id: I6381045b3dae7133cc3589c5dd20ed977118a83d
This commit is contained in:
alex.ryazantsev
2013-11-07 22:29:27 +04:00
committed by Shawn Pearce
parent c8cffc8e92
commit d215908bae
46 changed files with 486 additions and 123 deletions

View File

@@ -67,6 +67,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
project2 = new Project.NameKey("p2");
createProject(sshSession, project2.get());
sshSession.close();
session = new RestSession(server, admin);
}

View File

@@ -74,6 +74,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
createProject(sshSession, p1.get());
Project.NameKey p2 = new Project.NameKey("p2");
createProject(sshSession, p2.get());
sshSession.close();
assertEquals(HttpStatus.SC_NOT_FOUND,
GET("/projects/" + p1.get() + "/children/" + p2.get()).getStatusCode());
}
@@ -83,6 +84,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
SshSession sshSession = new SshSession(server, admin);
Project.NameKey child = new Project.NameKey("p1");
createProject(sshSession, child.get());
sshSession.close();
RestResponse r = GET("/projects/" + allProjects.get() + "/children/" + child.get());
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
ProjectInfo childInfo =
@@ -98,6 +100,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
createProject(sshSession, child.get());
Project.NameKey grandChild = new Project.NameKey("p1.1");
createProject(sshSession, grandChild.get(), child);
sshSession.close();
assertEquals(HttpStatus.SC_NOT_FOUND,
GET("/projects/" + allProjects.get() + "/children/" + grandChild.get())
.getStatusCode());
@@ -111,6 +114,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
createProject(sshSession, child.get());
Project.NameKey grandChild = new Project.NameKey("p1.1");
createProject(sshSession, grandChild.get(), child);
sshSession.close();
RestResponse r =
GET("/projects/" + allProjects.get() + "/children/" + grandChild.get()
+ "?recursive");

View File

@@ -99,6 +99,7 @@ public class ListBranchesIT extends AbstractDaemonTest {
@After
public void cleanup() {
sshSession.close();
db.close();
}

View File

@@ -84,6 +84,7 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
Project.NameKey child2 = new Project.NameKey("p2");
createProject(sshSession, child2.get());
createProject(sshSession, "p1.1", child1);
sshSession.close();
RestResponse r = GET("/projects/" + allProjects.get() + "/children/");
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
@@ -107,6 +108,7 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
createProject(sshSession, child1_1_1.get(), child1_1);
Project.NameKey child1_1_1_1 = new Project.NameKey("p1.1.1.1");
createProject(sshSession, child1_1_1_1.get(), child1_1_1);
sshSession.close();
RestResponse r = GET("/projects/" + child1.get() + "/children/?recursive");
assertEquals(HttpStatus.SC_OK, r.getStatusCode());

View File

@@ -35,6 +35,7 @@ import com.google.inject.Inject;
import com.jcraft.jsch.JSchException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -83,6 +84,11 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
createProject(sshSession, project3.get());
}
@After
public void cleanup() {
sshSession.close();
}
@Test
@UseLocalDisk
public void testGc() throws JSchException, IOException {
@@ -110,6 +116,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
SshSession s = new SshSession(server, accounts.create("user", "user@example.com", "User"));
s.exec("gerrit gc --all");
assertError("Capability runGC is required to access this resource", s.getError());
s.close();
}
@Test

View File

@@ -14,10 +14,12 @@
package com.google.gerrit.common.data;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class EncodePathSeparatorTest extends TestCase {
public class EncodePathSeparatorTest {
@Test
public void testDefaultBehaviour() {
GitWebType gitWebType = GitWebType.fromName(null);
@@ -25,6 +27,7 @@ public class EncodePathSeparatorTest extends TestCase {
assertEquals("a/b", gitWebType.replacePathSeparator("a/b"));
}
@Test
public void testExclamationMark() {
GitWebType gitWebType = GitWebType.fromName(null);

View File

@@ -14,12 +14,17 @@
package com.google.gerrit.common.data;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class ParameterizedStringTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ParameterizedStringTest {
@Test
public void testEmptyString() {
final ParameterizedString p = new ParameterizedString("");
assertEquals("", p.getPattern());
@@ -32,6 +37,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("", p.replace(a));
}
@Test
public void testAsis1() {
final ParameterizedString p = ParameterizedString.asis("${bar}c");
assertEquals("${bar}c", p.getPattern());
@@ -45,6 +51,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("${bar}c", p.replace(a));
}
@Test
public void testReplace1() {
final ParameterizedString p = new ParameterizedString("${bar}c");
assertEquals("${bar}c", p.getPattern());
@@ -60,6 +67,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("frobinatorc", p.replace(a));
}
@Test
public void testReplace2() {
final ParameterizedString p = new ParameterizedString("a${bar}c");
assertEquals("a${bar}c", p.getPattern());
@@ -75,6 +83,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("afrobinatorc", p.replace(a));
}
@Test
public void testReplace3() {
final ParameterizedString p = new ParameterizedString("a${bar}");
assertEquals("a${bar}", p.getPattern());
@@ -90,6 +99,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("afrobinator", p.replace(a));
}
@Test
public void testReplace4() {
final ParameterizedString p = new ParameterizedString("a${bar}c");
assertEquals("a${bar}c", p.getPattern());
@@ -104,6 +114,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("ac", p.replace(a));
}
@Test
public void testReplaceToLowerCase() {
final ParameterizedString p = new ParameterizedString("${a.toLowerCase}");
assertEquals(1, p.getParameterNames().size());
@@ -124,6 +135,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo", p.replace(a));
}
@Test
public void testReplaceToUpperCase() {
final ParameterizedString p = new ParameterizedString("${a.toUpperCase}");
assertEquals(1, p.getParameterNames().size());
@@ -144,6 +156,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("FOO", p.replace(a));
}
@Test
public void testReplaceLocalName() {
final ParameterizedString p = new ParameterizedString("${a.localPart}");
assertEquals(1, p.getParameterNames().size());
@@ -164,6 +177,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo", p.replace(a));
}
@Test
public void testUndefinedFunctionName() {
ParameterizedString p =
new ParameterizedString(
@@ -183,6 +197,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("hi, FIRSTNAME LASTNAME,your eamil address is 'firstname.lastname'.right?", p.replace(a));
}
@Test
public void testReplaceToUpperCaseToLowerCase() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.toLowerCase}");
@@ -204,6 +219,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo@example.com", p.replace(a));
}
@Test
public void testReplaceToUpperCaseLocalName() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.localPart}");
@@ -225,6 +241,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("FOO", p.replace(a));
}
@Test
public void testReplaceToUpperCaseAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.anUndefinedMethod}");
@@ -246,6 +263,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("FOO@EXAMPLE.COM", p.replace(a));
}
@Test
public void testReplaceLocalNameToUpperCase() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.toUpperCase}");
@@ -267,6 +285,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("FOO", p.replace(a));
}
@Test
public void testReplaceLocalNameToLowerCase() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.toLowerCase}");
@@ -288,6 +307,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo", p.replace(a));
}
@Test
public void testReplaceLocalNameAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.anUndefinedMethod}");
@@ -309,6 +329,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo", p.replace(a));
}
@Test
public void testReplaceToLowerCaseToUpperCase() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.toUpperCase}");
@@ -330,6 +351,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("FOO@EXAMPLE.COM", p.replace(a));
}
@Test
public void testReplaceToLowerCaseLocalName() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.localPart}");
@@ -351,6 +373,7 @@ public class ParameterizedStringTest extends TestCase {
assertEquals("foo", p.replace(a));
}
@Test
public void testReplaceToLowerCaseAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.anUndefinedMethod}");

View File

@@ -15,10 +15,15 @@
package com.google.gwtexpui.safehtml.client;
import static com.google.gwtexpui.safehtml.client.LinkFindReplace.hasValidScheme;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase;
import org.junit.Test;
public class LinkFindReplaceTest extends TestCase {
public class LinkFindReplaceTest {
@Test
public void testNoEscaping() {
String find = "find";
String link = "link";
@@ -28,12 +33,14 @@ public class LinkFindReplaceTest extends TestCase {
assertEquals("find = " + find + ", link = " + link, a.toString());
}
@Test
public void testBackreference() {
assertEquals("<a href=\"/bug?id=123\">issue 123</a>",
new LinkFindReplace("(bug|issue)\\s*([0-9]+)", "/bug?id=$2")
.replace("issue 123"));
}
@Test
public void testHasValidScheme() {
assertTrue(hasValidScheme("/absolute/path"));
assertTrue(hasValidScheme("relative/path"));
@@ -46,6 +53,7 @@ public class LinkFindReplaceTest extends TestCase {
assertFalse(hasValidScheme("javascript:alert(1)"));
}
@Test
public void testInvalidSchemeInReplace() {
try {
new LinkFindReplace("find", "javascript:alert(1)").replace("find");
@@ -54,6 +62,7 @@ public class LinkFindReplaceTest extends TestCase {
}
}
@Test
public void testInvalidSchemeWithBackreference() {
try {
new LinkFindReplace(".*(script:[^;]*)", "java$1")
@@ -63,11 +72,13 @@ public class LinkFindReplaceTest extends TestCase {
}
}
@Test
public void testReplaceEscaping() {
assertEquals("<a href=\"a&quot;&amp;&#39;&lt;&gt;b\">find</a>",
new LinkFindReplace("find", "a\"&'<>b").replace("find"));
}
@Test
public void testHtmlInFind() {
String rawFind = "<b>&quot;bold&quot;</b>";
LinkFindReplace a = new LinkFindReplace(rawFind, "/bold");

View File

@@ -14,9 +14,11 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RawFindReplaceTest extends TestCase {
public class RawFindReplaceTest {
@Test
public void testFindReplace() {
final String find = "find";
final String replace = "replace";

View File

@@ -14,9 +14,18 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class SafeHtmlBuilderTest extends TestCase {
import org.junit.Test;
public class SafeHtmlBuilderTest {
@Test
public void testEmpty() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertTrue(b.isEmpty());
@@ -28,6 +37,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("a", b.asString());
}
@Test
public void testToSafeHtml() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
b.append(1);
@@ -39,6 +49,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("1", h.asString());
}
@Test
public void testAppend_boolean() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(true));
@@ -46,6 +57,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("truefalse", b.asString());
}
@Test
public void testAppend_char() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append('a'));
@@ -53,6 +65,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("ab", b.asString());
}
@Test
public void testAppend_int() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(4));
@@ -61,6 +74,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("42-100", b.asString());
}
@Test
public void testAppend_long() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(4L));
@@ -68,18 +82,21 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("42", b.asString());
}
@Test
public void testAppend_float() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(0.0f));
assertEquals("0.0", b.asString());
}
@Test
public void testAppend_double() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(0.0));
assertEquals("0.0", b.asString());
}
@Test
public void testAppend_String() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((String) null));
@@ -89,6 +106,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testAppend_StringBuilder() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((StringBuilder) null));
@@ -98,6 +116,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testAppend_StringBuffer() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((StringBuffer) null));
@@ -107,6 +126,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testAppend_Object() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((Object) null));
@@ -120,6 +140,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testAppend_CharSequence() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((CharSequence) null));
@@ -129,6 +150,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testAppend_SafeHtml() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((SafeHtml) null));
@@ -138,6 +160,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("foobar", b.asString());
}
@Test
public void testHtmlSpecialCharacters() {
assertEquals("&amp;", escape("&"));
assertEquals("&lt;", escape("<"));
@@ -155,18 +178,21 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("&amp;lt;b&amp;gt;", escape("&lt;b&gt;"));
}
@Test
public void testEntityNbsp() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.nbsp());
assertEquals("&nbsp;", b.asString());
}
@Test
public void testTagBr() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.br());
assertEquals("<br />", b.asString());
}
@Test
public void testTagTableTrTd() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openElement("table"));
@@ -179,6 +205,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("<table><tr><td>d&lt;a&gt;ta</td></tr></table>", b.asString());
}
@Test
public void testTagDiv() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openDiv());
@@ -187,6 +214,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("<div>d&lt;a&gt;ta</div>", b.asString());
}
@Test
public void testTagAnchor() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openAnchor());
@@ -206,6 +234,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("<a href=\"d&lt;a&gt;ta\">go</a>", b.asString());
}
@Test
public void testTagHeightWidth() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openElement("img"));
@@ -215,6 +244,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("<img height=\"100\" width=\"42\" />", b.asString());
}
@Test
public void testStyleName() {
final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openSpan());
@@ -225,6 +255,7 @@ public class SafeHtmlBuilderTest extends TestCase {
assertEquals("<span class=\"foo bar\">d&lt;a&gt;ta</span>", b.asString());
}
@Test
public void testRejectJavaScript_AnchorHref() {
final String href = "javascript:window.close();";
try {
@@ -235,6 +266,7 @@ public class SafeHtmlBuilderTest extends TestCase {
}
}
@Test
public void testRejectJavaScript_ImgSrc() {
final String href = "javascript:window.close();";
try {
@@ -245,6 +277,7 @@ public class SafeHtmlBuilderTest extends TestCase {
}
}
@Test
public void testRejectJavaScript_FormAction() {
final String href = "javascript:window.close();";
try {

View File

@@ -14,9 +14,13 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
public class SafeHtml_LinkifyTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
public class SafeHtml_LinkifyTest {
@Test
public void testLinkify_SimpleHttp1() {
final SafeHtml o = html("A http://go.here/ B");
final SafeHtml n = o.linkify();
@@ -24,6 +28,7 @@ public class SafeHtml_LinkifyTest extends TestCase {
assertEquals("A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B", n.asString());
}
@Test
public void testLinkify_SimpleHttps2() {
final SafeHtml o = html("A https://go.here/ B");
final SafeHtml n = o.linkify();
@@ -31,6 +36,7 @@ public class SafeHtml_LinkifyTest extends TestCase {
assertEquals("A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B", n.asString());
}
@Test
public void testLinkify_Parens1() {
final SafeHtml o = html("A (http://go.here/) B");
final SafeHtml n = o.linkify();
@@ -38,6 +44,7 @@ public class SafeHtml_LinkifyTest extends TestCase {
assertEquals("A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B", n.asString());
}
@Test
public void testLinkify_Parens() {
final SafeHtml o = html("A http://go.here/#m() B");
final SafeHtml n = o.linkify();
@@ -45,6 +52,7 @@ public class SafeHtml_LinkifyTest extends TestCase {
assertEquals("A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B", n.asString());
}
@Test
public void testLinkify_AngleBrackets1() {
final SafeHtml o = html("A <http://go.here/> B");
final SafeHtml n = o.linkify();

View File

@@ -14,19 +14,25 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class SafeHtml_ReplaceTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
public class SafeHtml_ReplaceTest {
@Test
public void testReplaceEmpty() {
SafeHtml o = html("A\nissue42\nB");
assertSame(o, o.replaceAll(null));
assertSame(o, o.replaceAll(Collections.<FindReplace> emptyList()));
}
@Test
public void testReplaceOneLink() {
SafeHtml o = html("A\nissue 42\nB");
SafeHtml n = o.replaceAll(repls(
@@ -35,6 +41,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
assertEquals("A\n<a href=\"?42\">issue 42</a>\nB", n.asString());
}
@Test
public void testReplaceNoLeadingOrTrailingText() {
SafeHtml o = html("issue 42");
SafeHtml n = o.replaceAll(repls(
@@ -43,6 +50,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
assertEquals("<a href=\"?42\">issue 42</a>", n.asString());
}
@Test
public void testReplaceTwoLinks() {
SafeHtml o = html("A\nissue 42\nissue 9918\nB");
SafeHtml n = o.replaceAll(repls(
@@ -55,6 +63,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
, n.asString());
}
@Test
public void testReplaceInOrder() {
SafeHtml o = html("A\nissue 42\nReally GWTEXPUI-9918 is better\nB");
SafeHtml n = o.replaceAll(repls(
@@ -70,6 +79,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
, n.asString());
}
@Test
public void testReplaceOverlappingAfterFirstChar() {
SafeHtml o = html("abcd");
RawFindReplace ab = new RawFindReplace("ab", "AB");
@@ -81,6 +91,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
assertEquals("ABYZ", o.replaceAll(repls(ab, bc, cd)).asString());
}
@Test
public void testReplaceOverlappingAtFirstCharLongestMatch() {
SafeHtml o = html("abcd");
RawFindReplace ab = new RawFindReplace("ab", "AB");
@@ -90,6 +101,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
assertEquals("234d", o.replaceAll(repls(abc, ab)).asString());
}
@Test
public void testReplaceOverlappingAtFirstCharFirstMatch() {
SafeHtml o = html("abcd");
RawFindReplace ab1 = new RawFindReplace("ab", "AB");
@@ -99,6 +111,7 @@ public class SafeHtml_ReplaceTest extends TestCase {
assertEquals("12cd", o.replaceAll(repls(ab2, ab1)).asString());
}
@Test
public void testFailedSanitization() {
SafeHtml o = html("abcd");
LinkFindReplace evil = new LinkFindReplace("(b)", "javascript:alert('$1')");

View File

@@ -14,9 +14,12 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
public class SafeHtml_WikifyListTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
public class SafeHtml_WikifyListTest {
private static final String BEGIN_LIST = "<ul class=\"wikiList\">";
private static final String END_LIST = "</ul>";
@@ -24,6 +27,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
return "<li>" + raw + "</li>";
}
@Test
public void testBulletList1() {
final SafeHtml o = html("A\n\n* line 1\n* 2nd line");
final SafeHtml n = o.wikify();
@@ -36,6 +40,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testBulletList2() {
final SafeHtml o = html("A\n\n* line 1\n* 2nd line\n\nB");
final SafeHtml n = o.wikify();
@@ -49,6 +54,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testBulletList3() {
final SafeHtml o = html("* line 1\n* 2nd line\n\nB");
final SafeHtml n = o.wikify();
@@ -61,6 +67,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testBulletList4() {
final SafeHtml o = html("To see this bug, you have to:\n" //
+ "* Be on IMAP or EAS (not on POP)\n"//
@@ -75,6 +82,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testBulletList5() {
final SafeHtml o = html("To see this bug,\n" //
+ "you have to:\n" //
@@ -90,6 +98,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testDashList1() {
final SafeHtml o = html("A\n\n- line 1\n- 2nd line");
final SafeHtml n = o.wikify();
@@ -102,6 +111,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testDashList2() {
final SafeHtml o = html("A\n\n- line 1\n- 2nd line\n\nB");
final SafeHtml n = o.wikify();
@@ -115,6 +125,7 @@ public class SafeHtml_WikifyListTest extends TestCase {
, n.asString());
}
@Test
public void testDashList3() {
final SafeHtml o = html("- line 1\n- 2nd line\n\nB");
final SafeHtml n = o.wikify();

View File

@@ -14,9 +14,12 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
public class SafeHtml_WikifyPreformatTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
public class SafeHtml_WikifyPreformatTest {
private static final String B = "<span class=\"wikiPreFormat\">";
private static final String E = "</span><br />";
@@ -24,6 +27,7 @@ public class SafeHtml_WikifyPreformatTest extends TestCase {
return B + raw + E;
}
@Test
public void testPreformat1() {
final SafeHtml o = html("A\n\n This is pre\n formatted");
final SafeHtml n = o.wikify();
@@ -36,6 +40,7 @@ public class SafeHtml_WikifyPreformatTest extends TestCase {
, n.asString());
}
@Test
public void testPreformat2() {
final SafeHtml o = html("A\n\n This is pre\n formatted\n\nbut this is not");
final SafeHtml n = o.wikify();
@@ -49,6 +54,7 @@ public class SafeHtml_WikifyPreformatTest extends TestCase {
, n.asString());
}
@Test
public void testPreformat3() {
final SafeHtml o = html("A\n\n Q\n <R>\n S\n\nB");
final SafeHtml n = o.wikify();
@@ -63,6 +69,7 @@ public class SafeHtml_WikifyPreformatTest extends TestCase {
, n.asString());
}
@Test
public void testPreformat4() {
final SafeHtml o = html(" Q\n <R>\n S\n\nB");
final SafeHtml n = o.wikify();

View File

@@ -14,9 +14,13 @@
package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import org.junit.Test;
public class SafeHtml_WikifyTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
public class SafeHtml_WikifyTest {
@Test
public void testWikify_OneLine1() {
final SafeHtml o = html("A B");
final SafeHtml n = o.wikify();
@@ -24,6 +28,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A B</p>", n.asString());
}
@Test
public void testWikify_OneLine2() {
final SafeHtml o = html("A B\n");
final SafeHtml n = o.wikify();
@@ -31,6 +36,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A B\n</p>", n.asString());
}
@Test
public void testWikify_OneParagraph1() {
final SafeHtml o = html("A\nB");
final SafeHtml n = o.wikify();
@@ -38,6 +44,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A\nB</p>", n.asString());
}
@Test
public void testWikify_OneParagraph2() {
final SafeHtml o = html("A\nB\n");
final SafeHtml n = o.wikify();
@@ -45,6 +52,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A\nB\n</p>", n.asString());
}
@Test
public void testWikify_TwoParagraphs() {
final SafeHtml o = html("A\nB\n\nC\nD");
final SafeHtml n = o.wikify();
@@ -52,6 +60,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A\nB</p><p>C\nD</p>", n.asString());
}
@Test
public void testLinkify_SimpleHttp1() {
final SafeHtml o = html("A http://go.here/ B");
final SafeHtml n = o.wikify();
@@ -59,6 +68,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B</p>", n.asString());
}
@Test
public void testLinkify_SimpleHttps2() {
final SafeHtml o = html("A https://go.here/ B");
final SafeHtml n = o.wikify();
@@ -66,6 +76,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B</p>", n.asString());
}
@Test
public void testLinkify_Parens1() {
final SafeHtml o = html("A (http://go.here/) B");
final SafeHtml n = o.wikify();
@@ -73,6 +84,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B</p>", n.asString());
}
@Test
public void testLinkify_Parens() {
final SafeHtml o = html("A http://go.here/#m() B");
final SafeHtml n = o.wikify();
@@ -80,6 +92,7 @@ public class SafeHtml_WikifyTest extends TestCase {
assertEquals("<p>A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B</p>", n.asString());
}
@Test
public void testLinkify_AngleBrackets1() {
final SafeHtml o = html("A <http://go.here/> B");
final SafeHtml n = o.wikify();

View File

@@ -14,19 +14,24 @@
package com.google.gerrit.httpd;
import junit.framework.TestCase;
import org.junit.Test;
public class GitWebConfigTest extends TestCase {
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class GitWebConfigTest {
private static final String VALID_CHARACTERS = "*()";
private static final String SOME_INVALID_CHARACTERS = "09AZaz$-_.+!',";
@Test
public void testValidPathSeparator() {
for(char c : VALID_CHARACTERS.toCharArray()) {
assertTrue("valid character rejected: " + c, GitWebConfig.isValidPathSeparator(c));
}
}
@Test
public void testInalidPathSeparator() {
for(char c : SOME_INVALID_CHARACTERS.toCharArray()) {
assertFalse("invalid character accepted: " + c, GitWebConfig.isValidPathSeparator(c));

View File

@@ -21,9 +21,11 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ParameterParserTest extends TestCase {
public class ParameterParserTest {
@Test
public void testConvertFormToJson() throws BadRequestException {
JsonObject obj = ParameterParser.formToJson(
ImmutableMap.of(

View File

@@ -14,11 +14,11 @@
package org.eclipse.jgit.diff;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import org.eclipse.jgit.diff.EditDeserializer;
public class EditDeserializerTest extends TestCase {
public class EditDeserializerTest {
@Test
public void testDiffDeserializer() {
assertNotNull("edit deserializer", new EditDeserializer());
}

View File

@@ -21,13 +21,14 @@ import static org.easymock.EasyMock.verify;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Provider;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.FileNotFoundException;
public class LibrariesTest extends TestCase {
public class LibrariesTest {
@Test
public void testCreate() throws FileNotFoundException {
final SitePaths site = new SitePaths(new File("."));
final ConsoleUI ui = createStrictMock(ConsoleUI.class);

View File

@@ -145,6 +145,7 @@ java_test(
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-reviewdb:server',
'//lib:args4j',
'//lib:easymock',
'//lib:guava',
'//lib:gwtorm',

View File

@@ -29,6 +29,8 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.AbstractModule;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
@@ -46,9 +48,8 @@ public class GerritCommonTest extends PrologTestCase {
private ProjectConfig local;
private Util util;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
util = new Util();
load("gerrit", "gerrit_common_test.pl", new AbstractModule() {
@Override
@@ -86,6 +87,7 @@ public class GerritCommonTest extends PrologTestCase {
env.set(StoredValues.CHANGE_CONTROL, util.user(local).controlFor(change));
}
@Test
public void testGerritCommon() {
runPrologBasedTests();
}

View File

@@ -29,8 +29,6 @@ import com.googlecode.prolog_cafe.lang.SymbolTerm;
import com.googlecode.prolog_cafe.lang.Term;
import com.googlecode.prolog_cafe.lang.VariableTerm;
import junit.framework.TestCase;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -41,9 +39,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** Base class for any tests written in Prolog. */
public abstract class PrologTestCase extends TestCase {
public abstract class PrologTestCase {
private static final SymbolTerm test_1 = SymbolTerm.intern("test", 1);
private String pkg;

View File

@@ -14,13 +14,16 @@
package com.google.gerrit.server;
import junit.framework.TestCase;
import org.junit.Test;
public class StringUtilTest extends TestCase {
import static org.junit.Assert.assertEquals;
public class StringUtilTest {
/**
* Test the boundary condition that the first character of a string
* should be escaped.
*/
@Test
public void testEscapeFirstChar() {
assertEquals(StringUtil.escapeString("\tLeading tab"), "\\tLeading tab");
}
@@ -29,6 +32,7 @@ public class StringUtilTest extends TestCase {
* Test the boundary condition that the last character of a string
* should be escaped.
*/
@Test
public void testEscapeLastChar() {
assertEquals(StringUtil.escapeString("Trailing tab\t"), "Trailing tab\\t");
}
@@ -37,6 +41,7 @@ public class StringUtilTest extends TestCase {
* Test that various forms of input strings are escaped (or left as-is)
* in the expected way.
*/
@Test
public void testEscapeString() {
final String[] testPairs =
{ "", "",

View File

@@ -18,6 +18,9 @@ import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
@@ -46,9 +49,9 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
import junit.framework.TestCase;
import org.easymock.IAnswer;
import org.junit.Before;
import org.junit.Test;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -56,7 +59,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
public class CommentsTest extends TestCase {
public class CommentsTest {
private Injector injector;
private RevisionResource revRes1;
@@ -65,8 +68,8 @@ public class CommentsTest extends TestCase {
private PatchLineComment plc2;
private PatchLineComment plc3;
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
@SuppressWarnings("unchecked")
final DynamicMap<RestView<CommentResource>> views =
createMock(DynamicMap.class);
@@ -130,6 +133,7 @@ public class CommentsTest extends TestCase {
injector = Guice.createInjector(mod);
}
@Test
public void testListComments() throws Exception {
// test ListComments for patch set 1
assertListComments(injector, revRes1, ImmutableMap.of(
@@ -140,6 +144,7 @@ public class CommentsTest extends TestCase {
Collections.<String, ArrayList<PatchLineComment>>emptyMap());
}
@Test
public void testGetComment() throws Exception {
// test GetComment for existing comment
assertGetComment(injector, revRes1, plc1, plc1.getKey().get());

View File

@@ -14,17 +14,19 @@
package com.google.gerrit.server.config;
import org.junit.Test;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
public class ConfigUtilTest extends TestCase {
public class ConfigUtilTest {
@Test
public void testTimeUnit() {
assertEquals(ms(0, MILLISECONDS), parse("0"));
assertEquals(ms(2, MILLISECONDS), parse("2ms"));

View File

@@ -14,15 +14,23 @@
package com.google.gerrit.server.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.gerrit.server.util.HostPlatform;
import junit.framework.TestCase;
import org.junit.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class SitePathsTest extends TestCase {
public class SitePathsTest {
@Test
public void testCreate_NotExisting() throws IOException {
final File root = random();
final SitePaths site = new SitePaths(root);
@@ -31,6 +39,7 @@ public class SitePathsTest extends TestCase {
assertEquals(new File(root, "etc"), site.etc_dir);
}
@Test
public void testCreate_Empty() throws IOException {
final File root = random();
try {
@@ -44,6 +53,7 @@ public class SitePathsTest extends TestCase {
}
}
@Test
public void testCreate_NonEmpty() throws IOException {
final File root = random();
final File txt = new File(root, "test.txt");
@@ -60,6 +70,7 @@ public class SitePathsTest extends TestCase {
}
}
@Test
public void testCreate_NotDirectory() throws IOException {
final File root = random();
try {
@@ -75,6 +86,7 @@ public class SitePathsTest extends TestCase {
}
}
@Test
public void testResolve() throws IOException {
final File root = random();
final SitePaths site = new SitePaths(root);

View File

@@ -19,6 +19,9 @@ import static com.google.gerrit.reviewdb.client.Change.Status.DRAFT;
import static com.google.gerrit.reviewdb.client.Change.Status.MERGED;
import static com.google.gerrit.reviewdb.client.Change.Status.NEW;
import static com.google.gerrit.reviewdb.client.Change.Status.SUBMITTED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.reviewdb.client.Change;
@@ -31,22 +34,21 @@ import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gerrit.server.query.change.OrSource;
import com.google.gerrit.server.query.change.SqlRewriterImpl;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import java.util.EnumSet;
import java.util.Set;
@SuppressWarnings("unchecked")
public class IndexRewriteTest extends TestCase {
public class IndexRewriteTest {
private FakeIndex index;
private IndexCollection indexes;
private ChangeQueryBuilder queryBuilder;
private IndexRewriteImpl rewrite;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
index = new FakeIndex(FakeIndex.V2);
indexes = new IndexCollection();
indexes.setSearchIndex(index);
@@ -58,26 +60,31 @@ public class IndexRewriteTest extends TestCase {
new SqlRewriterImpl(null));
}
@Test
public void testIndexPredicate() throws Exception {
Predicate<ChangeData> in = parse("file:a");
assertEquals(query(in), rewrite(in));
}
@Test
public void testNonIndexPredicate() throws Exception {
Predicate<ChangeData> in = parse("foo:a");
assertSame(in, rewrite(in));
}
@Test
public void testIndexPredicates() throws Exception {
Predicate<ChangeData> in = parse("file:a file:b");
assertEquals(query(in), rewrite(in));
}
@Test
public void testNonIndexPredicates() throws Exception {
Predicate<ChangeData> in = parse("foo:a OR foo:b");
assertEquals(in, rewrite(in));
}
@Test
public void testOneIndexPredicate() throws Exception {
Predicate<ChangeData> in = parse("foo:a file:b");
Predicate<ChangeData> out = rewrite(in);
@@ -87,6 +94,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testThreeLevelTreeWithAllIndexPredicates() throws Exception {
Predicate<ChangeData> in =
parse("-status:abandoned (status:open OR status:merged)");
@@ -95,6 +103,7 @@ public class IndexRewriteTest extends TestCase {
rewrite.rewrite(in));
}
@Test
public void testThreeLevelTreeWithSomeIndexPredicates() throws Exception {
Predicate<ChangeData> in = parse("-foo:a (file:b OR file:c)");
Predicate<ChangeData> out = rewrite(in);
@@ -104,6 +113,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testMultipleIndexPredicates() throws Exception {
Predicate<ChangeData> in =
parse("file:a OR foo:b OR file:c OR foo:d");
@@ -115,6 +125,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testIndexAndNonIndexPredicates() throws Exception {
Predicate<ChangeData> in = parse("status:new bar:p file:a");
Predicate<ChangeData> out = rewrite(in);
@@ -125,6 +136,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testDuplicateCompoundNonIndexOnlyPredicates() throws Exception {
Predicate<ChangeData> in =
parse("(status:new OR status:draft) bar:p file:a");
@@ -136,6 +148,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testDuplicateCompoundIndexOnlyPredicates() throws Exception {
Predicate<ChangeData> in =
parse("(status:new OR file:a) bar:p file:b");
@@ -147,6 +160,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testLimit() throws Exception {
Predicate<ChangeData> in = parse("file:a limit:3");
Predicate<ChangeData> out = rewrite(in);
@@ -157,6 +171,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testGetPossibleStatus() throws Exception {
assertEquals(EnumSet.allOf(Change.Status.class), status("file:a"));
assertEquals(EnumSet.of(NEW), status("is:new"));
@@ -173,6 +188,7 @@ public class IndexRewriteTest extends TestCase {
status("(is:new is:draft) OR (is:merged OR is:submitted)"));
}
@Test
public void testUnsupportedIndexOperator() throws Exception {
Predicate<ChangeData> in = parse("status:merged file:a");
assertEquals(query(in), rewrite(in));
@@ -186,6 +202,7 @@ public class IndexRewriteTest extends TestCase {
out.getChildren());
}
@Test
public void testNoChangeIndexUsesSqlRewrites() throws Exception {
Predicate<ChangeData> in = parse("status:open project:p ref:b");
Predicate<ChangeData> out;

View File

@@ -15,32 +15,35 @@
package com.google.gerrit.server.index;
import static com.google.gerrit.server.index.IndexedChangeQuery.replaceSortKeyPredicates;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;
public class IndexedChangeQueryTest extends TestCase {
public class IndexedChangeQueryTest {
private FakeIndex index;
private ChangeQueryBuilder queryBuilder;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
index = new FakeIndex(FakeIndex.V2);
IndexCollection indexes = new IndexCollection();
indexes.setSearchIndex(index);
queryBuilder = new FakeQueryBuilder(indexes);
}
@Test
public void testReplaceSortKeyPredicate_NoSortKey() throws Exception {
Predicate<ChangeData> p = parse("foo:a bar:b OR (foo:b bar:a)");
assertSame(p, replaceSortKeyPredicates(p, "1234"));
}
@Test
public void testReplaceSortKeyPredicate_TopLevelSortKey() throws Exception {
Predicate<ChangeData> p;
p = parse("foo:a bar:b sortkey_before:1234 OR (foo:b bar:a)");
@@ -51,6 +54,7 @@ public class IndexedChangeQueryTest extends TestCase {
replaceSortKeyPredicates(p, "5678"));
}
@Test
public void testReplaceSortKeyPredicate_NestedSortKey() throws Exception {
Predicate<ChangeData> p;
p = parse("foo:a bar:b OR (foo:b bar:a AND sortkey_before:1234)");

View File

@@ -14,27 +14,31 @@
package com.google.gerrit.server.ioutil;
import org.junit.Test;
import static com.google.gerrit.server.ioutil.BasicSerialization.readFixInt64;
import static com.google.gerrit.server.ioutil.BasicSerialization.readString;
import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeFixInt64;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeString;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class BasicSerializationTest extends TestCase {
public class BasicSerializationTest {
@Test
public void testReadVarInt32() throws IOException {
assertEquals(0x00000000, readVarInt32(r(b(0))));
assertEquals(0x00000003, readVarInt32(r(b(3))));
assertEquals(0x000000ff, readVarInt32(r(b(0x80 | 0x7f, 0x01))));
}
@Test
public void testWriteVarInt32() throws IOException {
ByteArrayOutputStream out;
@@ -51,6 +55,7 @@ public class BasicSerializationTest extends TestCase {
assertOutput(b(0x80 | 0x7f, 0x01), out);
}
@Test
public void testReadFixInt64() throws IOException {
assertEquals(0L, readFixInt64(r(b(0, 0, 0, 0, 0, 0, 0, 0))));
assertEquals(3L, readFixInt64(r(b(0, 0, 0, 0, 0, 0, 0, 3))));
@@ -71,6 +76,7 @@ public class BasicSerializationTest extends TestCase {
0xff, 0xff, 0xff, 0xff))));
}
@Test
public void testWriteFixInt64() throws IOException {
ByteArrayOutputStream out;
@@ -99,6 +105,7 @@ public class BasicSerializationTest extends TestCase {
assertOutput(b(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), out);
}
@Test
public void testReadString() throws IOException {
assertNull(readString(r(b(0))));
assertEquals("a", readString(r(b(1, 'a'))));
@@ -106,6 +113,7 @@ public class BasicSerializationTest extends TestCase {
readString(r(b(7, 'c', 'o', 'f', 'f', 'e', 'e', '4'))));
}
@Test
public void testWriteString() throws IOException {
ByteArrayOutputStream out;

View File

@@ -14,12 +14,13 @@
package com.google.gerrit.server.ioutil;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import java.io.PrintWriter;
import java.io.StringWriter;
public class ColumnFormatterTest extends TestCase {
public class ColumnFormatterTest {
/**
* Holds an in-memory {@link java.io.PrintWriter} object and allows
* comparisons of its contents to a supplied string via an assert statement.
@@ -35,7 +36,7 @@ public class ColumnFormatterTest extends TestCase {
public void assertEquals(String str) {
printWriter.flush();
TestCase.assertEquals(stringWriter.toString(), str);
Assert.assertEquals(stringWriter.toString(), str);
}
public PrintWriter getPrintWriter() {
@@ -46,6 +47,7 @@ public class ColumnFormatterTest extends TestCase {
/**
* Test that only lines with at least one column of text emit output.
*/
@Test
public void testEmptyLine() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =
@@ -64,6 +66,7 @@ public class ColumnFormatterTest extends TestCase {
/**
* Test that there is no output if no columns are ever added.
*/
@Test
public void testEmptyOutput() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =
@@ -78,6 +81,7 @@ public class ColumnFormatterTest extends TestCase {
* Test that there is no output (nor any exceptions) if we finalize
* the output immediately after the creation of the {@link ColumnFormatter}.
*/
@Test
public void testNoNextLine() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =
@@ -90,6 +94,7 @@ public class ColumnFormatterTest extends TestCase {
* Test that the text in added columns is escaped while the column separator
* (which of course shouldn't be escaped) is left alone.
*/
@Test
public void testEscapingTakesPlace() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =
@@ -106,6 +111,7 @@ public class ColumnFormatterTest extends TestCase {
* Test that we get the correct output with multi-line input where the number
* of columns in each line varies.
*/
@Test
public void testMultiLineDifferentColumnCount() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =
@@ -124,6 +130,7 @@ public class ColumnFormatterTest extends TestCase {
/**
* Test that we get the correct output with a single column of input.
*/
@Test
public void testOneColumn() {
final PrintWriterComparator comparator = new PrintWriterComparator();
final ColumnFormatter formatter =

View File

@@ -14,53 +14,65 @@
package com.google.gerrit.server.mail;
import junit.framework.TestCase;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
public class AddressTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
public class AddressTest {
@Test
public void testParse_NameEmail1() {
final Address a = Address.parse("A U Thor <author@example.com>");
assertEquals("A U Thor", a.name);
assertEquals("author@example.com", a.email);
}
@Test
public void testParse_NameEmail2() {
final Address a = Address.parse("A <a@b>");
assertEquals("A", a.name);
assertEquals("a@b", a.email);
}
@Test
public void testParse_NameEmail3() {
final Address a = Address.parse("<a@b>");
assertNull(a.name);
assertEquals("a@b", a.email);
}
@Test
public void testParse_NameEmail4() {
final Address a = Address.parse("A U Thor<author@example.com>");
assertEquals("A U Thor", a.name);
assertEquals("author@example.com", a.email);
}
@Test
public void testParse_NameEmail5() {
final Address a = Address.parse("A U Thor <author@example.com>");
assertEquals("A U Thor", a.name);
assertEquals("author@example.com", a.email);
}
@Test
public void testParse_Email1() {
final Address a = Address.parse("author@example.com");
assertNull(a.name);
assertEquals("author@example.com", a.email);
}
@Test
public void testParse_Email2() {
final Address a = Address.parse("a@b");
assertNull(a.name);
assertEquals("a@b", a.email);
}
@Test
public void testParseInvalid() {
assertInvalid("");
assertInvalid("a");
@@ -88,34 +100,42 @@ public class AddressTest extends TestCase {
}
}
@Test
public void testToHeaderString_NameEmail1() {
assertEquals("A <a@a>", format("A", "a@a"));
}
@Test
public void testToHeaderString_NameEmail2() {
assertEquals("A B <a@a>", format("A B", "a@a"));
}
@Test
public void testToHeaderString_NameEmail3() {
assertEquals("\"A B. C\" <a@a>", format("A B. C", "a@a"));
}
@Test
public void testToHeaderString_NameEmail4() {
assertEquals("\"A B, C\" <a@a>", format("A B, C", "a@a"));
}
@Test
public void testToHeaderString_NameEmail5() {
assertEquals("\"A \\\" C\" <a@a>", format("A \" C", "a@a"));
}
@Test
public void testToHeaderString_NameEmail6() {
assertEquals("=?UTF-8?Q?A_=E2=82=AC_B?= <a@a>", format("A \u20ac B", "a@a"));
}
@Test
public void testToHeaderString_Email1() {
assertEquals("a@a", format(null, "a@a"));
}
@Test
public void testToHeaderString_Email2() {
assertEquals("<a,b@a>", format(null, "a,b@a"));
}

View File

@@ -19,6 +19,9 @@ import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountExternalId;
@@ -27,21 +30,20 @@ import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.util.TimeUtil;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.PersonIdent;
import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
public class FromAddressGeneratorProviderTest extends TestCase {
public class FromAddressGeneratorProviderTest {
private Config config;
private PersonIdent ident;
private AccountCache accountCache;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
config = new Config();
ident = new PersonIdent("NAME", "e@email", 0, 0);
accountCache = createStrictMock(AccountCache.class);
@@ -56,10 +58,12 @@ public class FromAddressGeneratorProviderTest extends TestCase {
config.setString("sendemail", null, "from", newFrom);
}
@Test
public void testDefaultIsMIXED() {
assertTrue(create() instanceof FromAddressGeneratorProvider.PatternGen);
}
@Test
public void testSelectUSER() {
setFrom("USER");
assertTrue(create() instanceof FromAddressGeneratorProvider.UserGen);
@@ -71,6 +75,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
assertTrue(create() instanceof FromAddressGeneratorProvider.UserGen);
}
@Test
public void testUSER_FullyConfiguredUser() {
setFrom("USER");
@@ -86,6 +91,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testUSER_NoFullNameUser() {
setFrom("USER");
@@ -100,6 +106,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testUSER_NoPreferredEmailUser() {
setFrom("USER");
@@ -114,6 +121,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testUSER_NullUser() {
setFrom("USER");
replay(accountCache);
@@ -124,6 +132,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testSelectSERVER() {
setFrom("SERVER");
assertTrue(create() instanceof FromAddressGeneratorProvider.ServerGen);
@@ -135,6 +144,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
assertTrue(create() instanceof FromAddressGeneratorProvider.ServerGen);
}
@Test
public void testSERVER_FullyConfiguredUser() {
setFrom("SERVER");
@@ -150,6 +160,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testSERVER_NullUser() {
setFrom("SERVER");
replay(accountCache);
@@ -160,6 +171,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testSelectMIXED() {
setFrom("MIXED");
assertTrue(create() instanceof FromAddressGeneratorProvider.PatternGen);
@@ -171,6 +183,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
assertTrue(create() instanceof FromAddressGeneratorProvider.PatternGen);
}
@Test
public void testMIXED_FullyConfiguredUser() {
setFrom("MIXED");
@@ -186,6 +199,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testMIXED_NoFullNameUser() {
setFrom("MIXED");
@@ -200,6 +214,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testMIXED_NoPreferredEmailUser() {
setFrom("MIXED");
@@ -214,6 +229,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testMIXED_NullUser() {
setFrom("MIXED");
replay(accountCache);
@@ -224,6 +240,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testCUSTOM_FullyConfiguredUser() {
setFrom("A ${user} B <my.server@email.address>");
@@ -239,6 +256,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testCUSTOM_NoFullNameUser() {
setFrom("A ${user} B <my.server@email.address>");
@@ -253,6 +271,7 @@ public class FromAddressGeneratorProviderTest extends TestCase {
verify(accountCache);
}
@Test
public void testCUSTOM_NullUser() {
setFrom("A ${user} B <my.server@email.address>");

View File

@@ -12,14 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.patch;
import com.google.gerrit.reviewdb.client.Patch;
import org.junit.Test;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class PatchListEntryTest extends TestCase {
public class PatchListEntryTest {
@Test
public void testEmpty1() {
final String name = "empty-file";
final PatchListEntry e = PatchListEntry.empty(name);

View File

@@ -26,6 +26,8 @@ import static com.google.gerrit.server.project.Util.ADMIN;
import static com.google.gerrit.server.project.Util.DEVS;
import static com.google.gerrit.server.project.Util.grant;
import static com.google.gerrit.server.project.Util.doNotInherit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.common.data.PermissionRange;
@@ -33,10 +35,10 @@ import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.ProjectConfig;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;
public class RefControlTest extends TestCase {
public class RefControlTest {
private static void assertOwner(String ref, ProjectControl u) {
assertTrue("OWN " + ref, u.controlForRef(ref).isOwner());
}
@@ -54,14 +56,14 @@ public class RefControlTest extends TestCase {
util = new Util();
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
local = new ProjectConfig(localKey);
local.createInMemory();
util.add(local);
}
@Test
public void testOwnerProject() {
grant(local, OWNER, ADMIN, "refs/*");
@@ -72,6 +74,7 @@ public class RefControlTest extends TestCase {
assertTrue("is owner", uAdmin.isOwner());
}
@Test
public void testBranchDelegation1() {
grant(local, OWNER, ADMIN, "refs/*");
grant(local, OWNER, DEVS, "refs/heads/x/*");
@@ -88,6 +91,7 @@ public class RefControlTest extends TestCase {
assertNotOwner("refs/heads/master", uDev);
}
@Test
public void testBranchDelegation2() {
grant(local, OWNER, ADMIN, "refs/*");
grant(local, OWNER, DEVS, "refs/heads/x/*");
@@ -116,6 +120,7 @@ public class RefControlTest extends TestCase {
assertNotOwner("refs/heads/master", uFix);
}
@Test
public void testInheritRead_SingleBranchDeniesUpload() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(util.getParentConfig(), PUSH, REGISTERED, "refs/for/refs/*");
@@ -133,6 +138,7 @@ public class RefControlTest extends TestCase {
u.controlForRef("refs/heads/foobar").canUpload());
}
@Test
public void testInheritRead_SingleBranchDoesNotOverrideInherited() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(util.getParentConfig(), PUSH, REGISTERED, "refs/for/refs/*");
@@ -148,6 +154,7 @@ public class RefControlTest extends TestCase {
u.controlForRef("refs/heads/foobar").canUpload());
}
@Test
public void testInheritDuplicateSections() {
grant(util.getParentConfig(), READ, ADMIN, "refs/*");
grant(local, READ, DEVS, "refs/heads/*");
@@ -160,6 +167,7 @@ public class RefControlTest extends TestCase {
assertTrue("d can read", util.user(local, "d", DEVS).isVisible());
}
@Test
public void testInheritRead_OverrideWithDeny() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(local, READ, REGISTERED, "refs/*").setDeny();
@@ -168,6 +176,7 @@ public class RefControlTest extends TestCase {
assertFalse("can't read", u.isVisible());
}
@Test
public void testInheritRead_AppendWithDenyOfRef() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(local, READ, REGISTERED, "refs/heads/*").setDeny();
@@ -179,6 +188,7 @@ public class RefControlTest extends TestCase {
assertTrue("no master", u.controlForRef("refs/heads/master").isVisible());
}
@Test
public void testInheritRead_OverridesAndDeniesOfRef() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(local, READ, REGISTERED, "refs/*").setDeny();
@@ -191,6 +201,7 @@ public class RefControlTest extends TestCase {
assertTrue("can read", u.controlForRef("refs/heads/foobar").isVisible());
}
@Test
public void testInheritSubmit_OverridesAndDeniesOfRef() {
grant(util.getParentConfig(), SUBMIT, REGISTERED, "refs/*");
grant(local, SUBMIT, REGISTERED, "refs/*").setDeny();
@@ -202,6 +213,7 @@ public class RefControlTest extends TestCase {
assertTrue("can submit", u.controlForRef("refs/heads/foobar").canSubmit());
}
@Test
public void testCannotUploadToAnyRef() {
grant(util.getParentConfig(), READ, REGISTERED, "refs/*");
grant(local, READ, DEVS, "refs/heads/*");
@@ -213,6 +225,7 @@ public class RefControlTest extends TestCase {
u.controlForRef("refs/heads/master").canUpload());
}
@Test
public void testUsernamePatternNonRegex() {
grant(local, READ, DEVS, "refs/sb/${username}/heads/*");
@@ -221,6 +234,7 @@ public class RefControlTest extends TestCase {
assertTrue("d can read", d.controlForRef("refs/sb/d/heads/foobar").isVisible());
}
@Test
public void testUsernamePatternWithRegex() {
grant(local, READ, DEVS, "^refs/sb/${username}/heads/.*");
@@ -229,6 +243,7 @@ public class RefControlTest extends TestCase {
assertTrue("d can read", d.controlForRef("refs/sb/dev/heads/foobar").isVisible());
}
@Test
public void testSortWithRegex() {
grant(local, READ, DEVS, "^refs/heads/.*");
grant(util.getParentConfig(), READ, ANONYMOUS, "^refs/heads/.*-QA-.*");
@@ -238,6 +253,7 @@ public class RefControlTest extends TestCase {
assertTrue("d can read", d.controlForRef("refs/heads/foo-QA-bar").isVisible());
}
@Test
public void testBlockRule_ParentBlocksChild() {
grant(local, PUSH, DEVS, "refs/tags/*");
grant(util.getParentConfig(), PUSH, ANONYMOUS, "refs/tags/*").setBlock();
@@ -246,6 +262,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't force update tag", u.controlForRef("refs/tags/V10").canForceUpdate());
}
@Test
public void testBlockLabelRange_ParentBlocksChild() {
grant(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
grant(util.getParentConfig(), LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*").setBlock();
@@ -259,6 +276,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't vote 2", range.contains(2));
}
@Test
public void testUnblockNoForce() {
grant(local, PUSH, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, PUSH, DEVS, "refs/heads/*");
@@ -267,6 +285,7 @@ public class RefControlTest extends TestCase {
assertTrue("u can push", u.controlForRef("refs/heads/master").canUpdate());
}
@Test
public void testUnblockForce() {
PermissionRule r = grant(local, PUSH, ANONYMOUS, "refs/heads/*");
r.setBlock();
@@ -277,6 +296,7 @@ public class RefControlTest extends TestCase {
assertTrue("u can force push", u.controlForRef("refs/heads/master").canForceUpdate());
}
@Test
public void testUnblockForceWithAllowNoForce_NotPossible() {
PermissionRule r = grant(local, PUSH, ANONYMOUS, "refs/heads/*");
r.setBlock();
@@ -287,6 +307,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't force push", u.controlForRef("refs/heads/master").canForceUpdate());
}
@Test
public void testUnblockMoreSpecificRef_Fails() {
grant(local, PUSH, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, PUSH, DEVS, "refs/heads/master");
@@ -295,6 +316,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't push", u.controlForRef("refs/heads/master").canUpdate());
}
@Test
public void testUnblockLargerScope_Fails() {
grant(local, PUSH, ANONYMOUS, "refs/heads/master").setBlock();
grant(local, PUSH, DEVS, "refs/heads/*");
@@ -303,6 +325,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't push", u.controlForRef("refs/heads/master").canUpdate());
}
@Test
public void testUnblockInLocal_Fails() {
grant(util.getParentConfig(), PUSH, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, PUSH, fixers, "refs/heads/*");
@@ -311,6 +334,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't push", f.controlForRef("refs/heads/master").canUpdate());
}
@Test
public void testUnblockInParentBlockInLocal() {
grant(util.getParentConfig(), PUSH, ANONYMOUS, "refs/heads/*").setBlock();
grant(util.getParentConfig(), PUSH, DEVS, "refs/heads/*");
@@ -320,6 +344,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't push", d.controlForRef("refs/heads/master").canUpdate());
}
@Test
public void testUnblockVisibilityByREGISTEREDUsers() {
grant(local, READ, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, READ, REGISTERED, "refs/heads/*");
@@ -328,6 +353,7 @@ public class RefControlTest extends TestCase {
assertTrue("u can read", u.controlForRef("refs/heads/master").isVisibleByRegisteredUsers());
}
@Test
public void testUnblockInLocalVisibilityByRegisteredUsers_Fails() {
grant(util.getParentConfig(), READ, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, READ, REGISTERED, "refs/heads/*");
@@ -336,6 +362,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't read", u.controlForRef("refs/heads/master").isVisibleByRegisteredUsers());
}
@Test
public void testUnblockForceEditTopicName() {
grant(local, EDIT_TOPIC_NAME, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, EDIT_TOPIC_NAME, DEVS, "refs/heads/*").setForce(true);
@@ -345,6 +372,7 @@ public class RefControlTest extends TestCase {
.canForceEditTopicName());
}
@Test
public void testUnblockInLocalForceEditTopicName_Fails() {
grant(util.getParentConfig(), EDIT_TOPIC_NAME, ANONYMOUS, "refs/heads/*")
.setBlock();
@@ -355,6 +383,7 @@ public class RefControlTest extends TestCase {
.canForceEditTopicName());
}
@Test
public void testUnblockRange() {
grant(local, LABEL + "Code-Review", -1, +1, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
@@ -365,6 +394,7 @@ public class RefControlTest extends TestCase {
assertTrue("u can vote +2", range.contains(2));
}
@Test
public void testUnblockRangeOnMoreSpecificRef_Fails() {
grant(local, LABEL + "Code-Review", -1, +1, ANONYMOUS, "refs/heads/*").setBlock();
grant(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/master");
@@ -375,6 +405,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't vote +2", range.contains(-2));
}
@Test
public void testUnblockRangeOnLargerScope_Fails() {
grant(local, LABEL + "Code-Review", -1, +1, ANONYMOUS, "refs/heads/master").setBlock();
grant(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
@@ -385,6 +416,7 @@ public class RefControlTest extends TestCase {
assertFalse("u can't vote +2", range.contains(-2));
}
@Test
public void testUnblockInLocalRange_Fails() {
grant(util.getParentConfig(), LABEL + "Code-Review", -1, 1, ANONYMOUS,
"refs/heads/*").setBlock();

View File

@@ -15,14 +15,19 @@
package com.google.gerrit.server.query;
import static com.google.gerrit.server.query.Predicate.and;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class AndPredicateTest extends TestCase {
public class AndPredicateTest {
private static final class TestPredicate extends OperatorPredicate<String> {
private TestPredicate(String name, String value) {
super(name, value);
@@ -43,6 +48,7 @@ public class AndPredicateTest extends TestCase {
return new TestPredicate(name, value);
}
@Test
@SuppressWarnings("unchecked")
public void testChildren() {
final TestPredicate a = f("author", "alice");
@@ -53,6 +59,7 @@ public class AndPredicateTest extends TestCase {
assertSame(b, n.getChild(1));
}
@Test
@SuppressWarnings("unchecked")
public void testChildrenUnmodifiable() {
final TestPredicate a = f("author", "alice");
@@ -83,6 +90,7 @@ public class AndPredicateTest extends TestCase {
assertEquals(o + " did not affect child", l, p.getChildren());
}
@Test
@SuppressWarnings("unchecked")
public void testToString() {
final TestPredicate a = f("q", "alice");
@@ -92,6 +100,7 @@ public class AndPredicateTest extends TestCase {
assertEquals("(q:alice q:bob q:charlie)", and(a, b, c).toString());
}
@Test
@SuppressWarnings("unchecked")
public void testEquals() {
final TestPredicate a = f("author", "alice");
@@ -107,6 +116,7 @@ public class AndPredicateTest extends TestCase {
assertFalse(and(a, c).equals(a));
}
@Test
@SuppressWarnings("unchecked")
public void testHashCode() {
final TestPredicate a = f("author", "alice");
@@ -118,6 +128,7 @@ public class AndPredicateTest extends TestCase {
assertFalse(and(a, c).hashCode() == and(a, b).hashCode());
}
@Test
@SuppressWarnings("unchecked")
public void testCopy() {
final TestPredicate a = f("author", "alice");

View File

@@ -14,11 +14,16 @@
package com.google.gerrit.server.query;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.Collections;
public class FieldPredicateTest extends TestCase {
public class FieldPredicateTest {
private static final class TestPredicate extends OperatorPredicate<String> {
private TestPredicate(String name, String value) {
super(name, value);
@@ -39,12 +44,14 @@ public class FieldPredicateTest extends TestCase {
return new TestPredicate(name, value);
}
@Test
public void testToString() {
assertEquals("author:bob", f("author", "bob").toString());
assertEquals("author:\"\"", f("author", "").toString());
assertEquals("owner:\"A U Thor\"", f("owner", "A U Thor").toString());
}
@Test
public void testEquals() {
assertTrue(f("author", "bob").equals(f("author", "bob")));
assertFalse(f("author", "bob").equals(f("author", "alice")));
@@ -52,11 +59,13 @@ public class FieldPredicateTest extends TestCase {
assertFalse(f("author", "bob").equals("author"));
}
@Test
public void testHashCode() {
assertTrue(f("a", "bob").hashCode() == f("a", "bob").hashCode());
assertFalse(f("a", "bob").hashCode() == f("a", "alice").hashCode());
}
@Test
public void testNameValue() {
final String name = "author";
final String value = "alice";
@@ -66,6 +75,7 @@ public class FieldPredicateTest extends TestCase {
assertEquals(0, f.getChildren().size());
}
@Test
public void testCopy() {
final OperatorPredicate<String> f = f("author", "alice");
assertSame(f, f.copy(Collections.<Predicate<String>> emptyList()));

View File

@@ -16,13 +16,18 @@ package com.google.gerrit.server.query;
import static com.google.gerrit.server.query.Predicate.and;
import static com.google.gerrit.server.query.Predicate.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
public class NotPredicateTest extends TestCase {
public class NotPredicateTest {
private static final class TestPredicate extends OperatorPredicate<String> {
private TestPredicate(String name, String value) {
super(name, value);
@@ -43,6 +48,7 @@ public class NotPredicateTest extends TestCase {
return new TestPredicate(name, value);
}
@Test
public void testNotNot() {
final TestPredicate p = f("author", "bob");
final Predicate<String> n = not(p);
@@ -51,6 +57,7 @@ public class NotPredicateTest extends TestCase {
assertSame(p, not(n));
}
@Test
public void testChildren() {
final TestPredicate p = f("author", "bob");
final Predicate<String> n = not(p);
@@ -58,6 +65,7 @@ public class NotPredicateTest extends TestCase {
assertSame(p, n.getChild(0));
}
@Test
public void testChildrenUnmodifiable() {
final TestPredicate p = f("author", "bob");
final Predicate<String> n = not(p);
@@ -87,10 +95,12 @@ public class NotPredicateTest extends TestCase {
assertSame(o + " did not affect child", c, p.getChild(0));
}
@Test
public void testToString() {
assertEquals("-author:bob", not(f("author", "bob")).toString());
}
@Test
public void testEquals() {
assertTrue(not(f("author", "bob")).equals(not(f("author", "bob"))));
assertFalse(not(f("author", "bob")).equals(not(f("author", "alice"))));
@@ -98,11 +108,13 @@ public class NotPredicateTest extends TestCase {
assertFalse(not(f("author", "bob")).equals("author"));
}
@Test
public void testHashCode() {
assertTrue(not(f("a", "b")).hashCode() == not(f("a", "b")).hashCode());
assertFalse(not(f("a", "b")).hashCode() == not(f("a", "a")).hashCode());
}
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void testCopy() {
final TestPredicate a = f("author", "alice");

View File

@@ -15,14 +15,19 @@
package com.google.gerrit.server.query;
import static com.google.gerrit.server.query.Predicate.or;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class OrPredicateTest extends TestCase {
public class OrPredicateTest {
private static final class TestPredicate extends OperatorPredicate<String> {
private TestPredicate(String name, String value) {
super(name, value);
@@ -43,6 +48,7 @@ public class OrPredicateTest extends TestCase {
return new TestPredicate(name, value);
}
@Test
@SuppressWarnings("unchecked")
public void testChildren() {
final TestPredicate a = f("author", "alice");
@@ -53,6 +59,7 @@ public class OrPredicateTest extends TestCase {
assertSame(b, n.getChild(1));
}
@Test
@SuppressWarnings("unchecked")
public void testChildrenUnmodifiable() {
final TestPredicate a = f("author", "alice");
@@ -83,6 +90,7 @@ public class OrPredicateTest extends TestCase {
assertEquals(o + " did not affect child", l, p.getChildren());
}
@Test
@SuppressWarnings("unchecked")
public void testToString() {
final TestPredicate a = f("q", "alice");
@@ -92,6 +100,7 @@ public class OrPredicateTest extends TestCase {
assertEquals("(q:alice OR q:bob OR q:charlie)", or(a, b, c).toString());
}
@Test
@SuppressWarnings("unchecked")
public void testEquals() {
final TestPredicate a = f("author", "alice");
@@ -107,6 +116,7 @@ public class OrPredicateTest extends TestCase {
assertFalse(or(a, c).equals(a));
}
@Test
@SuppressWarnings("unchecked")
public void testHashCode() {
final TestPredicate a = f("author", "alice");
@@ -118,6 +128,7 @@ public class OrPredicateTest extends TestCase {
assertFalse(or(a, c).hashCode() == or(a, b).hashCode());
}
@Test
@SuppressWarnings("unchecked")
public void testCopy() {
final TestPredicate a = f("author", "alice");

View File

@@ -13,13 +13,13 @@
// limitations under the License.
package com.google.gerrit.server.query;
import junit.framework.TestCase;
import org.antlr.runtime.tree.Tree;
import org.junit.Test;
public class QueryParserTest extends TestCase {
import static org.junit.Assert.assertEquals;
public class QueryParserTest {
@Test
public void testProjectBare() throws QueryParseException {
Tree r;

View File

@@ -16,12 +16,15 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
public class RegexFilePredicateTest extends TestCase {
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class RegexFilePredicateTest {
@Test
public void testPrefixOnlyOptimization() throws OrmException {
RegexFilePredicate p = predicate("^a/b/.*");
assertTrue(p.match(change("a/b/source.c")));
@@ -31,6 +34,7 @@ public class RegexFilePredicateTest extends TestCase {
assertFalse(p.match(change("a/bb/source.c")));
}
@Test
public void testPrefixReducesSearchSpace() throws OrmException {
RegexFilePredicate p = predicate("^a/b/.*\\.[ch]");
assertTrue(p.match(change("a/b/source.c")));
@@ -40,6 +44,7 @@ public class RegexFilePredicateTest extends TestCase {
assertTrue(p.match(change("a/b/a.a", "a/b/a.d", "a/b/a.h")));
}
@Test
public void testFileExtension_Constant() throws OrmException {
RegexFilePredicate p = predicate("^.*\\.res");
assertTrue(p.match(change("test.res")));
@@ -47,6 +52,7 @@ public class RegexFilePredicateTest extends TestCase {
assertFalse(p.match(change("test.res.bar")));
}
@Test
public void testFileExtension_CharacterGroup() throws OrmException {
RegexFilePredicate p = predicate("^.*\\.[ch]");
assertTrue(p.match(change("test.c")));
@@ -54,6 +60,7 @@ public class RegexFilePredicateTest extends TestCase {
assertFalse(p.match(change("test.C")));
}
@Test
public void testEndOfString() throws OrmException {
assertTrue(predicate("^a$").match(change("a")));
assertFalse(predicate("^a$").match(change("a$")));
@@ -62,6 +69,7 @@ public class RegexFilePredicateTest extends TestCase {
assertTrue(predicate("^a\\$").match(change("a$")));
}
@Test
public void testExactMatch() throws OrmException {
RegexFilePredicate p = predicate("^foo.c");
assertTrue(p.match(change("foo.c")));

View File

@@ -14,6 +14,11 @@
package com.google.gerrit.server.schema;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -29,9 +34,10 @@ import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Repository;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
@@ -40,7 +46,7 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
public class SchemaCreatorTest extends TestCase {
public class SchemaCreatorTest {
@Inject
private AllProjectsName allProjects;
@@ -50,18 +56,17 @@ public class SchemaCreatorTest extends TestCase {
@Inject
private InMemoryDatabase db;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
new InMemoryModule().inject(this);
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
InMemoryDatabase.drop(db);
super.tearDown();
}
@Test
public void testGetCauses_CreateSchema() throws OrmException, SQLException,
IOException {
// Initially the schema should be empty.
@@ -109,6 +114,7 @@ public class SchemaCreatorTest extends TestCase {
}
}
@Test
public void testCreateSchema_LabelTypes() throws Exception {
List<String> labels = Lists.newArrayList();
for (LabelType label : getLabelTypes().getLabelTypes()) {
@@ -117,6 +123,7 @@ public class SchemaCreatorTest extends TestCase {
assertEquals(ImmutableList.of("Code-Review"), labels);
}
@Test
public void testCreateSchema_Label_CodeReview() throws Exception {
LabelType codeReview = getLabelTypes().byLabel("Code-Review");
assertNotNull(codeReview);

View File

@@ -34,10 +34,11 @@ import com.google.gwtorm.server.StatementExecutor;
import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.PersonIdent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.FileNotFoundException;
@@ -45,21 +46,22 @@ import java.io.IOException;
import java.util.List;
import java.util.UUID;
public class SchemaUpdaterTest extends TestCase {
import static org.junit.Assert.assertEquals;
public class SchemaUpdaterTest {
private InMemoryDatabase db;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
db = InMemoryDatabase.newDatabase();
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
InMemoryDatabase.drop(db);
super.tearDown();
}
@Test
public void testUpdate() throws OrmException, FileNotFoundException,
IOException {
db.create();

View File

@@ -14,11 +14,15 @@
package com.google.gerrit.server.util;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.HashSet;
public class IdGeneratorTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class IdGeneratorTest {
@Test
public void test1234() {
final HashSet<Integer> seen = new HashSet<Integer>();
for (int i = 0; i < 1 << 16; i++) {
@@ -32,6 +36,7 @@ public class IdGeneratorTest extends TestCase {
assertEquals(0x0b966b11, IdGenerator.unmix(IdGenerator.mix(0x0b966b11)));
}
@Test
public void testFormat() {
assertEquals("0000000f", IdGenerator.format(0xf));
assertEquals("801234ab", IdGenerator.format(0x801234ab));

View File

@@ -20,8 +20,12 @@ import static com.google.gerrit.server.util.SocketUtil.parse;
import static com.google.gerrit.server.util.SocketUtil.resolve;
import static java.net.InetAddress.getByName;
import static java.net.InetSocketAddress.createUnresolved;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase;
import org.junit.Test;
import java.net.Inet4Address;
import java.net.Inet6Address;
@@ -29,7 +33,8 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
public class SocketUtilTest extends TestCase {
public class SocketUtilTest {
@Test
public void testIsIPv6() throws UnknownHostException {
final InetAddress ipv6 = getByName("1:2:3:4:5:6:7:8");
assertTrue(ipv6 instanceof Inet6Address);
@@ -40,12 +45,14 @@ public class SocketUtilTest extends TestCase {
assertFalse(isIPv6(ipv4));
}
@Test
public void testHostname() {
assertEquals("*", hostname(new InetSocketAddress(80)));
assertEquals("localhost", hostname(new InetSocketAddress("localhost", 80)));
assertEquals("foo", hostname(createUnresolved("foo", 80)));
}
@Test
public void testFormat() throws UnknownHostException {
assertEquals("*:1234", SocketUtil.format(new InetSocketAddress(1234), 80));
assertEquals("*", SocketUtil.format(new InetSocketAddress(80), 80));
@@ -64,6 +71,7 @@ public class SocketUtilTest extends TestCase {
SocketUtil. format(new InetSocketAddress("localhost", 80), 80));
}
@Test
public void testParse() {
assertEquals(new InetSocketAddress(1234), parse("*:1234", 80));
assertEquals(new InetSocketAddress(80), parse("*", 80));
@@ -100,6 +108,7 @@ public class SocketUtilTest extends TestCase {
}
}
@Test
public void testResolve() throws UnknownHostException {
assertEquals(new InetSocketAddress(1234), resolve("*:1234", 80));
assertEquals(new InetSocketAddress(80), resolve("*", 80));

View File

@@ -26,9 +26,8 @@ import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Guice;
import com.google.inject.Inject;
import junit.framework.TestCase;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.junit.Test;
import java.io.IOException;
import java.sql.Connection;
@@ -37,6 +36,8 @@ import java.util.Properties;
import javax.sql.DataSource;
import static org.junit.Assert.assertEquals;
/**
* An in-memory test instance of {@link ReviewDb} database.
* <p>
@@ -162,6 +163,6 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
public void assertSchemaVersion() throws OrmException {
final CurrentSchemaVersion act = getSchemaVersion();
TestCase.assertEquals(schemaVersion.getVersionNbr(), act.versionNbr);
assertEquals(schemaVersion.getVersionNbr(), act.versionNbr);
}
}

View File

@@ -223,8 +223,8 @@ maven_jar(
maven_jar(
name = 'easymock',
id = 'org.easymock:easymock:3.1',
sha1 = '3e127311a86fc2e8f550ef8ee4abe094bbcf7e7e',
id = 'org.easymock:easymock:3.2',
sha1 = '00c82f7fa3ef377d8954b1db25123944b5af2ba4',
license = 'DO_NOT_DISTRIBUTE',
deps = [
':cglib-2_2',