Class DataProviderUtil


  • public class DataProviderUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object[][] buildDataDimensions​(java.util.List<?>... dimensions)
      This is a utility to be used with junit-dataprovider.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • buildDataDimensions

        public static java.lang.Object[][] buildDataDimensions​(java.util.List<?>... dimensions)
        This is a utility to be used with junit-dataprovider. It will instead of taking in an array of argument arrays, will get an array of available dimensions, each with possible values. It will then multiply all the possible dimension possibilities with each other and result the array of parameter array that junit-dataprovider wants.

        E.g. providing two dimensions, content type and locale, e.g. like this:

        
         return buildDataDimensions(
             Arrays.asList(ContentType.WALLPAPER, ContentType.AUDIO),
             Arrays.asList(Locale.US, Locale.DE, Locale.SIMPLIFIED_CHINESE));
         
        Will create 6 argument arrays, one for each combination of content type and locale as if the input was this:
        
         return new Object[][]{
             {ContentType.WALLPAPER, Locale.US},
             {ContentType.WALLPAPER, Locale.DE},
             {ContentType.WALLPAPER, Locale.SIMPLIFIED_CHINESE},
             {ContentType.AUDIO, Locale.US},
             {ContentType.AUDIO, Locale.DE},
             {ContentType.AUDIO, Locale.SIMPLIFIED_CHINESE},
         });
         
        This can significantly shorten the argument list especially with larger set of dimensions and longer lists of options for each. It accepts null values and does not accept empty dimensions. Each dimension is called a 'layer' in the input.
        Parameters:
        dimensions - The available dimensions.
        Returns:
        The argument arrays.