r2028 - in trunk/nuiton-utils/src: main/java/org/nuiton/util test/java/org/nuiton/util
Author: tchemit Date: 2011-01-22 11:37:02 +0100 (Sat, 22 Jan 2011) New Revision: 2028 Url: http://nuiton.org/repositories/revision/nuiton-utils/2028 Log: Evolution #1223: Remove deprecated api Added: trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java Removed: trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java 2011-01-20 15:26:32 UTC (rev 2027) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -1,372 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import java.text.DateFormat; -import java.text.DateFormatSymbols; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; - -/** - * Library for manipulating dates. - * - * @author fdesbois - * @version $Id$ - * @deprecated since 1.4.1 (use now {@link DateUtil} - */ -@Deprecated -public class DateUtils { - - public static final String DEFAULT_PATTERN = "dd/MM/yyyy"; - - public static final String MONTH_PATTERN = "MM/yyyy"; - - /** - * Format a date using the pattern in argument. The pattern is the same using - * for DateFormat object. - * - * @param date the date to format - * @param pattern the pattern to use - * @return a String corresponding to the date formatted - * @see DateFormat - */ - public static String formatDate(Date date, String pattern) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - return simpleDateFormat.format(date); - } - - public static String formatDate(Date date, String pattern, Locale locale) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale); - return simpleDateFormat.format(date); - } - - /** - * Parse a date using the pattern in argument. The pattern is the same using - * for DateFormat object. - * - * @param date the String to parse - * @param pattern the pattern to use - * @return a Date corresponding to the String argument parsed - * @throws ParseException for parsing errors - * @see DateFormat - */ - public static Date parseDate(String date, String pattern) throws ParseException { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - Date result = simpleDateFormat.parse(date); - return result; - } - - /** - * Create a new date from day, month and year (French version). - * The month is the real month of the year and not the one which is stored - * in Calendar object. - * @param s value of the seconds 1-60 - * @param m value of the minutes 1-60 - * @param h value of the hours 1-24 - * @param dd value of the day 1-31 - * @param mm value of the month 1-12 - * @param yy value of the year 0-9999 - * @return a new date - */ - public static Date createDate(int s, int m, int h, int dd, int mm, int yy) { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, yy); - calendar.set(Calendar.MONTH, mm-1); - calendar.set(Calendar.DAY_OF_MONTH, dd); - calendar.set(Calendar.HOUR_OF_DAY, h); - calendar.set(Calendar.MINUTE, m); - calendar.set(Calendar.SECOND, s); - return calendar.getTime(); - } - - /** - * Create a new date from day, month and year (French version). - * The month is the real month of the year and not the one which is stored - * in Calendar object. Time is set to 00:00:00.000 - * @param dd value of the day 1-31 - * @param mm value of the month 1-12 - * @param yy value of the year 0-9999 - * @return a new date - */ - public static Date createDate(int dd, int mm, int yy) { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, yy); - calendar.set(Calendar.MONTH, mm-1); - calendar.set(Calendar.DAY_OF_MONTH, dd); - return setMinTimeOfDay(calendar.getTime()); - } - - /** - * Create a new date after the current date (today) with modification on day, month and year. - * You can use negative values on arguments to have a date before today. - * - * @param ddStep nb days you want to increase from the current date - * @param mmStep nb months you want to increase from the current date - * @param yyStep nb years you want to increase from the current date - * @return a new date from the current date increase by days, months and years. - */ - public static Date createDateAfterToday(int ddStep, int mmStep, int yyStep) { - Calendar calendar = getDefaultCalendar(new Date()); - calendar.add(Calendar.DAY_OF_MONTH, ddStep); - calendar.add(Calendar.MONTH,mmStep); - calendar.add(Calendar.YEAR, yyStep); - return calendar.getTime(); - } - - /** - * Set the last day of month to the date in argument. - * The value depends on the month of the date. (30 april, 28 february, ...) - * - * @param date Date to modify - * @return the date with day of month modified - */ - public static Date setLastDayOfMonth(Date date) { - Calendar calendar = getDefaultCalendar(date); - int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); - calendar.set(Calendar.DAY_OF_MONTH, maximum); - return calendar.getTime(); - } - - /** - * Set the first day of month to the date in argument. - * - * @param date Date to modify - * @return the date with day of month modified - */ - public static Date setFirstDayOfMonth(Date date) { - Calendar calendar = getDefaultCalendar(date); - calendar.set(Calendar.DAY_OF_MONTH, 1); - return calendar.getTime(); - } - - /** - * Set the min time of the day : 00:00:00.000. - * - * @param date to modify - * @return Date with the time set to the minimum in the day - */ - public static Date setMinTimeOfDay(Date date) { - Calendar calendar = getDefaultCalendar(date); - calendar.set(Calendar.AM_PM, Calendar.AM); - calendar.set(Calendar.HOUR, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - return calendar.getTime(); - } - - /** - * Set the max time of the day. EUROPE : 23:59:59.999. - * - * @param date to modify - * @return Date with the time set to the maximum in the day - */ - public static Date setMaxTimeOfDay(Date date) { - Calendar calendar = getDefaultCalendar(date); - calendar.set(Calendar.AM_PM, Calendar.PM); - calendar.set(Calendar.HOUR, 11); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); - return calendar.getTime(); - } - - /** - * Check if the first date in argument is included between the two other - * dates. The argument myDate can be equals to beforeDate or afterDate to - * validate the includes. - * - * @param myDate the date to test - * @param beforeDate the first date of the period to test - * @param afterDate the second date of the period to test - * @return true if myDate is included between beforeDate and afterDate - */ - public static boolean between(Date myDate, Date beforeDate, Date afterDate) { - if (myDate == null) { - return false; - } - boolean result = true; - result &= myDate.after(beforeDate) || myDate.compareTo(beforeDate) == 0; - result &= afterDate == null || myDate.before(afterDate) || - myDate.compareTo(afterDate) == 0; - return result; - } - - /** - * Check if the current date is between the two dates in argument. - * - * @param beforeDate the first date of the period - * @param afterDate the second date of the period - * @return true if the current date is included between the two dates, - * false otherwise - * @see #between(Date, Date, Date) - */ - public static boolean currentPeriod(Date beforeDate, Date afterDate) { - return between(new Date(), beforeDate, afterDate); - } - - /** - * Get the month value from a date (between 0 and 11). - * - * @param date the date to extract month - * @return the month value of the date - */ - public static int getMonth(Date date) { - Calendar calendar = getDefaultCalendar(date); - return calendar.get(Calendar.MONTH); - } - - /** - * Do the difference between the two dates in argument. The result is a number - * of seconds between the two dates. - * - * @param beginDate first date - * @param endDate second date - * @return a number of seconds between beginDate and endDate - */ - public static int getDifferenceInSeconds(Date beginDate, Date endDate) { - long begin = beginDate.getTime(); - long end = endDate.getTime(); - return (int) Math.ceil((end - begin) / 1000); - } - - /** - * Do the difference between the two dates in argument. The result is a number - * of minutes between the two dates. - * - * @param beginDate first date - * @param endDate second date - * @return a number of minutes between beginDate and endDate - */ - public static int getDifferenceInMinutes(Date beginDate, Date endDate) { - long begin = beginDate.getTime(); - long end = endDate.getTime(); - // 60000 = 60 * 1000 - return (int) Math.ceil((end - begin) / 60000); - } - - /** - * Do the difference between the two dates in argument. The result is a number - * of hours between the two dates. - * - * @param beginDate first date - * @param endDate second date - * @return a number of hours between beginDate and endDate - */ - public static int getDifferenceInHours(Date beginDate, Date endDate) { - long begin = beginDate.getTime(); - long end = endDate.getTime(); - // 3600000 = 60 * 60 * 1000 - return (int) Math.ceil((end - begin) / 3600000); - } - - /** - * Do the difference between the two dates in argument. The result is a number - * of days between the two dates. - * Ex : 28/01/2009 and 08/02/2009 return 11. - * - * @param beginDate first date - * @param endDate second date - * @return a number of days between beginDate and endDate - */ - public static int getDifferenceInDays(Date beginDate, Date endDate) { - long begin = beginDate.getTime(); - long end = endDate.getTime(); - // 86400000 = 24 * 60 * 60 * 1000 - return (int) Math.ceil((end - begin) / 86400000); - } - - /** - * Do the difference between the two dates in argument. The result is a number - * of months between the two dates. - * Ex : 01/01/2009 and 28/02/2009 return 2 months. - * Warning, if beginDate is inferior to endDate, the result will be 1 minimum - * - * @param beginDate first date - * @param endDate second date - * @return a number of months between beginDate and endDate - */ - public static int getDifferenceInMonths(Date beginDate, Date endDate) { - int count = 0; - Calendar fromCalendar = getDefaultCalendar(beginDate); - Calendar thruCalendar = getDefaultCalendar(endDate); - - while (fromCalendar.before(thruCalendar)) { - fromCalendar.add(Calendar.MONTH, 1); - count++; - } - return count; - } - - /** - * Get libelle of the month corresponding to the number given in argument. - * - * @param monthNumber between 1-12 - * @param locale Locale for language support - * @return a String corresponding to the libelle of the month - */ - public static String getMonthLibelle(int monthNumber, Locale locale) { - return new DateFormatSymbols(locale).getMonths()[monthNumber-1]; - } - - /** - * Get libelle of the month corresponding to the number given in argument. - * - * @param monthNumber between 1-12 - * @return a String corresponding to the libelle of the month - */ - public static String getMonthLibelle(int monthNumber) { - return getMonthLibelle(monthNumber, Locale.getDefault()); - } - - /** - * Get the date before today - * - * @param date concerned - * @return Date before today - */ - public static Date getYesterday(Date date) { - Calendar cal = getDefaultCalendar(date); - cal.roll(Calendar.DAY_OF_MONTH, false); - return cal.getTime(); - } - - /** - * Get the calendar corresponding to the {@code date}. The default calendar - * will be returned (default time zone and locale). - * - * @param date used to set the calendar time - * @return the default calendar with time corresponding to the {@code date} - */ - public static Calendar getDefaultCalendar(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - return calendar; - } -} Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java 2011-01-20 15:26:32 UTC (rev 2027) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -1,105 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.util; - -import org.apache.commons.logging.LogFactory; -import org.apache.commons.logging.Log; - -import java.io.File; -import java.io.IOException; - -/** - * TODO tchemit 2010-08-25 : Why a Test thing is here ? Move it to the test and expose nuiton-utils with a test classifier. - * - * This class contains useful methods for Tests. - * - * Created: 22 juin 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @deprecated since 1.5.3, will not be replaced here and will be removed in 2.0 - */ -@Deprecated -public class TestUtil { - - private static Log log = LogFactory.getLog(TestUtil.class); - - public static final String TESTS_DATA_DEFAULT_DIR = "surefire-data"; - - /** - * Create a directory in target directory for maven projects. The - * directory name will be the default one defined by {@link #TESTS_DATA_DEFAULT_DIR} - * - * @return the directory created - * @see #createTestsDataDirectory(String) - */ - public static File createDefaultTestsDataDirectory() { - return createTestsDataDirectory(TESTS_DATA_DEFAULT_DIR); - } - - /** - * Create a directory in target directory for maven projects. The - * directory will be called {@code dirName}. This directory will be useful - * to put all data created during tests. - * - * @param dirName name of the directory to create - * @return the directory created - */ - public static File createTestsDataDirectory(String dirName) { - // Search basedir from maven environment - String basedirPath = System.getenv("basedir"); - if (basedirPath == null) { - basedirPath = new File("").getAbsolutePath(); - } - - File result = new File(basedirPath, "target" + File.separator + dirName); - - try { - FileUtil.createDirectoryIfNecessary(result); - } catch (IOException eee) { - String errorMessage = "Error during tests data directory creation"; - if (log.isErrorEnabled()) { - log.error(errorMessage, eee); - } - throw new Error(errorMessage, eee); - } - - if (log.isDebugEnabled()) { - log.debug("Create tests data directory : " + result.getAbsolutePath()); - } - - return result; - } - - public static File getBaseDir() { - // Search basedir from maven environment - String basedirPath = System.getenv("basedir"); - if (basedirPath == null) { - basedirPath = new File("").getAbsolutePath(); - } - - File result = new File(basedirPath); - return result; - } -} Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java 2011-01-20 15:26:32 UTC (rev 2027) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -67,7 +67,7 @@ } /** - * Test of formatDate method, of class DateUtils. + * Test of formatDate method, of class DateUtil. */ //@Test public void testFormatDate() { @@ -75,7 +75,7 @@ } /** - * Test of parseDate method, of class DateUtils. + * Test of parseDate method, of class DateUtil. */ //@Test public void testParseDate() { @@ -83,7 +83,7 @@ } /** - * Test of createDate method, of class DateUtils. + * Test of createDate method, of class DateUtil. */ @Test public void testCreateDate() throws ParseException { Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java 2011-01-20 15:26:32 UTC (rev 2027) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -1,292 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; - -/** - * - * @author fdesbois - * @deprecated since 1.4.1, use now {@link DateUtilTest} - */ -@Deprecated -public class DateUtilsTest { - - /** Logger */ - private static final Log log = LogFactory.getLog(DateUtilsTest.class); - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of formatDate method, of class DateUtils. - */ - //@Test - public void testFormatDate() { - log.info("formatDate"); - } - - /** - * Test of parseDate method, of class DateUtils. - */ - //@Test - public void testParseDate() { - log.info("parseDate"); - } - - /** - * Test of createDate method, of class DateUtils. - */ - @Test - public void testCreateDate() { - log.info("createDate"); - - Date newdate = DateUtils.createDate(3, 3, 2009); - Calendar calendar = DateUtils.getDefaultCalendar(newdate); - - Assert.assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH)); - Assert.assertEquals(2, calendar.get(Calendar.MONTH)); - Assert.assertEquals(2009, calendar.get(Calendar.YEAR)); - - Assert.assertEquals(0, calendar.get(Calendar.HOUR)); - Assert.assertEquals(0, calendar.get(Calendar.MINUTE)); - Assert.assertEquals(0, calendar.get(Calendar.SECOND)); - Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND)); - } - - /** - * Test of createDateAfterToday method, of class DateUtils. - */ - //@Test - public void testCreateDateAfterToday() { - log.info("createDateAfterToday"); - } - - /** - * Test of setLastDayOfMonth method, of class DateUtils. - */ - //@Test - public void testSetLastDayOfMonth() { - log.info("setLastDayOfMonth"); - } - - /** - * Test of setFirstDayOfMonth method, of class DateUtils. - */ - //@Test - public void testSetFirstDayOfMonth() { - log.info("setFirstDayOfMonth"); - } - - /** - * Test of between method, of class DateUtils. - */ - @Test - public void testBetween() { - log.info("between"); - - Date middle = DateUtils.createDate(3, 3, 2009); - - // middle = begin, and end = null - Date begin = DateUtils.createDate(3, 3, 2009); - Date end = null; - - boolean result = DateUtils.between(middle, begin, end); - Assert.assertTrue(result); - - // middle between the period : march 2009 - PeriodDates period = new PeriodDates(begin, begin); - period.initDayOfMonthExtremities(); - - log.info("period : " + period); - - result = DateUtils.between(middle, period.getFromDate(), period.getThruDate()); - Assert.assertTrue(result); - - // middle = period begin - middle = DateUtils.setFirstDayOfMonth(middle); - result = DateUtils.between(middle, period.getFromDate(), period.getThruDate()); - Assert.assertTrue(result); - - // test with different implementation of Date - Timestamp middle2 = new Timestamp(middle.getTime()); - result = DateUtils.between(middle2, period.getFromDate(), period.getThruDate()); - Assert.assertTrue(result); - - // middle before begin - middle = DateUtils.createDate(2, 2, 2009); - result = DateUtils.between(middle, period.getFromDate(), period.getThruDate()); - Assert.assertFalse(result); - } - - /** - * Test of currentPeriod method, of class DateUtils. - */ - //@Test - public void testCurrentPeriod() { - log.info("currentPeriod"); - } - - /** - * Test of getMonth method, of class DateUtils. - */ - //@Test - public void testGetMonth() { - log.info("getMonth"); - } - - @Test - public void testGetDifferenceInSeconds() { - log.info("getDifferenceInSecondes"); - - Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009); - Date endDate = DateUtils.createDate(0, 11, 0, 3, 2, 2009); - - int result = DateUtils.getDifferenceInSeconds(beginDate, endDate); - Assert.assertEquals(30, result); - - beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009); - endDate = DateUtils.createDate(50, 30, 0, 28, 1, 2009); - - result = DateUtils.getDifferenceInSeconds(beginDate, endDate); - Assert.assertEquals(161, result); - } - - @Test - public void testGetDifferenceInMinutes() { - log.info("getDifferenceInMinutes"); - - Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009); - Date endDate = DateUtils.createDate(0, 12, 0, 3, 2, 2009); - - int result = DateUtils.getDifferenceInMinutes(beginDate, endDate); - Assert.assertEquals(1, result); - - beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009); - endDate = DateUtils.createDate(50, 30, 0, 28, 1, 2009); - - result = DateUtils.getDifferenceInMinutes(beginDate, endDate); - Assert.assertEquals(2, result); - } - - @Test - public void testGetDifferenceInHours() { - log.info("getDifferenceInHours"); - - Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009); - Date endDate = DateUtils.createDate(0, 11, 0, 4, 2, 2009); - - int result = DateUtils.getDifferenceInHours(beginDate, endDate); - Assert.assertEquals(24, result); - - beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009); - endDate = DateUtils.createDate(50, 30, 8, 28, 1, 2009); - - result = DateUtils.getDifferenceInHours(beginDate, endDate); - Assert.assertEquals(8, result); - } - - @Test - public void testGetDifferenceInDays() { - log.info("getDifferenceInDays"); - - Date beginDate = DateUtils.createDate(3, 2, 2009); - Date endDate = DateUtils.createDate(8, 2, 2009); - - int result = DateUtils.getDifferenceInDays(beginDate, endDate); - Assert.assertEquals(5, result); - - beginDate = DateUtils.createDate(28, 1, 2009); - endDate = DateUtils.createDate(8, 2, 2009); - - result = DateUtils.getDifferenceInDays(beginDate, endDate); - Assert.assertEquals(11, result); - } - - @Test - public void testGetDifferenceInMonths() { - log.info("getDifferenceInMonths"); - - Date beginDate = DateUtils.createDate(3, 2, 2009); - Date endDate = DateUtils.createDate(8, 8, 2010); - - int result = DateUtils.getDifferenceInMonths(beginDate, endDate); - log.info("result1 : " + result); - Assert.assertEquals(19, result); - - beginDate = DateUtils.createDate(1, 1, 2009); - endDate = DateUtils.createDate(28, 2, 2009); - - result = DateUtils.getDifferenceInMonths(beginDate, endDate); - log.info("result2 : " + result); - Assert.assertEquals(2, result); - - beginDate = DateUtils.createDate(31, 1, 2009); - endDate = DateUtils.createDate(1, 2, 2009); - - result = DateUtils.getDifferenceInMonths(beginDate, endDate); - log.info("result3 : " + result); - Assert.assertEquals(1, result); - } - - @Test - public void testGetMonthLibelle() { - log.info("getMonthLibelle"); - - Locale.setDefault(Locale.FRENCH); - String janvier = DateUtils.getMonthLibelle(1); - Assert.assertEquals("janvier", janvier); - - String juli = DateUtils.getMonthLibelle(7, Locale.GERMAN); - Assert.assertEquals("Juli", juli); - } - -} Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java 2011-01-20 15:26:32 UTC (rev 2027) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -107,9 +107,9 @@ @Test public void testCopyRecursively() throws Exception { - File srcDir = FileUtil.createTempDirectory("test-copyRecursively", ""); - File destDir1 = FileUtil.createTempDirectory("test-copyRecursively", ""); - File destDir2 = FileUtil.createTempDirectory("test-copyRecursively", ""); + File srcDir = FileUtil.createTempDirectory("test-copyRecursively", "", parent); + File destDir1 = FileUtil.createTempDirectory("test-copyRecursively", "", parent); + File destDir2 = FileUtil.createTempDirectory("test-copyRecursively", "", parent); new File(srcDir, "toto").createNewFile(); new File(srcDir, "titi").createNewFile(); @@ -265,9 +265,8 @@ @Test public void testSedComment() throws IOException { - //FIXME tchemit 20100924 Do tests in target, not in /tmp please! // try to not make sed in real src dir ;) - File testDirectory = FileUtil.createTempDirectory("sed", "test"); + File testDirectory = FileUtil.createTempDirectory("sed", "test", parent); FileUtil.copyRecursively(new File("src").getAbsoluteFile(), testDirectory); File testUtilFile = FileUtil.find(testDirectory, ".*FileUtil\\.java", true).get(0); @@ -289,7 +288,7 @@ @BeforeClass public static void beforeTest() { - parent = TestUtil.createTestsDataDirectory("FileUtil"); + parent = TestHelper.createTestsDataDirectory("FileUtil"); } public void testChangeExtension() throws IOException { Added: trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java (rev 0) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java 2011-01-22 10:37:02 UTC (rev 2028) @@ -0,0 +1,78 @@ +package org.nuiton.util; + +import org.apache.commons.logging.*; +import org.apache.commons.logging.Log; +import org.junit.Ignore; + +import java.io.File; +import java.io.IOException; + +/** + * Usefeull methods to do tests. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +@Ignore +public class TestHelper { + + private static Log log = LogFactory.getLog(TestHelper.class); + + public static final String TESTS_DATA_DEFAULT_DIR = "surefire-workdir"; + + /** + * Create a directory in target directory for maven projects. The + * directory name will be the default one defined by {@link #TESTS_DATA_DEFAULT_DIR} + * + * @return the directory created + * @see #createTestsDataDirectory(String) + */ + public static File createDefaultTestsDataDirectory() { + return createTestsDataDirectory(TESTS_DATA_DEFAULT_DIR); + } + + /** + * Create a directory in target directory for maven projects. The + * directory will be called {@code dirName}. This directory will be useful + * to put all data created during tests. + * + * @param dirName name of the directory to create + * @return the directory created + */ + public static File createTestsDataDirectory(String dirName) { + // Search basedir from maven environment + String basedirPath = System.getenv("basedir"); + if (basedirPath == null) { + basedirPath = new File("").getAbsolutePath(); + } + + File result = new File(basedirPath, "target" + File.separator + dirName); + + try { + FileUtil.createDirectoryIfNecessary(result); + } catch (IOException eee) { + String errorMessage = "Error during tests data directory creation"; + if (log.isErrorEnabled()) { + log.error(errorMessage, eee); + } + throw new Error(errorMessage, eee); + } + + if (log.isDebugEnabled()) { + log.debug("Create tests data directory : " + result.getAbsolutePath()); + } + + return result; + } + + public static File getBaseDir() { + // Search basedir from maven environment + String basedirPath = System.getenv("basedir"); + if (basedirPath == null) { + basedirPath = new File("").getAbsolutePath(); + } + + File result = new File(basedirPath); + return result; + } +} Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native
participants (1)
-
tchemit@users.nuiton.org