com.javasbar.framework.lib.common.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of DolphinNG Show documentation
Show all versions of DolphinNG Show documentation
DolphinNG provides set of very useful addons for testNG. Most important features that it supports are
condensed smart reports, auto creation of jira ticets for test failures, linking test fails to jira tickets,
progress reporting during test runs.
package com.javasbar.framework.lib.common;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.TimeZone;
/**
* @author Basavaraj M
*/
public class Util
{
/**
* returns date and time now with default format
*
* @return
*/
public static String now()
{
return now("yyyy/MM/dd HH:mm:ss");
}
/**
* Returns date and time now with the format specified
*
* @param format - example : yyyy-MM-dd HH-mm-ss
* @return
*/
public static String now(String format)
{
return now(format, null);
}
/**
* @param format
* @param timezone
* @return
*/
public static String now(String format, String timezone)
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(format);
if (null != timezone)
{
sdf.setTimeZone(TimeZone.getTimeZone(timezone));
}
return sdf.format(cal.getTime());
}
/**
* Returns a non-zero randomInteger
*
* @return
*/
public static int RandomInt()
{
int randomInt = 1;
Random randomGenerator;
try
{
randomGenerator = new Random();
randomInt = randomGenerator.nextInt();
} catch (Exception e)
{
e.printStackTrace();
}
return randomInt + 1;
}
/**
* Returns non zero random integer upto 'x'
*
* @param x
* @return
*/
public static int RandomInt(int x)
{
int randomInt = 1;
Random randomGenerator;
try
{
randomGenerator = new Random();
randomInt = randomGenerator.nextInt(x);
} catch (Exception e)
{
e.printStackTrace();
}
return randomInt + 1;
}
/**
* i milliseconds sleep
*
* @param i
*/
public static void sleep(int i)
{
try
{
Thread.sleep(i);
} catch (InterruptedException e)
{
}
}
}