Skip to content

Commit

Permalink
新建 DefaultIfNullParameterizedTest fix #353
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Jun 9, 2022
1 parent 82135f2 commit 127c2e7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.core.lang.objectutil;

import static com.feilong.core.bean.ConvertUtil.toList;
import static com.feilong.core.lang.ObjectUtil.defaultIfNull;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

import com.feilong.test.Abstract2ParamsAndResultParameterizedTest;

/**
* The Class DefaultIfNullParameterizedTest.
*/
public class DefaultIfNullParameterizedTest extends Abstract2ParamsAndResultParameterizedTest<Object, Object, Object>{

/**
* Data.
*
* @return the iterable
*/
@Parameters(name = "index:{index}: ObjectUtil.defaultIfNull({0},{1})={2}")
public static Iterable<Object[]> data(){
Object[][] objects = build();
return toList(objects);
}

private static Object[][] build(){
ArrayList<Object> arrayList = new ArrayList<>();
String empty = "";
String space = " ";
int[] is = new int[] {};
return new Object[][] {
new Object[] { null, 1, 1 },
new Object[] { null, null, null },
new Object[] { null, empty, empty },
new Object[] { arrayList, 1, arrayList },
new Object[] { empty, empty, empty },
new Object[] { empty, " ", empty },
new Object[] { empty, "fei", empty },
new Object[] { space, "feilong", space },
new Object[] { "fl", "feilong", "fl" },
new Object[] { " fl", "feilong", " fl" },
new Object[] { is, "feilong", is }

};
}

@Test
public void test(){
assertEquals(expectedValue, defaultIfNull(input1, input2));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.runners.Suite.SuiteClasses;

/**
* The Class FeiLongObjectUtilSuiteTests.
* The Class ObjectUtilSuiteTests.
*
* @author <a href="https://github.com/ifeilong/feilong">feilong</a>
*/
Expand All @@ -29,6 +29,7 @@
IsArrayParameterizedTest.class,
IsPrimitiveArrayParameterizedTest.class,
DefaultIfNullOrEmptyParameterizedTest.class,
DefaultIfNullParameterizedTest.class,

ObjectUtilTest.class, })
public class ObjectUtilSuiteTests{
Expand Down

0 comments on commit 127c2e7

Please sign in to comment.