下面列出了怎么用org.junit.jupiter.params.provider.MethodSource的API类实例代码及写法,或者点击链接到github查看源代码。
@ParameterizedTest
@MethodSource( "data1" )
public void T_equal_obj_1( final IColumn column ) throws IOException{
int[] mustReadIndex = { 0 };
PrimitiveObject[] compareData = new PrimitiveObject[]{ new ByteObj( (byte)-10 ) , new ShortObj( (short)-10 ) , new IntegerObj( -10 ) , new LongObj( -10 ) , new FloatObj( -10.0f ) , new DoubleObj( -10.0d ) };
for( PrimitiveObject obj : compareData ){
IFilter filter = new NumberFilter( NumberFilterType.EQUAL , obj );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_getPrimitiveObjectArray_1( final String targetClassName ) throws IOException{
IColumn column = createNotNullColumn( targetClassName );
IExpressionIndex indexList = new AllExpressionIndex( column.size() );
PrimitiveObject[] objArray = column.getPrimitiveObjectArray( indexList , 0 , indexList.size() );
assertEquals( objArray[0].getBoolean() , true );
assertEquals( objArray[1].getBoolean() , false );
assertEquals( objArray[2].getBoolean() , true );
assertEquals( objArray[3].getBoolean() , false );
assertEquals( objArray[4].getBoolean() , true );
assertEquals( objArray[5].getBoolean() , false );
assertEquals( objArray[6].getBoolean() , true );
assertEquals( objArray[7].getBoolean() , false );
assertEquals( objArray[8].getBoolean() , true );
assertEquals( objArray[9].getBoolean() , false );
assertEquals( objArray[10].getBoolean() , true );
}
@ParameterizedTest
@MethodSource("listJsonDataFormatsToBeTested")
public void testUnmarshallingDifferentPojos(String jsonComponent) {
String bodyA = "{\"name\":\"name A\"}";
String bodyB = "{\"value\":1.0}";
RestAssured.given().contentType(ContentType.TEXT)
.queryParam("json-component", jsonComponent)
.body(bodyA)
.post("/dataformats-json/in-a");
RestAssured.given().contentType(ContentType.TEXT)
.queryParam("json-component", jsonComponent)
.body(bodyB)
.post("/dataformats-json/in-b");
RestAssured.given()
.queryParam("json-component", jsonComponent)
.post("/dataformats-json/out-a")
.then()
.body(equalTo(bodyA));
RestAssured.given()
.queryParam("json-component", jsonComponent)
.post("/dataformats-json/out-b")
.then()
.body(equalTo(bodyB));
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_getPrimitiveObjectArray_2( final String targetClassName ) throws IOException{
IColumn column = createNotNullColumn( targetClassName );
List<Integer> list = new ArrayList<Integer>();
list.add( Integer.valueOf( 0 ) );
list.add( Integer.valueOf( 2 ) );
list.add( Integer.valueOf( 4 ) );
list.add( Integer.valueOf( 6 ) );
list.add( Integer.valueOf( 8 ) );
list.add( Integer.valueOf( 10 ) );
IExpressionIndex indexList = new ListIndexExpressionIndex( list );
PrimitiveObject[] objArray = column.getPrimitiveObjectArray( indexList , 0 , indexList.size() );
assertEquals( objArray[0].getBoolean() , true );
assertEquals( objArray[1].getBoolean() , true );
assertEquals( objArray[2].getBoolean() , true );
assertEquals( objArray[3].getBoolean() , true );
assertEquals( objArray[4].getBoolean() , true );
assertEquals( objArray[5].getBoolean() , true );
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_lt_2( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[4] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_gt_2( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[10] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_encodeAndDecode_equalsSetValue_withInt32( final String targetClassName ) throws IOException{
int[] intArray = new int[]{
(int)Integer.MAX_VALUE,
(int)Integer.MIN_VALUE,
(int)Short.MAX_VALUE,
(int)Short.MIN_VALUE,
(int)Byte.MAX_VALUE,
(int)Byte.MIN_VALUE,
1,
1,
2,
2
};
IColumn column = createTestColumn( targetClassName , intArray );
assertEquals( column.size() , 10 );
for ( int i = 0 ; i < 10 ; i++ ) {
assertEquals( ( (PrimitiveObject)( column.get(i).getRow() ) ).getLong() , intArray[i] );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_compareString_3( final IBlockIndex index ) throws IOException{
int[] mustReadIndex = { 0 , 1 , 3 };
IFilter filter = new RangeStringCompareFilter( "bb" , true , "x" , false );
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_ge_obj_3( final IColumn column ) throws IOException{
int[] mustReadIndex = { 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 };
PrimitiveObject[] compareData = new PrimitiveObject[]{ new ByteObj( (byte)0 ) , new ShortObj( (short)0 ) , new IntegerObj( 0 ) , new LongObj( 0 ) , new FloatObj( 0.0f ) , new DoubleObj( 0.0d ) };
for( PrimitiveObject obj : compareData ){
IFilter filter = new NumberFilter( NumberFilterType.GE , obj );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_backwardMatch_1( final IColumn column ) throws IOException{
int[] mustReadIndex = { 0 , 20 };
IFilter filter = new BackwardMatchStringFilter( "0" );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
//dumpFilterResult( filterResult );
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_ge_obj_2( final IColumn column ) throws IOException{
int[] mustReadIndex = { 28 , 29 };
PrimitiveObject[] compareData = new PrimitiveObject[]{ new ByteObj( (byte)28 ) , new ShortObj( (short)28 ) , new IntegerObj( 28 ) , new LongObj( 28 ) , new FloatObj( 28.0f ) , new DoubleObj( 28.0d ) };
for( PrimitiveObject obj : compareData ){
IFilter filter = new NumberFilter( NumberFilterType.GE , obj );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_encodeAndDecode_equalsSetValue_withIntBit0( final String targetClassName ) throws IOException{
short[] valueArray = new short[]{
(short)0,
(short)0,
(short)0,
(short)0,
(short)0,
(short)0,
(short)0,
(short)0,
(short)0,
(short)0
};
IColumn column = createTestColumn( targetClassName , valueArray );
assertEquals( column.size() , 10 );
for ( int i = 0 ; i < 10 ; i++ ) {
assertEquals( ( (PrimitiveObject)( column.get(i).getRow() ) ).getShort() , valueArray[i] );
}
}
@ParameterizedTest(name = "{index}. ssz->value {0} {3}->{2}")
@MethodSource("readUintBoundsTests")
void testUintBoundsFromSSZ(String type, boolean valid, String value, String ssz) {
if (valid) {
int bitLength = Integer.valueOf(type.substring("uint".length()));
Bytes read;
if (bitLength < 31) {
read = Bytes.ofUnsignedLong((long) SSZ.decode(Bytes.fromHexString(ssz), reader -> reader.readUInt(bitLength)));
} else if (bitLength < 62) {
read = Bytes.ofUnsignedLong(SSZ.decode(Bytes.fromHexString(ssz), reader -> reader.readULong(bitLength)));
} else {
read = Bytes
.wrap(
SSZ.decode(Bytes.fromHexString(ssz), reader -> reader.readUnsignedBigInteger(bitLength)).toByteArray());
}
assertEquals(Bytes.wrap(new BigInteger(value).toByteArray()).toShortHexString(), read.toShortHexString());
}
}
@ParameterizedTest
@MethodSource("parameters")
public void testLoaders(String location, Class<? extends SourceLoader> type) throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI(location);
SourceLoader loader = RoutesConfigurer.load(runtime, source);
assertThat(loader).isInstanceOf(type);
assertThat(runtime.builders).hasSize(1);
assertThat(runtime.builders).first().isInstanceOf(RouteBuilder.class);
RouteBuilder builder = (RouteBuilder)runtime.builders.get(0);
builder.setContext(runtime.getCamelContext());
builder.configure();
List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
assertThat(routes).hasSize(1);
assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick");
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_range_1( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[15] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_range_6( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 , 1 , 2 , 3 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[20] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_le_obj_2( final IColumn column ) throws IOException{
int[] mustReadIndex = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 };
PrimitiveObject[] compareData = new PrimitiveObject[]{ new ByteObj( (byte)29 ) , new ShortObj( (short)29 ) , new IntegerObj( 29 ) , new LongObj( 29 ) , new FloatObj( 29.0f ) , new DoubleObj( 29.0d ) };
for( PrimitiveObject obj : compareData ){
IFilter filter = new NumberFilter( NumberFilterType.LE , obj );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_encodeAndDecode_equalsSetValue_withInt16( final String targetClassName ) throws IOException{
int[] intArray = new int[]{
(int)Short.MAX_VALUE,
(int)Short.MIN_VALUE,
(int)Byte.MAX_VALUE,
(int)Byte.MIN_VALUE,
1,
1,
-1,
-1,
2,
2
};
IColumn column = createTestColumn( targetClassName , intArray );
assertEquals( column.size() , 10 );
for ( int i = 0 ; i < 10 ; i++ ) {
assertEquals( ( (PrimitiveObject)( column.get(i).getRow() ) ).getInt() , intArray[i] );
}
}
@ParameterizedTest
@MethodSource("parameters")
public void testLoaders(String location, Class<? extends SourceLoader> type) throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI(location);
SourceLoader loader = runtime.load(source);
assertThat(loader).isInstanceOf(type);
assertThat(runtime.builders).hasSize(1);
assertThat(runtime.builders).first().isInstanceOf(RouteBuilder.class);
RouteBuilder builder = (RouteBuilder)runtime.builders.get(0);
builder.setContext(runtime.getCamelContext());
builder.configure();
List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
assertThat(routes).hasSize(1);
assertThat(routes.get(0).getInput().getEndpointUri()).isEqualTo("timer:tick");
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_forwardMatch_1( final IColumn column ) throws IOException{
int[] mustReadIndex = { 0 };
IFilter filter = new ForwardMatchStringFilter( "0" );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
//dumpFilterResult( filterResult );
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
@ParameterizedTest
@MethodSource("resolutionDataProvider")
void testIsMobileWindowResolution(int actualWidth, boolean mobileViewport)
{
WebApplicationConfiguration webApplicationConfiguration = prepareWebApplicationConfiguration();
webApplicationConfiguration.setMobileScreenResolutionWidthThreshold(WIDTH_THRESHOLD);
IJavascriptActions javascriptActions = mockJavascriptActions(actualWidth);
assertEquals(mobileViewport, webApplicationConfiguration.isMobileViewport(javascriptActions));
}
@MethodSource("rangeSource")
@ParameterizedTest
void testConvert(String rangeAsString, Set<Integer> expected)
{
IntegerRange range = converter.convert(rangeAsString);
assertEquals(expected, range.getRange());
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_null_1( final String targetClassName ) throws IOException{
IColumn column = createNullColumn( targetClassName );
assertNull( column.get(0).getRow() );
assertNull( column.get(1).getRow() );
}
@ParameterizedTest
@MethodSource("data")
public void checksIfBoxed(Model model, String shapeId, boolean isBoxed) {
BoxIndex index = model.getKnowledge(BoxIndex.class);
ShapeId targetId = ShapeId.from(shapeId);
if (isBoxed && !index.isBoxed(targetId)) {
Assertions.fail("Did not expect shape to be determined as boxed: " + targetId);
} else if (!isBoxed && index.isBoxed(targetId)) {
Assertions.fail("Expected shape to be determined as boxed: " + targetId);
}
}
@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnitControlledByUnitOfWork(String bpmnPath) throws Exception {
Application app = generateCode(Collections.singletonList(bpmnPath), Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.drl"));
assertThat(app).isNotNull();
final List<String> startedProcesses = new ArrayList<>();
// add custom event listener that collects data
((DefaultProcessEventListenerConfig)app.config().process().processEventListeners()).listeners().add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(event.getProcessInstance().getId());
}
});
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.processes().processById("BusinessRuleUnit");
Model m = p.createModel();
m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model)processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("person");
assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
// since the unit of work has not been finished yet not listeners where invoked
assertThat(startedProcesses).hasSize(0);
uow.end();
// after unit of work has been ended listeners are invoked
assertThat(startedProcesses).hasSize(1);
}
@ParameterizedTest
@MethodSource("data")
public void testConst(String oldValue, String newValue, String tag, String searchString) {
TestCaseData data = new TestCaseData(oldValue, newValue);
Shape definition = createDefinition(ModifiedTrait.DIFF_ERROR_CONST);
Model modelA = Model.assembler().addShape(definition).addShape(data.oldShape).assemble().unwrap();
Model modelB = Model.assembler().addShape(definition).addShape(data.newShape).assemble().unwrap();
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);
assertThat(TestHelper.findEvents(events, "ModifiedTrait").size(), equalTo(1));
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_hasNull_3( final String targetClassName ) throws IOException {
IColumn column = new PrimitiveColumn( ColumnType.LONG , "column" );
column.add( ColumnType.LONG , new LongObj( (long)1 ) , 1 );
column.add( ColumnType.LONG , new LongObj( (long)2 ) , 5 );
ColumnBinary columnBinary = create( column , targetClassName );
assertEquals( columnBinary.logicalDataSize , Long.BYTES * 2 );
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_canBlockSkip_1( final IBlockIndex bIndex , final IFilter filter , final boolean result ){
if( result ){
assertEquals( result , bIndex.getBlockSpreadIndex( filter ).isEmpty() );
}
else{
assertTrue( bIndex.getBlockSpreadIndex( filter ) == null );
}
}
@ParameterizedTest
@MethodSource("stringSupplier")
void shouldParseString(String input, String expected) {
TomlParseResult result = Toml.parse(input);
assertFalse(result.hasErrors(), () -> joinErrors(result));
assertEquals(expected, result.getString("foo"));
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_compressAndSet_1( final String[] classNames , final byte[] compressTarget , final int start , final int length , final byte[] success ) throws IOException{
for( int i = 0 ; i < classNames.length ; i++ ){
ICompressor compressor = FindCompressor.get( classNames[i] );
byte[] compressData = compressor.compress( compressTarget , start , length );
byte[] decompressData = new byte[ compressor.getDecompressSize( compressData , 0 , compressData.length ) ];
compressor.decompressAndSet( compressData , 0 , compressData.length , decompressData );
assertTrue( Arrays.equals( decompressData , success ) );
}
}