下面列出了怎么用org.junit.runners.Parameterized的API类实例代码及写法,或者点击链接到github查看源代码。
@Parameterized.Parameters
public static Collection<Object[]> data() {
return asList(new Object[][] {
//1 tier
{ newResourcePoolsBuilder().heap(1, MB), singletonList("OnHeap:HitCount"), singletonList(CACHE_HIT_TOTAL), CACHE_HIT_TOTAL },
{ newResourcePoolsBuilder().offheap(1, MB), singletonList("OffHeap:HitCount"), singletonList(CACHE_HIT_TOTAL), CACHE_HIT_TOTAL },
{ newResourcePoolsBuilder().disk(1, MB), singletonList("Disk:HitCount"), singletonList(CACHE_HIT_TOTAL), CACHE_HIT_TOTAL },
//2 tiers
{ newResourcePoolsBuilder().heap(1, MB).offheap(2, MB), Arrays.asList("OnHeap:HitCount","OffHeap:HitCount"), Arrays.asList(2L,2L), CACHE_HIT_TOTAL},
{ newResourcePoolsBuilder().heap(1, MB).disk(2, MB), Arrays.asList("OnHeap:HitCount","Disk:HitCount"), Arrays.asList(2L,2L), CACHE_HIT_TOTAL},
//3 tiers
{ newResourcePoolsBuilder().heap(1, MB).offheap(2, MB).disk(3, MB), Arrays.asList("OnHeap:HitCount","OffHeap:HitCount","Disk:HitCount"), Arrays.asList(2L,0L,2L), CACHE_HIT_TOTAL},
{ newResourcePoolsBuilder().heap(1, ENTRIES).offheap(2, MB).disk(3, MB), Arrays.asList("OnHeap:HitCount","OffHeap:HitCount","Disk:HitCount"), Arrays.asList(1L,1L,2L), CACHE_HIT_TOTAL},
});
}
@Parameterized.Parameters(name = "Scenario {index}")
public static Collection<AuthorizationScenario[]> scenarios() {
return AuthorizationTestRule.asParameters(
scenario()
.withoutAuthorizations()
.failsDueToRequired(
grant(Resources.PROCESS_DEFINITION, PROCESS_DEFINITION_KEY, "userId", Permissions.DELETE)),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_DEFINITION, PROCESS_DEFINITION_KEY, "userId", Permissions.DELETE))
.succeeds(),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_DEFINITION, "*", "userId", Permissions.DELETE))
.succeeds()
);
}
@Parameterized.Parameters(name = "{index}: {0} ({1})")
public static Collection<Object[]> resources() {
return Arrays.asList(new Object[][]{
{"dsp/standalone_class_Correct.ttl", 0},
{"dsp/standalone_class_Wrong.ttl", 1},
{"dsp/property_cardinality_Correct.ttl", 0},
{"dsp/property_cardinality_Wrong.ttl", 5},
{"dsp/valueClass_Correct.ttl", 0},
{"dsp/valueClass_Wrong.ttl", 1},
{"dsp/valueClass-miss_Wrong.ttl", 1},
{"dsp/languageOccurrence_Correct.ttl", 0},
{"dsp/languageOccurrence_Wrong.ttl", 2},
{"dsp/language_Correct.ttl", 0},
{"dsp/language_Wrong.ttl", 3},
{"dsp/isLiteral_Wrong.ttl", 1},
{"dsp/literal_Correct.ttl", 0},
{"dsp/literal_Wrong.ttl", 4},
});
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{void.class, Opcodes.RETURN, 0},
{Object.class, Opcodes.ARETURN, 1},
{Object[].class, Opcodes.ARETURN, 1},
{long.class, Opcodes.LRETURN, 2},
{double.class, Opcodes.DRETURN, 2},
{float.class, Opcodes.FRETURN, 1},
{int.class, Opcodes.IRETURN, 1},
{char.class, Opcodes.IRETURN, 1},
{short.class, Opcodes.IRETURN, 1},
{byte.class, Opcodes.IRETURN, 1},
{boolean.class, Opcodes.IRETURN, 1},
});
}
@Parameterized.Parameters
public static Object[][] parameters() {
return new Object[][] {
new Object[] { "boolean", false, true },
new Object[] { "int", 5, 55 },
new Object[] { "long", 5_000_000_049L, 5_000L },
new Object[] { "float", 1.97f, 2.11f },
new Object[] { "double", 2.11d, 1.97d },
new Object[] { "date", "2018-06-29", "2018-05-03" },
new Object[] { "time", "10:02:34.000000", "10:02:34.000001" },
new Object[] { "timestamp",
"2018-06-29T10:02:34.000000",
"2018-06-29T15:02:34.000000" },
new Object[] { "timestamptz",
"2018-06-29T10:02:34.000000+00:00",
"2018-06-29T10:02:34.000000-07:00" },
new Object[] { "string", "tapir", "monthly" },
// new Object[] { "uuid", uuid, UUID.randomUUID() }, // not supported yet
new Object[] { "fixed", "abcd".getBytes(Charsets.UTF_8), new byte[] { 0, 1, 2, 3 } },
new Object[] { "binary", "xyz".getBytes(Charsets.UTF_8), new byte[] { 0, 1, 2, 3, 4, 5 } },
new Object[] { "int_decimal", "77.77", "12.34" },
new Object[] { "long_decimal", "88.88", "12.34" },
new Object[] { "fixed_decimal", "99.99", "12.34" },
};
}
@Parameterized.Parameters(name = "{0}")
public static Collection<String> matchers() {
return Arrays.asList(
"withValByte",
"withValueByte",
"withValChar",
"withValueCharacter",
"withValInt",
"withValueInteger",
"withValLong",
"withValueLong",
"withValFloat",
"withValueFloat",
"withValDouble",
"withValueDouble",
"withValBoolean",
"withValueBoolean"
);
}
@Parameterized.Parameters(name = "{0}")
public static Collection<Object> data() {
return Arrays.asList(
new Object[][] {
{
new UnconfiguredBuildTargetWithOutputsTypeCoercer(
new UnconfiguredBuildTargetTypeCoercer(
new ParsingUnconfiguredBuildTargetViewFactory())),
EXPECTED_UNCONFIGURED_BUILD_TARGET_WITH_OUTPUTS_BI_FUNCTION
},
{
new BuildTargetWithOutputsTypeCoercer(
new UnconfiguredBuildTargetWithOutputsTypeCoercer(
new UnconfiguredBuildTargetTypeCoercer(
new ParsingUnconfiguredBuildTargetViewFactory()))),
EXPECTED_BUILD_TARGET_WITH_OUTPUTS_BI_FUNCTION
}
});
}
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
List<Object[]> result = new ArrayList<>();
result
.add(new Object[] {TestDir.cdmUnitTestDir + "gribCollections/tp/GFS_Global_onedeg_ana_20150326_0600.grib2.ncx4",
FeatureType.GRID, "Temperature_sigma"}); // SRC // TP
result.add(new Object[] {TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4", FeatureType.GRID,
"Pressure_surface"}); // TP
result.add(new Object[] {TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4", FeatureType.GRID,
"Best/Soil_temperature_depth_below_surface_layer"}); // TwoD Best
result.add(new Object[] {TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4", FeatureType.FMRC,
"TwoD/Soil_temperature_depth_below_surface_layer"}); // TwoD
result.add(new Object[] {TestDir.cdmUnitTestDir + "ft/coverage/testCFwriter.nc", FeatureType.GRID, "Temperature"});
return result;
}
/**
* This method returns a collection of {@link org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent}
* objects as parameters to the test
*
* @return
*/
@Parameterized.Parameters
public static Collection getArtifactUpdatedEventsAsParams() {
ArtifactUpdatedEvent publicRepoEvent = createTestArtifactUpdatedEvent();
ArtifactUpdatedEvent privateRepoEvent = createTestArtifactUpdatedEvent();
privateRepoEvent.setRepoURL("https://bitbucket.org/testapache2211/testrepo.git");
privateRepoEvent.setRepoUserName("testapache2211");
privateRepoEvent.setRepoPassword("RExPDGa4GkPJj4kJDzSROQ==");
ArtifactUpdatedEvent privateRepoEvent2 = createTestArtifactUpdatedEvent();
privateRepoEvent2.setRepoURL("https://[email protected]/testapache2211/testrepo.git");
privateRepoEvent2.setRepoUserName("testapache2211");
privateRepoEvent2.setRepoPassword("RExPDGa4GkPJj4kJDzSROQ==");
return Arrays.asList(new Object[][]{
{publicRepoEvent, true},
{privateRepoEvent, true},
{privateRepoEvent2, true}
});
}
@Parameterized.Parameters(name = "Scenario {index}")
public static Collection<AuthorizationScenario[]> scenarios() {
return AuthorizationTestRule.asParameters(
scenario()
.withoutAuthorizations()
.failsDueToRequired(
grant(Resources.PROCESS_INSTANCE, "processInstanceId", "userId", Permissions.READ),
grant(Resources.PROCESS_DEFINITION, "oneExternalTaskProcess", "userId", Permissions.READ_INSTANCE)),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_INSTANCE, "processInstanceId", "userId", Permissions.READ))
.succeeds(),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_INSTANCE, "*", "userId", Permissions.READ))
.succeeds(),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_DEFINITION, "processDefinitionKey", "userId", Permissions.READ_INSTANCE))
.succeeds(),
scenario()
.withAuthorizations(
grant(Resources.PROCESS_DEFINITION, "*", "userId", Permissions.READ_INSTANCE))
.succeeds()
);
}
@Parameterized.Parameters
public static Collection<Object[]> parameters() {
return Arrays.asList(new Object[][]{
new Object[] {Boolean.TRUE},
new Object[] {Boolean.FALSE},
});
}
@Parameterized.Parameters
public static Collection operations() {
Object[][] ops = new Object[Operation.values().length][];
for (int i = 0; i < Operation.values().length; i++) {
ops[i] = new Object[]{Operation.values()[i]};
}
//To test one or a subset of operations do:
//return Arrays.asList(new Object[][]{ new Object[]{Operation.APPEND}});
return Arrays.asList(ops);
}
@Parameterized.Parameters(name = "{index} rangeHeader [{0}]")
public static Collection<Object[]> parameters() {
// Get the length of the file used for this test
// It varies by platform due to line-endings
File index = new File("test/webapp/index.html");
long len = index.length();
String strLen = Long.toString(len);
List<Object[]> parameterSets = new ArrayList<>();
parameterSets.add(new Object[] { "", Integer.valueOf(200), strLen, "" });
// Invalid
parameterSets.add(new Object[] { "bytes", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes=", Integer.valueOf(416), "", "*/" + len });
// Invalid with unknown type
parameterSets.add(new Object[] { "unknown", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "unknown=", Integer.valueOf(416), "", "*/" + len });
// Invalid ranges
parameterSets.add(new Object[] { "bytes=-", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes=10-b", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes=b-10", Integer.valueOf(416), "", "*/" + len });
// Invalid no equals
parameterSets.add(new Object[] { "bytes 1-10", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes1-10", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes10-", Integer.valueOf(416), "", "*/" + len });
parameterSets.add(new Object[] { "bytes-10", Integer.valueOf(416), "", "*/" + len });
// Unknown types
parameterSets.add(new Object[] { "unknown=1-2", Integer.valueOf(200), strLen, "" });
parameterSets.add(new Object[] { "bytesX=1-2", Integer.valueOf(200), strLen, "" });
parameterSets.add(new Object[] { "Xbytes=1-2", Integer.valueOf(200), strLen, "" });
// Valid range
parameterSets.add(new Object[] { "bytes=0-9", Integer.valueOf(206), "10", "0-9/" + len });
parameterSets.add(new Object[] { "bytes=-100", Integer.valueOf(206), "100", (len - 100) + "-" + (len - 1) + "/" + len });
parameterSets.add(new Object[] { "bytes=100-", Integer.valueOf(206), "" + (len - 100), "100-" + (len - 1) + "/" + len });
// Valid range (too much)
parameterSets.add(new Object[] { "bytes=0-1000", Integer.valueOf(206), strLen, "0-" + (len - 1) + "/" + len });
parameterSets.add(new Object[] { "bytes=-1000", Integer.valueOf(206), strLen, "0-" + (len - 1) + "/" + len });
return parameterSets;
}
@Parameterized.Parameters
public static Collection providers() throws Exception {
final StatefulMongoDBRdfConfiguration conf = new StatefulMongoDBRdfConfiguration(new Configuration(), EmbeddedMongoSingleton.getNewMongoClient());
return Lists.<AbstractPcjIndexSetProvider> newArrayList(
new AccumuloIndexSetProvider(new Configuration()),
new MongoPcjIndexSetProvider(conf)
);
}
/**
* The bucket file prefix is the absolute path to the part files, which is stored within the savepoint.
*/
@Parameterized.Parameters(name = "Migration Savepoint / Bucket Files Prefix: {0}")
public static Collection<Tuple2<MigrationVersion, String>> parameters () {
return Arrays.asList(
Tuple2.of(MigrationVersion.v1_3, "/var/folders/tv/b_1d8fvx23dgk1_xs8db_95h0000gn/T/junit4273542175898623023/junit3801102997056424640/1970-01-01--01/part-0-"),
Tuple2.of(MigrationVersion.v1_4, "/var/folders/tv/b_1d8fvx23dgk1_xs8db_95h0000gn/T/junit3198043255809479705/junit8947526563966405708/1970-01-01--01/part-0-"),
Tuple2.of(MigrationVersion.v1_5, "/tmp/junit4927100426019463155/junit2465610012100182280/1970-01-01--00/part-0-"),
Tuple2.of(MigrationVersion.v1_6, "/tmp/junit3459711376354834545/junit5114611885650086135/1970-01-01--00/part-0-"),
Tuple2.of(MigrationVersion.v1_7, "/var/folders/r2/tdhx810x7yxb7q9_brnp49x40000gp/T/junit4288325607215628863/junit8132783417241536320/1970-01-01--08/part-0-"),
Tuple2.of(MigrationVersion.v1_8, "/var/folders/rc/84k970r94nz456tb9cdlt30s1j0k94/T/junit7271027454784776053/junit5108755539355247469/1970-01-01--08/part-0-"),
Tuple2.of(MigrationVersion.v1_9, "/var/folders/rc/84k970r94nz456tb9cdlt30s1j0k94/T/junit587754116249874744/junit764636113243634374/1970-01-01--08/part-0-"));
}
@Parameterized.Parameters
public static Object[][] data() {
final long millis = System.currentTimeMillis();
return new Object[][]{
{Date.class, millis, new Date(millis)},
{java.sql.Date.class, millis, new java.sql.Date(millis)},
{Time.class, millis, new Time(millis)},
{Timestamp.class, millis, new Timestamp(millis)}
};
}
/**
* Running for both {@link SimpleOperationTracker} and {@link AdaptiveOperationTracker}
* @return an array with both {@link #SIMPLE_OP_TRACKER} and {@link #ADAPTIVE_OP_TRACKER}
*/
@Parameterized.Parameters
public static List<Object[]> data() {
return Arrays.asList(
new Object[][]{{SIMPLE_OP_TRACKER, false}, {ADAPTIVE_OP_TRACKER, false}, {SIMPLE_OP_TRACKER, true},
{ADAPTIVE_OP_TRACKER, true}});
}
@Parameterized.Parameters
public static List<Object[]> data() {
// If desired this can be made dependent on runtime variables
Object[][] a;
a = new Object[2][1];
a[0][0] = StreamWriterImplType.WOODSTOCKIMPL;
a[1][0] = StreamWriterImplType.SUNINTERNALIMPL;
return Arrays.asList(a);
}
@Parameterized.Parameters(name = "{index} intermediate: {0}, terminal: {1}")
public static Collection<Object[]> data() {
final List<Object[]> list = new ArrayList<>();
for (final Object intermediate : intermediateMethods) {
for (final Object terminal : terminalMethods) {
list.add(new Object[] {intermediate, terminal});
}
}
return list;
}
@Parameterized.Parameters
public static Object[][] parameters() {
return new Object[][] {
new Object[] { "parquet" },
new Object[] { "avro" },
new Object[] { "orc" }
};
}
@Parameterized.Parameters(name = "Migration Savepoint: {0}")
public static Collection<MigrationVersion> parameters () {
return Arrays.asList(
MigrationVersion.v1_4,
MigrationVersion.v1_5,
MigrationVersion.v1_6,
MigrationVersion.v1_7,
MigrationVersion.v1_8,
MigrationVersion.v1_9);
}
@Parameterized.Parameters
public static Collection<Object[]> parameters()
{
ArrayList<Object[]> list = new ArrayList<Object[]>();
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(1, 0)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(64, 0)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(1, 1)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(64, 1)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(1, 2)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(64, 2)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(1, 3)));
list.add(makeMpq(0, 1, 0, Ordering.FIFO, new MpscUnboundedXaddArrayQueue<>(64, 3)));
return list;
}
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() throws Exception {
BaseGuess baseGuess = new BaseGuess() {
@Override
public double exec(Match match) {
return 0;
}
};
Method method = BaseGuess.class.getDeclaredMethod("nCk", int.class, int.class);
method.setAccessible(true);
return Arrays.asList(new Object[][]{
{"", 1, Collections.emptyMap()},
{"a", 1, Collections.emptyMap()},
{"4", 2, Collections.singletonMap('4', 'a')},
{"4pple", 2, Collections.singletonMap('4', 'a')},
{"abcet", 1, Collections.emptyMap()},
{"4bcet", 2, Collections.singletonMap('4', 'a')},
{"a8cet", 2, Collections.singletonMap('8', 'b')},
{"abce+", 2, Collections.singletonMap('+', 't')},
{"48cet", 4, new HashMap<Character, Character>() {{
put('4', 'a');
put('8', 'b');
}}},
{"a4a4aa", (int) method.invoke(baseGuess, 6, 2) + (int) method.invoke(baseGuess, 6, 1), Collections.singletonMap('4', 'a')},
{"4a4a44", (int) method.invoke(baseGuess, 6, 2) + (int) method.invoke(baseGuess, 6, 1), Collections.singletonMap('4', 'a')},
{"a44att+", ((int) method.invoke(baseGuess, 4, 2) + (int) method.invoke(baseGuess, 4, 1)) * (int) method.invoke(baseGuess, 3, 1),
new HashMap<Character, Character>() {{
put('4', 'a');
put('+', 't');
}}},
{"Aa44aA", (int) method.invoke(baseGuess, 6, 2) + (int) method.invoke(baseGuess, 6, 1), Collections.singletonMap('4', 'a')}
});
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
/* Parameters for initializing the tests: {numTasks, numSplits} */
return Arrays.asList(
new Object[][] {
{1, 1}, {1, 2}, {1, 4},
});
}
/**
* Running for both regular and encrypted blobs, and versions 2 and 3 of MetadataContent
* @return an array with all four different choices
*/
@Parameterized.Parameters
public static List<Object[]> data() {
return Arrays.asList(new Object[][]{{false, MessageFormatRecord.Metadata_Content_Version_V2},
{false, MessageFormatRecord.Metadata_Content_Version_V3},
{true, MessageFormatRecord.Metadata_Content_Version_V2},
{true, MessageFormatRecord.Metadata_Content_Version_V3}});
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
Collection<Object[]> params = Lists.newArrayListWithCapacity(2);
params.add(new Object[]{"jdbc:splice://localhost:1527/splicedb;user=splice;password=admin"});
params.add(new Object[]{"jdbc:splice://localhost:1527/splicedb;user=splice;password=admin;useSpark=true"});
return params;
}
@Parameterized.Parameters(name = "expectInterruption({0})")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"g_V", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t},
{"g_V_out", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.out()},
{"g_V_outE", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.outE()},
{"g_V_in", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.in()},
{"g_V_inE", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.inE()},
{"g_V_properties", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.properties()},
{"g_E", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t},
{"g_E_outV", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.outV()},
{"g_E_inV", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.inV()},
{"g_E_properties", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.properties()},
});
}
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> testCases() {
List<Object[]> result = new ArrayList<Object[]>();
for (TestCase testCase : createTestSubjects()) {
result.add(new Object[] { testCase });
}
return result;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
Collection<Object[]> params = Lists.newArrayListWithCapacity(2);
params.add(new Object[]{true});
params.add(new Object[]{false});
return params;
}
@Parameterized.Parameters(name = "configure_csc={0}, rule_analysis_rules={1}")
public static Collection<Object[]> data() {
return ParameterizedTests.getPermutations(
ImmutableList.of(false, true),
ImmutableList.of(
RuleAnalysisComputationMode.DISABLED, RuleAnalysisComputationMode.PROVIDER_COMPATIBLE));
}