Completed test migration to junit4, easymock updated to version 3.2
Change-Id: I6381045b3dae7133cc3589c5dd20ed977118a83d
This commit is contained in:

committed by
Shawn Pearce

parent
c8cffc8e92
commit
d215908bae
@@ -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();
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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 =
|
||||
{ "", "",
|
||||
|
@@ -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());
|
||||
|
@@ -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"));
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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)");
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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 =
|
||||
|
@@ -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"));
|
||||
}
|
||||
|
@@ -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>");
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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");
|
||||
|
@@ -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()));
|
||||
|
@@ -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");
|
||||
|
@@ -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");
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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")));
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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));
|
||||
|
@@ -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));
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user