pax_global_header00006660000000000000000000000064124301753070014514gustar00rootroot0000000000000052 comment=e0f965be0e55201f3458f756e157d010fb9f95bf fest-util-1.2.5/000077500000000000000000000000001243017530700134355ustar00rootroot00000000000000fest-util-1.2.5/.gitignore000066400000000000000000000001351243017530700154240ustar00rootroot00000000000000/target /fest-util.iws /fest-util.iml /fest-util.ipr /.idea /.classpath /.project /.settings fest-util-1.2.5/LICENSE.txt000066400000000000000000000261361243017530700152700ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. fest-util-1.2.5/README.md000066400000000000000000000004271243017530700147170ustar00rootroot00000000000000Common utilities used in all FEST modules. To prevent this project to include everything even the kitchen sink, the scope of this project is to contain utilities needed in two or more FEST modules. For more details please visit [FEST's home page](http://fest.easytesting.org).fest-util-1.2.5/pom.xml000066400000000000000000000031611243017530700147530ustar00rootroot00000000000000 4.0.0 fest-util 1.2.5 FEST Util Utility methods used by FEST modules 2007 http://fest.easytesting.org org.easytesting fest 1.0.15 Easy Testing Group http://groups.google.com/group/easytesting http://groups.google.com/group/easytesting http://groups.google.com/group/easytesting scm:git:git@github.com:alexruiz/fest-util.git scm:git:git://github.com/alexruiz/fest-util.git https://github.com/alexruiz/fest-util junit junit org.mockito mockito-all 1.9.0 test github https://github.com/alexruiz/fest-util/issues fest-util-1.2.5/release-notes.txt000066400000000000000000000011511243017530700167420ustar00rootroot00000000000000For the next release -------------------- 1.2.4 release notes ------------------- This version is a "compatibility" version so that fest-assert-core 2.0M9 plays nicely with fest-reflect 1.4.1 (both depending on fest-util 1.2.4) Additional Fix - github #13 Iterables.sizeOf(Iterable iterable) runs into infinite loop for non-collection Iterable Improvement - use 1.0.15 parent pom that enables java 6 compatibility check 1.2.2 release notes ------------------- - nonNullElements now accepts Iterable instead of Collection (Florent Biville) - use 1.0.14 parent pom that enables java 5 compatibility check fest-util-1.2.5/src/000077500000000000000000000000001243017530700142245ustar00rootroot00000000000000fest-util-1.2.5/src/main/000077500000000000000000000000001243017530700151505ustar00rootroot00000000000000fest-util-1.2.5/src/main/java/000077500000000000000000000000001243017530700160715ustar00rootroot00000000000000fest-util-1.2.5/src/main/java/org/000077500000000000000000000000001243017530700166605ustar00rootroot00000000000000fest-util-1.2.5/src/main/java/org/fest/000077500000000000000000000000001243017530700176215ustar00rootroot00000000000000fest-util-1.2.5/src/main/java/org/fest/util/000077500000000000000000000000001243017530700205765ustar00rootroot00000000000000fest-util-1.2.5/src/main/java/org/fest/util/ArrayFormatter.java000066400000000000000000000064171243017530700244130ustar00rootroot00000000000000/* * Created on Mar 29, 2009 * * 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. * * Copyright @2009-2012 the original author or authors. */ package org.fest.util; import static java.lang.reflect.Array.getLength; import static org.fest.util.Arrays.isArray; import static org.fest.util.ToString.toStringOf; import java.lang.reflect.Array; import java.util.HashSet; import java.util.Set; /** * Creates a {@code String} representation of an array. * * @author Alex Ruiz * @author Joel Costigliola */ final class ArrayFormatter { private static final String NULL = "null"; String format(Object o) { if (!isArray(o)) { return null; } return isObjectArray(o) ? formatObjectArray(o) : formatPrimitiveArray(o); } private String formatObjectArray(Object o) { Object[] array = (Object[]) o; int size = array.length; if (size == 0) { return "[]"; } StringBuilder buffer = new StringBuilder((20 * (size - 1))); deepToString(array, buffer, new HashSet()); return buffer.toString(); } private void deepToString(Object[] array, StringBuilder buffer, Set alreadyFormatted) { if (array == null) { buffer.append(NULL); return; } alreadyFormatted.add(array); buffer.append('['); int size = array.length; for (int i = 0; i < size; i++) { if (i != 0) { buffer.append(", "); } Object element = array[i]; if (!isArray(element)) { buffer.append(element == null ? NULL : toStringOf(element)); continue; } if (!isObjectArray(element)) { buffer.append(formatPrimitiveArray(element)); continue; } if (alreadyFormatted.contains(element)) { buffer.append("[...]"); continue; } deepToString((Object[]) element, buffer, alreadyFormatted); } buffer.append(']'); alreadyFormatted.remove(array); } private boolean isObjectArray(Object o) { return isArray(o) && !isArrayTypePrimitive(o); } private String formatPrimitiveArray(Object o) { if (!isArray(o)) { return null; } if (!isArrayTypePrimitive(o)) { throw notAnArrayOfPrimitives(o); } int size = getLength(o); if (size == 0) { return "[]"; } StringBuilder buffer = new StringBuilder(); buffer.append('['); buffer.append(Array.get(o, 0)); for (int i = 1; i < size; i++) { buffer.append(", "); buffer.append(Array.get(o, i)); } buffer.append("]"); return buffer.toString(); } private boolean isArrayTypePrimitive(Object o) { return o.getClass().getComponentType().isPrimitive(); } private IllegalArgumentException notAnArrayOfPrimitives(Object o) { return new IllegalArgumentException(String.format("<%s> is not an array of primitives", o)); } } fest-util-1.2.5/src/main/java/org/fest/util/Arrays.java000066400000000000000000000075151243017530700227120ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static java.util.Collections.emptyList; import static org.fest.util.Preconditions.checkNotNull; import java.util.*; /** * Utility methods related to arrays. * * @author Alex Ruiz * @author Joel Costigliola */ public class Arrays { private static final ArrayFormatter FORMATTER = new ArrayFormatter(); /** * Indicates whether the given object is not {@code null} and is an array. * * @param o the given object. * @return {@code true} if the given object is not {@code null} and is an array, otherwise {@code false}. */ public static boolean isArray(Object o) { return o != null && o.getClass().isArray(); } /** * Indicates whether the given array is {@code null} or empty. * * @param the type of elements of the array. * @param array the array to check. * @return {@code true} if the given array is {@code null} or empty, otherwise {@code false}. */ public static boolean isNullOrEmpty(T[] array) { return array == null || !hasElements(array); } /** * Returns an array containing the given arguments. * * @param the type of the array to return. * @param values the values to store in the array. * @return an array containing the given arguments. */ public static T[] array(T... values) { return values; } /** * Returns the {@code String} representation of the given array, or {@code null} if the given object is either * {@code null} or not an array. This method supports arrays having other arrays as elements. * * @param array the object that is expected to be an array. * @return the {@code String} representation of the given array. */ public static String format(Object array) { return FORMATTER.format(array); } /** * Returns all the non-{@code null} elements in the given array. * * @param the type of elements of the array. * @param array the given array. * @return all the non-{@code null} elements in the given array. An empty list is returned if the given array is * {@code null}. * @since 1.1.3 */ public static List nonNullElementsIn(T[] array) { if (array == null) { return emptyList(); } List nonNullElements = new ArrayList(); for (T o : array) { if (o != null) { nonNullElements.add(o); } } return nonNullElements; } /** * Returns {@code true} if the given array has only {@code null} elements, {@code false} otherwise. If given array is * empty, this method returns {@code true}. * * @param the type of elements of the array. * @param array the given array. It must not be null. * @return {@code true} if the given array has only {@code null} elements or is empty, {@code false} otherwise. * @throws NullPointerException if the given array is {@code null}. * @since 1.1.3 */ public static boolean hasOnlyNullElements(T[] array) { checkNotNull(array); if (!hasElements(array)) { return false; } for (T o : array) { if (o != null) { return false; } } return true; } private static boolean hasElements(T[] array) { return array.length > 0; } private Arrays() {} } fest-util-1.2.5/src/main/java/org/fest/util/Closeables.java000066400000000000000000000027401243017530700235200ustar00rootroot00000000000000/* * Created on Jan 15, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import java.io.Closeable; import java.util.logging.Level; import java.util.logging.Logger; /** * Utility methods related to {@link Closeable}. * * @author Yvonne Wang */ public final class Closeables { private static Logger logger = Logger.getLogger(Closeables.class.getCanonicalName()); /** * Closes the given {@link Closeable}s, ignoring any thrown exceptions. * * @param closeables the {@code Closeable}s to close. */ public static void closeQuietly(Closeable... closeables) { for (Closeable c : closeables) { closeCloseable(c); } } private static void closeCloseable(Closeable c) { if (c == null) { return; } try { c.close(); } catch (Throwable t) { logger.log(Level.WARNING, "Error ocurred while closing " + c, t); } } private Closeables() {} } fest-util-1.2.5/src/main/java/org/fest/util/CollectionFilter.java000066400000000000000000000016631243017530700247100ustar00rootroot00000000000000/* * Created on Nov 1, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import java.util.Collection; import java.util.List; /** * Filters elements in a collection. * * @param the generic type of the elements to return by the filter. * * @author Yvonne Wang */ public interface CollectionFilter { List filter(Collection target); } fest-util-1.2.5/src/main/java/org/fest/util/Collections.java000066400000000000000000000072101243017530700237170ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static java.util.Collections.emptyList; import static org.fest.util.ToString.toStringOf; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; /** * Utility methods related to {@code Collection}s. * * @author Yvonne Wang * @author Alex Ruiz * @author Joel Costigliola */ public final class Collections { /** * Returns any duplicate elements from the given {@code Collection}. * * @param the generic type of the given {@code Collection}. * @param c the given {@code Collection} that might have duplicate elements. * @return a {@code Collection} containing the duplicate elements of the given one. If no duplicates are found, an * empty {@code Collection} is returned. */ public static Collection duplicatesFrom(Collection c) { Set duplicates = new LinkedHashSet(); if (isNullOrEmpty(c)) { return duplicates; } Set noDuplicates = new HashSet(); for (T e : c) { if (noDuplicates.contains(e)) { duplicates.add(e); continue; } noDuplicates.add(e); } return duplicates; } /** * Indicates whether the given {@code Collection} is {@code null} or empty. * * @param c the given {@code Collection}. * @return {@code true} if the given {@code Collection} is {@code null} or empty, otherwise {@code false}. */ public static boolean isNullOrEmpty(Collection c) { return c == null || c.isEmpty(); } /** * Returns the {@code String} representation of the given {@code Collection}, or {@code null} if the given * {@code Collection} is {@code null}. * * @param c the {@code Collection} to format. * @return the {@code String} representation of the given {@code Collection}. */ public static String format(Collection c) { if (c == null) { return null; } Iterator i = c.iterator(); if (!i.hasNext()) { return "[]"; } StringBuilder b = new StringBuilder(); b.append('['); for (;;) { Object e = i.next(); b.append(e == c ? "(this Collection)" : toStringOf(e)); if (!i.hasNext()) { return b.append(']').toString(); } b.append(", "); } } /** * Returns all the non-{@code null} elements in the given {@link Collection}. * * @param the type of elements of the {@code Collection}. * @param c the given {@code Collection}. * @return all the non-{@code null} elements in the given {@code Collection}. An empty list is returned if the * given {@code Collection} is {@code null}. * @since 1.1.3 */ public static List nonNullElementsIn(Collection c) { if (isNullOrEmpty(c)) { return emptyList(); } List nonNull = new ArrayList(); for (T element : c) { if (element != null) { nonNull.add(element); } } return nonNull; } private Collections() {} } fest-util-1.2.5/src/main/java/org/fest/util/Dates.java000066400000000000000000000207101243017530700225010ustar00rootroot00000000000000/* * Created on Jan 22, 2011 * * 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. * * Copyright @2011 the original author or authors. */ package org.fest.util; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Utility methods related to dates. * * @author Joel Costigliola */ public class Dates { /** * ISO 8601 date format (yyyy-MM-dd), example : 2003-04-23 */ public static final DateFormat ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); /** * ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : 2003-04-26T13:01:02 */ public static final DateFormat ISO_DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); /** * ISO 8601 date-time format with millisecond (yyyy-MM-dd'T'HH:mm:ss.SSS), example : 2003-04-26T03:01:02.999 */ public static final DateFormat ISO_DATE_TIME_FORMAT_WITH_MS = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); /** * Formats the given date using the ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss).
* Method in synchronized because SimpleDateFormat is not thread safe (sigh). *

* Returns null if given the date is null. * @param date the date to format. * @return the formatted date or null if given the date was null. */ public static synchronized String formatAsDatetime(Date date) { return date == null ? null : ISO_DATE_TIME_FORMAT.format(date); } /** * Formats the given date using the ISO 8601 date-time format with millisecond (yyyy-MM-dd'T'HH:mm:ss:SSS).
* Method in synchronized because SimpleDateFormat is not thread safe (sigh). *

* Returns null if given the date is null. * @param date the date to format. * @return the formatted date or null if given the date was null. */ public static synchronized String formatAsDatetimeWithMs(Date date) { return date == null ? null : ISO_DATE_TIME_FORMAT_WITH_MS.format(date); } /** * Formats the date of the given calendar using the ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss).
* Method is thread safe. *

* Returns null if the given calendar is null. * @param calendar the calendar to format. * @return the formatted calendar or null if the given calendar was null. */ public static String formatAsDatetime(Calendar calendar) { return calendar == null ? null : formatAsDatetime(calendar.getTime()); } /** * Utility method to parse a Date following {@link #ISO_DATE_FORMAT}, returns null if the given String is null. * @param dateAsString the string to parse as a Date following {@link #ISO_DATE_FORMAT} * @return the corrresponding Date or null if the given String is null. * @throws RuntimeException encapsulating ParseException if the string can't be parsed as a Date */ public static Date parse(String dateAsString) { try { return dateAsString == null ? null : ISO_DATE_FORMAT.parse(dateAsString); } catch (ParseException e) { throw new RuntimeException(e); } } /** * Utility method to parse a Date following {@link #ISO_DATE_TIME_FORMAT}, returns null if the given String is null. * @param dateAsString the string to parse as a Date following {@link #ISO_DATE_TIME_FORMAT} * @return the corrresponding Date with time details or null if the given String is null. * @throws RuntimeException encapsulating ParseException if the string can't be parsed as a Date */ public static Date parseDatetime(String dateAsString) { try { return dateAsString == null ? null : ISO_DATE_TIME_FORMAT.parse(dateAsString); } catch (ParseException e) { throw new RuntimeException(e); } } /** * Converts the given Date to Calendar, returns null if the given Date is null. * @param date the date to convert to a Calendar. * @return the Calendar corresponding to the given Date or null if the given Date is null. */ public static Calendar toCalendar(Date date) { if (date == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } /** * Extracts the year of the given Date. * @param date the date to extract the year from - must not be null. * @return the year of the given Date * @throws NullPointerException if given Date is null */ public static int yearOf(Date date) { return toCalendar(date).get(Calendar.YEAR); } /** * Dates Extracts the month of the given Date starting at 1 (January=1, February=2, ...). * @param date the date to extract the month from - must not be null. * @return the month of the given Date starting at 1 (January=1, February=2, ...) * @throws NullPointerException if given Date is null */ public static int monthOf(Date date) { return toCalendar(date).get(Calendar.MONTH) + 1; // based 1 month (January=1) } /** * Dates Extracts the day of month of the given Date. * @param date the date to extract the day of month from - must not be null. * @return the day of month of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfMonthOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_MONTH); } /** * Extracts the day of week of the given Date, returned value follows {@link Calendar#DAY_OF_WEEK} . * @param date the date to extract the day of week from - must not be null. * @return the day of week of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfWeekOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_WEEK); } /** * Extracts the hour of day if the given Date (24-hour clock). * @param date the date to extract the hour of day from - must not be null. * @return the hour of day of the given Date (24-hour clock) * @throws NullPointerException if given Date is null */ public static int hourOfDay(Date date) { return toCalendar(date).get(Calendar.HOUR_OF_DAY); } /** * Dates Extracts the minute of the given Date. * @param date the date to extract the minute from - must not be null. * @return the minute of the given Date * @throws NullPointerException if given Date is null */ public static int minuteOf(Date date) { return toCalendar(date).get(Calendar.MINUTE); } /** * Extracts the second of the given Date. * @param date the date to extract the second from - must not be null. * @return the second of the given Date * @throws NullPointerException if given Date is null */ public static int secondOf(Date date) { return toCalendar(date).get(Calendar.SECOND); } /** * Extracts the millisecond of the given Date. * @param date the date to extract the millisecond from - must not be null. * @return the millisecond of the given Date * @throws NullPointerException if given Date is null */ public static int millisecondOf(Date date) { return toCalendar(date).get(Calendar.MILLISECOND); } /** * Returns a copy of the given date without the time part (which is set to 00:00:00), for example :
* truncateTime(2008-12-29T23:45:12) will give 2008-12-29T00:00:00. *

* Returns null if the given Date is null. * @param date we want to get the day part (the parameter is read only). * @return the truncated date. */ public static Date truncateTime(Date date) { if (date == null) { return null; } Calendar cal = toCalendar(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); } public static Date today() { return new Date(); } public static Date yesterday() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -1); return cal.getTime(); } public static Date tomorrow() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, 1); return cal.getTime(); } } fest-util-1.2.5/src/main/java/org/fest/util/FailureMessages.java000066400000000000000000000016651243017530700245300ustar00rootroot00000000000000/* * Created on Sep 7, 2010 * * 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. * * Copyright @2010-2011 the original author or authors. */ package org.fest.util; /** * @author Alex Ruiz */ public final class FailureMessages { public static String actualIsEmpty() { return "expecting actual not to be empty"; } public static String actualIsNull() { return "expecting actual not to be null"; } private FailureMessages() {} } fest-util-1.2.5/src/main/java/org/fest/util/Files.java000066400000000000000000000243261243017530700225120ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2012 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static java.lang.String.*; import static org.fest.util.Arrays.isNullOrEmpty; import static org.fest.util.Closeables.closeQuietly; import static org.fest.util.Flushables.flush; import static org.fest.util.Strings.*; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; /** * Utility methods related to files. * * @author Yvonne Wang * @author Alex Ruiz */ public class Files { /** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); if (!dir.isDirectory()) { throw new IllegalArgumentException(format("%s is not a directory", quote(dirName))); } return fileNamesIn(dir, recurse); } /** * Returns the names of the files inside the specified directory. * * @param dir the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. */ private static List fileNamesIn(File dir, boolean recurse) { List scriptNames = new ArrayList(); File[] existingFiles = dir.listFiles(); if (isNullOrEmpty(existingFiles)) { return scriptNames; } for (File existingFile : existingFiles) { if (existingFile.isDirectory()) { if (recurse) { scriptNames.addAll(fileNamesIn(existingFile, recurse)); } continue; } String filename = existingFile.getAbsolutePath(); if (!scriptNames.contains(filename)) { scriptNames.add(filename); } } return scriptNames; } /** * Returns the system's temporary directory. * * @return the system's temporary directory. * @throws FilesException if this method cannot find or create the system's temporary directory. */ public static File temporaryFolder() { File temp = new File(temporaryFolderPath()); if (!temp.isDirectory()) { throw new FilesException("Unable to find temporary directory"); } return temp; } /** * Returns the path of the system's temporary directory. This method appends the system's file separator at the end of * the path. * * @return the path of the system's temporary directory. */ public static String temporaryFolderPath() { return append(separator).to(System.getProperty("java.io.tmpdir")); } /** * Creates a new file in the system's temporary directory. The name of the file will be the result of: * *

   * concat(String.valueOf(System.currentTimeMillis()), ".txt");
   * 
* * @return the created file. */ public static File newTemporaryFile() { String tempFileName = concat(valueOf(System.currentTimeMillis()), ".txt"); return newFile(concat(temporaryFolderPath(), tempFileName)); } /** * Creates a new directory in the system's temporary directory. The name of the directory will be the result of: * *
   * System.currentTimeMillis();
   * 
* * @return the created file. */ public static File newTemporaryFolder() { String tempFileName = String.valueOf(System.currentTimeMillis()); return newFolder(concat(temporaryFolderPath(), tempFileName)); } /** * Creates a new file using the given path. * * @param path the path of the new file. * @return the new created file. * @throws FilesException if the path belongs to an existing non-empty directory. * @throws FilesException if the path belongs to an existing file. * @throws FilesException if any I/O error is thrown when creating the new file. */ public static File newFile(String path) { File file = new File(path); if (file.isDirectory() && !isNullOrEmpty(file.list())) { throw cannotCreateNewFile(path, "a non-empty directory was found with the same path"); } try { if (!file.createNewFile()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (IOException e) { throw cannotCreateNewFile(path, e); } return file; } /** * Creates a new directory using the given path. * * @param path the path of the new directory. * @return the new created directory. * @throws FilesException if the path belongs to an existing non-empty directory. * @throws FilesException if the path belongs to an existing file. * @throws FilesException if any I/O error is thrown when creating the new directory. */ public static File newFolder(String path) { File file = new File(path); if (file.isDirectory() && !isNullOrEmpty(file.list())) { throw cannotCreateNewFile(path, "a non-empty directory was found with the same path"); } try { if (!file.mkdir()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (Exception e) { throw cannotCreateNewFile(path, e); } return file; } private static FilesException cannotCreateNewFile(String path, String reason) { throw cannotCreateNewFile(path, reason, null); } private static FilesException cannotCreateNewFile(String path, Exception cause) { throw cannotCreateNewFile(path, null, cause); } private static FilesException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause != null) { throw new FilesException(message, cause); } throw new FilesException(message); } /** * Flushes and closes the given {@link Writer}. Any I/O errors catched by this method are ignored and not * rethrown. * * @param writer the writer to flush and close. */ public static void flushAndClose(Writer writer) { if (writer == null) { return; } flush(writer); closeQuietly(writer); } /** * Flushes and closes the given {@link OutputStream}. Any I/O errors catched by this method are ignored * and not rethrown. * * @param out the output stream to flush and close. */ public static void flushAndClose(OutputStream out) { if (out == null) { return; } flush(out); closeQuietly(out); } /** * Returns the current directory. * * @return the current directory. * @throws FilesException if the current directory cannot be obtained. */ public static File currentFolder() { try { return new File(".").getCanonicalFile(); } catch (IOException e) { throw new FilesException("Unable to get current directory", e); } } /** * Deletes the given file or directory. * * @param file the file or directory to delete. */ public static void delete(File file) { if (file.isFile()) { file.delete(); return; } if (!file.isDirectory()) { return; } for (File f : file.listFiles()) { delete(f); } file.delete(); } /** * Loads the text content of a file into a character string. * * @param file the file. * @param charsetName the name of the character set to use. * @return the content of the file. * @throws IllegalArgumentException if the given character set is not supported on this platform. * @throws FilesException if an I/O exception occurs. */ public static String contentOf(File file, String charsetName) { if (!Charset.isSupported(charsetName)) { throw new IllegalArgumentException(String.format("Charset:<'%s'> is not supported on this system", charsetName)); } return contentOf(file, Charset.forName(charsetName)); } /** * Loads the text content of a file into a character string. * * @param file the file. * @param charset the character set to use. * @return the content of the file. * @throws NullPointerException if the given charset is {@code null}. * @throws FilesException if an I/O exception occurs. */ public static String contentOf(File file, Charset charset) { if (charset == null) { throw new NullPointerException("The charset should not be null"); } try { return loadContents(file, charset); } catch (IOException e) { throw new FilesException("Unable to read " + file.getAbsolutePath(), e); } } private static String loadContents(File file, Charset charset) throws IOException { BufferedReader reader = null; boolean threw = true; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); StringWriter writer = new StringWriter(); int c; while ((c = reader.read()) != -1) { writer.write(c); } threw = false; return writer.toString(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { if (!threw) { throw e; // if there was an initial exception, don't hide it } } } } } private Files() {} } fest-util-1.2.5/src/main/java/org/fest/util/FilesException.java000066400000000000000000000024101243017530700243570ustar00rootroot00000000000000/* * Created on May 16, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; /** * Exception thrown by {@link Files}. * * @author Yvonne Wang */ public final class FilesException extends RuntimeException { private static final long serialVersionUID = -8328554403430790831L; /** * Creates a new {@link FilesException}. * * @param message the detail message. */ public FilesException(String message) { super(message); } /** * Creates a new {@link FilesException}. * * @param message the detail message. * @param cause the cause of the error. */ public FilesException(String message, Throwable cause) { super(message, cause); } } fest-util-1.2.5/src/main/java/org/fest/util/Flushables.java000066400000000000000000000024171243017530700235350ustar00rootroot00000000000000/* * Created on Jan 15, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import java.io.Flushable; /** * Utility methods related to {@link Flushable}. * * @author Yvonne Wang */ public class Flushables { /** * Flushes the given {@link Flushable}s, ignoring any thrown exceptions. * * @param flushables the {@code Flushable}s to flush. */ public static void flush(Flushable... flushables) { for (Flushable f : flushables) { flushFlushable(f); } } private static void flushFlushable(Flushable f) { if (f == null) { return; } try { f.flush(); } catch (Exception e) { } } private Flushables() { } } fest-util-1.2.5/src/main/java/org/fest/util/Introspection.java000066400000000000000000000073111243017530700243030ustar00rootroot00000000000000/* * Created on Jun 28, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; import static java.lang.String.format; import static java.lang.reflect.Modifier.isPublic; import static java.util.Locale.ENGLISH; import static org.fest.util.Preconditions.*; import static org.fest.util.Strings.quote; import java.beans.*; import java.lang.reflect.Method; /** * Utility methods related to JavaBeans Introspection. * * @author Alex Ruiz */ public final class Introspection { /** * Returns a {@link PropertyDescriptor} for a property matching the given name in the given object. * * @param propertyName the given property name. * @param target the given object. * @return a {@code PropertyDescriptor} for a property matching the given name in the given object. * @throws NullPointerException if the given property name is {@code null}. * @throws IllegalArgumentException if the given property name is empty. * @throws NullPointerException if the given object is {@code null}. * @throws IntrospectionError if a matching property cannot be found or accessed. */ public static PropertyDescriptor getProperty(String propertyName, Object target) { checkNotNullOrEmpty(propertyName); checkNotNull(target); BeanInfo beanInfo = null; Class type = target.getClass(); try { beanInfo = Introspector.getBeanInfo(type); } catch (Throwable t) { throw new IntrospectionError(format("Unable to get BeanInfo for type %s", type.getName()), t); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (propertyName.equals(descriptor.getName())) { return descriptor; } } throw new IntrospectionError(propertyNotFoundErrorMessage(propertyName, target)); } private static String propertyNotFoundErrorMessage(String propertyName, Object target) { String targetTypeName = target.getClass().getName(); String property = quote(propertyName); Method getter = findGetter(propertyName, target); if (getter == null) { return format("No getter for property %s in %s", property, targetTypeName); } if (!isPublic(getter.getModifiers())) { return format("No public getter for property %s in %s", property, targetTypeName); } return format("Unable to find property %s in %s", property, targetTypeName); } private static Method findGetter(String propertyName, Object target) { String capitalized = propertyName.substring(0, 1).toUpperCase(ENGLISH) + propertyName.substring(1); // try to find getProperty Method getter = findMethod("get" + capitalized, target); if (getter != null) { return getter; } // try to find isProperty for boolean properties return findMethod("is" + capitalized, target); } private static Method findMethod(String name, Object target) { // TODO walk class hierarchy to check if any superclass declares the method we are looking for. try { return target.getClass().getDeclaredMethod(name); } catch (Throwable t) { return null; } } private Introspection() {} } fest-util-1.2.5/src/main/java/org/fest/util/IntrospectionError.java000066400000000000000000000025621243017530700253200ustar00rootroot00000000000000/* * Created on Jun 28, 2010 * * 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. * * Copyright @2010-2011 the original author or authors. */ package org.fest.util; /** * Error that occurred when using JavaBeans * Instrospection. * * @author Alex Ruiz */ public class IntrospectionError extends RuntimeException { private static final long serialVersionUID = 1L; /** * Creates a new {@link IntrospectionError}. * @param message the detail message. */ public IntrospectionError(String message) { super(message); } /** * Creates a new {@link IntrospectionError}. * @param message the detail message. * @param cause the original cause. */ public IntrospectionError(String message, Throwable cause) { super(message, cause); } } fest-util-1.2.5/src/main/java/org/fest/util/Iterables.java000066400000000000000000000055351243017530700233630ustar00rootroot00000000000000/* * Created on Aug 23, 2012 * * 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. * * Copyright @2012 the original author or authors. */ package org.fest.util; import static java.util.Collections.emptyList; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; /** * Utility methods related to {@code Iterable}s. * * @author Yvonne Wang * @author Alex Ruiz * @author Joel Costigliola */ // TODO(alexRuiz): Get rid of this class. public final class Iterables { /** * Indicates whether the given {@link Iterable} is {@code null} or empty. * * @param iterable the given {@code Iterable} to check. * @return {@code true} if the given {@code Iterable} is {@code null} or empty, otherwise {@code false}. */ public static boolean isNullOrEmpty(Iterable iterable) { if (iterable == null) { return true; } if (iterable instanceof Collection && ((Collection) iterable).isEmpty()) { return true; } return !iterable.iterator().hasNext(); } /** * Returns the size of the given {@link Iterable}. * * @param iterable the {@link Iterable} to get size. * @return the size of the given {@link Iterable}. * @throws NullPointerException if given {@link Iterable} is null. */ public static int sizeOf(Iterable iterable) { if (iterable == null) { throw new NullPointerException("Iterable must not be null"); } if (iterable instanceof Collection) { return ((Collection) iterable).size(); } int size = 0; Iterator iterator = iterable.iterator(); while (iterator.hasNext()) { size++; iterator.next(); } return size; } /** * Returns all the non-{@code null} elements in the given {@link Iterable}. * * @param the type of elements of the {@code Iterable}. * @param i the given {@code Iterable}. * @return all the non-{@code null} elements in the given {@code Iterable}. An empty list is returned if the given * {@code Iterable} is {@code null}. * @since 1.1.3 */ public static List nonNullElementsIn(Iterable i) { if (isNullOrEmpty(i)) { return emptyList(); } List nonNull = new ArrayList(); for (T element : i) { if (element != null) { nonNull.add(element); } } return nonNull; } private Iterables() {} } fest-util-1.2.5/src/main/java/org/fest/util/Lists.java000066400000000000000000000040051243017530700225360ustar00rootroot00000000000000/* * Created on Aug 23, 2012 * * 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. * * Copyright @2012 the original author or authors. */ package org.fest.util; import java.util.ArrayList; /** * Utility methods related to {@code java.util.List}s. * * @author Yvonne Wang * @author Alex Ruiz * @author Joel Costigliola */ public final class Lists { /** * Creates a mutable {@link ArrayList} containing the given elements. * * @param the generic type of the {@code ArrayList} to create. * @param elements the elements to store in the {@code ArrayList}. * @return the created {@code ArrayList}, of {@code null} if the given array of elements is {@code null}. */ public static ArrayList newArrayList(T... elements) { if (elements == null) { return null; } ArrayList list = new ArrayList(); for (T e : elements) { list.add(e); } return list; } /** * Creates a mutable {@link ArrayList} containing the given elements. * * @param the generic type of the {@code ArrayList} to create. * @param elements the elements to store in the {@code ArrayList}. * @return the created {@code ArrayList}, of {@code null} if the given {@code Iterable} is {@code null}. */ public static ArrayList newArrayList(Iterable elements) { if (elements == null) { return null; } ArrayList list = new ArrayList(); for (T e : elements) { list.add(e); } return list; } private Lists() {} } fest-util-1.2.5/src/main/java/org/fest/util/Maps.java000066400000000000000000000041641243017530700223460ustar00rootroot00000000000000/* * Created on Jan 25, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.ToString.toStringOf; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; /** * Utility methods related to maps. * * @author Yvonne Wang * @author Alex Ruiz */ public class Maps { /** * Indicates whether the given {@code Map} is {@code null} or empty. * * @param map the map to check. * @return {@code true} if the given {@code Map} is {@code null} or empty, otherwise {@code false}. */ public static boolean isNullOrEmpty(Map map) { return map == null || map.isEmpty(); } /** * Returns the {@code String} representation of the given map, or {@code null} if the given map is {@code null}. * * @param map the map to format. * @return the {@code String} representation of the given map. */ public static String format(Map map) { if (map == null) { return null; } Iterator i = map.entrySet().iterator(); if (!i.hasNext()) { return "{}"; } StringBuilder buffer = new StringBuilder(); buffer.append("{"); for (;;) { Entry e = (Entry) i.next(); buffer.append(format(map, e.getKey())); buffer.append('='); buffer.append(format(map, e.getValue())); if (!i.hasNext()) { return buffer.append("}").toString(); } buffer.append(", "); } } private static Object format(Map map, Object o) { return o == map ? "(this Map)" : toStringOf(o); } private Maps() {} } fest-util-1.2.5/src/main/java/org/fest/util/Objects.java000066400000000000000000000064651243017530700230450ustar00rootroot00000000000000/* * Created on Jun 2, 2006 * * 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. * * Copyright @2006-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Arrays.*; import java.lang.reflect.Array; /** * Utility methods related to objects. * * @author Alex Ruiz * @author Joel Costigliola */ public final class Objects { /** Prime number used to calculate the hash code of objects. */ public static final int HASH_CODE_PRIME = 31; /** * Returns {@code true} if the given objects are equal or if both objects are {@code null}. * * @param o1 one of the objects to compare. * @param o2 one of the objects to compare. * @return {@code true} if the given objects are equal or if both objects are {@code null}. */ public static boolean areEqual(Object o1, Object o2) { if (o1 == null) { return o2 == null; } if (o1.equals(o2)) { return true; } return areEqualArrays(o1, o2); } private static boolean areEqualArrays(Object o1, Object o2) { if (!isArray(o1) || !isArray(o2)) { return false; } if (o1 == o2) { return true; } int size = Array.getLength(o1); if (Array.getLength(o2) != size) { return false; } for (int i = 0; i < size; i++) { Object e1 = Array.get(o1, i); Object e2 = Array.get(o2, i); if (!areEqual(e1, e2)) { return false; } } return true; } /** * Returns an array containing the names of the given types. * * @param types the given types. * @return the names of the given types stored in an array. */ public static String[] namesOf(Class... types) { if (isNullOrEmpty(types)) { return new String[0]; } String[] names = new String[types.length]; for (int i = 0; i < types.length; i++) { names[i] = types[i].getName(); } return names; } /** * Returns the hash code for the given object. If the object is {@code null}, this method returns zero. Otherwise * calls the method {@code hashCode} of the given object. * * @param o the given object. * @return the hash code for the given object */ public static int hashCodeFor(Object o) { return o != null ? o.hashCode() : 0; } /** * Casts the given object to the given type only if the object is of the given type. If the object is not of the given * type, this method returns {@code null}. * * @param the generic type to cast the given object to. * @param o the object to cast. * @param type the given type. * @return the casted object, or {@code null} if the given object is not to the given type. */ public static T castIfBelongsToType(Object o, Class type) { if (o != null && type.isAssignableFrom(o.getClass())) { return type.cast(o); } return null; } private Objects() {} } fest-util-1.2.5/src/main/java/org/fest/util/Preconditions.java000066400000000000000000000033511243017530700242630ustar00rootroot00000000000000/* * Created on Sep 4, 2012 * * 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. * * Copyright @2012 Google Inc. and others. */ package org.fest.util; /** * Verifies correct argument values and state. Borrowed from Guava. * * @author alruiz@google.com (Alex Ruiz) */ public final class Preconditions { /** * Verifies that the given {@code String} is not {@code null} or empty. * * @param s the given {@code String}. * @return the validated {@code String}. * @throws NullPointerException if the given {@code String} is {@code null}. * @throws IllegalArgumentException if the given {@code String} is empty. */ public static String checkNotNullOrEmpty(String s) { checkNotNull(s); if (s.isEmpty()) { throw new IllegalArgumentException(); } return s; } /** * Verifies that the given object reference is not {@code null}. * * @param reference the given object reference. * @return the non-{@code null} reference that was validated. * @throws NullPointerException if the given object reference is {@code null}. */ public static T checkNotNull(T reference) { if (reference == null) { throw new NullPointerException(); } return reference; } private Preconditions() {} } fest-util-1.2.5/src/main/java/org/fest/util/Sets.java000066400000000000000000000026701243017530700223640ustar00rootroot00000000000000/* * Created on Aug 23, 2012 * * 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. * * Copyright @2012 the original author or authors. */ package org.fest.util; import java.util.LinkedHashSet; import java.util.Set; /** * Utility methods related to {@link Set}s. * * @author alruiz */ public final class Sets { /** * Creates a mutable {@link LinkedHashSet} containing the given elements. * * @param the generic type of the {@code LinkedHashSet} to create. * @param elements the elements to store in the {@code LinkedHashSet}. * @return the created {@code LinkedHashSet}, of {@code null} if the given array of elements is {@code null}. * @since 1.1.5 */ public static LinkedHashSet newLinkedHashSet(T... elements) { if (elements == null) { return null; } LinkedHashSet set = new LinkedHashSet(); for (T e : elements) { set.add(e); } return set; } private Sets() {} } fest-util-1.2.5/src/main/java/org/fest/util/Strings.java000066400000000000000000000136321243017530700230770ustar00rootroot00000000000000/* * Created on Jun 2, 2006 * * 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. * * Copyright @2006-2012 the original author or authors. */ package org.fest.util; /** * Utility methods related to {@code String}s. * * @author Alex Ruiz */ public final class Strings { /** * Indicates whether the given {@code String} is {@code null} or empty. * * @param s the {@code String} to check. * @return {@code true} if the given {@code String} is {@code null} or empty, otherwise {@code false}. */ public static boolean isNullOrEmpty(String s) { return s == null || s.length() == 0; } /** * Only there for backward compatibility reasons - use {@link #isNullOrEmpty(String)} instead. */ @Deprecated public static boolean isEmpty(String s) { return isNullOrEmpty( s ); } /** * Returns the given {@code String} surrounded by single quotes, or {@code null} if the given {@code String} is * {@code null}. * * @param s the given {@code String}. * @return the given {@code String} surrounded by single quotes, or {@code null} if the given {@code String} is * {@code null}. */ public static String quote(String s) { return s != null ? concat("'", s, "'") : null; } /** * Returns the given object surrounded by single quotes, only if the object is a {@code String}. * * @param o the given object. * @return the given object surrounded by single quotes, only if the object is a {@code String}. * @see #quote(String) */ public static Object quote(Object o) { return o instanceof String ? quote(o.toString()) : o; } /** * Concatenates the given objects into a single {@code String}. This method is more efficient than concatenating using * "+", since only one {@link StringBuilder} is created. * * @param objects the objects to concatenate. * @return a {@code String} containing the given objects. */ public static String concat(Object... objects) { if (Arrays.isNullOrEmpty(objects)) { return null; } StringBuilder b = new StringBuilder(); for (Object o : objects) { b.append(o); } return b.toString(); } /** * Joins the given {@code String}s using a given delimiter. The following example illustrates proper usage of this * method: * *
   * Strings.join("a", "b", "c").with("|")
   * 
* * which will result in the {@code String} "a|b|c". * * @param strings the {@code String}s to join. * @return an intermediate object that takes a given delimiter and knows how to join the given {@code String}s. * @see StringsToJoin#with(String) */ public static StringsToJoin join(String... strings) { return new StringsToJoin(strings); } /** * Knows how to join {@code String}s using a given delimiter. * * @see Strings#join(String[]) */ public static class StringsToJoin { /** The {@code String}s to join. */ private final String[] strings; /** * Creates a new {@link StringsToJoin}. * * @param strings the {@code String}s to join. */ StringsToJoin(String... strings) { this.strings = strings; } /** * Specifies the delimeter to use to join {@code String}s. * * @param delimeter the delimeter to use. * @return the {@code String}s joined using the given delimeter. */ public String with(String delimeter) { if (delimeter == null) { throw new IllegalArgumentException("Delimiter should not be null"); } if (Arrays.isNullOrEmpty(strings)) { return ""; } StringBuilder b = new StringBuilder(); int stringCount = strings.length; for (int i = 0; i < stringCount; i++) { String s = strings[i]; b.append(s != null ? s : ""); if (i < stringCount - 1) { b.append(delimeter); } } return b.toString(); } } /** * Appends a given {@code String} to the given target, only if the target does not end with the given {@code String} * to append. The following example illustrates proper usage of this method: * *
   * Strings.append("c").to("ab");
   * Strings.append("c").to("abc");
   * 
* * resulting in the {@code String} "abc" for both cases. * * @param toAppend the {@code String} to append. * @return an intermediate object that takes the target {@code String} and knows to append the given {@code String}. * @see StringToAppend#to(String) */ public static StringToAppend append(String toAppend) { return new StringToAppend(toAppend); } /** * Knows how to append a given {@code String} to the given target, only if the target does not end with the given * {@code String} to append. */ public static class StringToAppend { private final String toAppend; StringToAppend(String toAppend) { this.toAppend = toAppend; } /** * Appends the {@code String} specified in the constructor to the {@code String} passed as argument. * * @param s the target {@code String}. * @return a {@code String} containing the target {@code String} with the given {@code String} to append added to * the end. */ public String to(String s) { if (!s.endsWith(toAppend)) { return concat(s, toAppend); } return s; } } private Strings() {} } fest-util-1.2.5/src/main/java/org/fest/util/SystemProperties.java000066400000000000000000000017741243017530700250130ustar00rootroot00000000000000/* * Created on Feb 10, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; /** * System properties. * * @author Yvonne Wang */ public final class SystemProperties { public static final String LINE_SEPARATOR = lineSeparator(); private static String lineSeparator() { try { return System.getProperty("line.separator"); } catch (Exception e) { return "\n"; } } private SystemProperties() {} } fest-util-1.2.5/src/main/java/org/fest/util/TextFileWriter.java000066400000000000000000000032361243017530700243660ustar00rootroot00000000000000/* * Created on Jan 27, 2011 * * 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. * * Copyright @2011-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Closeables.closeQuietly; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.Charset; /** * @author Yvonne Wang * @author Olivier Michallat */ public class TextFileWriter { private static TextFileWriter INSTANCE = new TextFileWriter(); public static TextFileWriter instance() { return INSTANCE; } public void write(File file, String... content) throws IOException { write(file, Charset.defaultCharset(), content); } public void write(File file, Charset charset, String... content) throws IOException { PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); for (String line : content) { writer.println(line); } } finally { closeQuietly(writer); } } private TextFileWriter() { } } fest-util-1.2.5/src/main/java/org/fest/util/Throwables.java000066400000000000000000000122201243017530700235500ustar00rootroot00000000000000/* * Created on Dec 13, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import java.util.*; /** * Utility methods related to {@link Throwable}s. * * @author Alex Ruiz */ public final class Throwables { /** * Appends the stack trace of the current thread to the one in the given {@link Throwable}. * * @param t the given {@code Throwable}. * @param methodToStartFrom the name of the method used as the starting point of the current thread's stack trace. */ public static void appendStackTraceInCurentThreadToThrowable(Throwable t, String methodToStartFrom) { List stackTrace = newArrayList(t.getStackTrace()); stackTrace.addAll(stackTraceInCurrentThread(methodToStartFrom)); t.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); } private static List stackTraceInCurrentThread(String methodToStartFrom) { List filtered = stackTraceInCurrentThread(); List toRemove = new ArrayList(); for (StackTraceElement e : filtered) { if (methodToStartFrom.equals(e.getMethodName())) { break; } toRemove.add(e); } filtered.removeAll(toRemove); return filtered; } private static List stackTraceInCurrentThread() { return newArrayList(Thread.currentThread().getStackTrace()); } /** * Removes the FEST-related elements from the {@link Throwable} stack trace that have little value for * end user. Therefore, instead of seeing this: * *
   * org.junit.ComparisonFailure: expected:<'[Ronaldo]'> but was:<'[Messi]'>
   *   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   *   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   *   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   *   at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
   *   at org.fest.assertions.error.ConstructorInvoker.newInstance(ConstructorInvoker.java:34)
   *   at org.fest.assertions.error.ShouldBeEqual.newComparisonFailure(ShouldBeEqual.java:111)
   *   at org.fest.assertions.error.ShouldBeEqual.comparisonFailure(ShouldBeEqual.java:103)
   *   at org.fest.assertions.error.ShouldBeEqual.newAssertionError(ShouldBeEqual.java:81)
   *   at org.fest.assertions.internal.Failures.failure(Failures.java:76)
   *   at org.fest.assertions.internal.Objects.assertEqual(Objects.java:116)
   *   at org.fest.assertions.api.AbstractAssert.isEqualTo(AbstractAssert.java:74)
   *   at examples.StackTraceFilterExample.main(StackTraceFilterExample.java:13)
   * 
* * We get this: * *
   * org.junit.ComparisonFailure: expected:<'[Ronaldo]'> but was:<'[Messi]'>
   *   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   *   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   *   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   *   at examples.StackTraceFilterExample.main(StackTraceFilterExample.java:20)
   * 
* @param throwable the {@code Throwable} to filter stack trace. */ public static void removeFestRelatedElementsFromStackTrace(Throwable throwable) { List filtered = newArrayList(throwable.getStackTrace()); StackTraceElement previous = null; for (StackTraceElement element : throwable.getStackTrace()) { if (element.getClassName().contains("org.fest")) { filtered.remove(element); // Handle the case when FEST builds a ComparisonFailure by reflection (see ShouldBeEqual.newAssertionError // method), the stack trace looks like: // // java.lang.reflect.Constructor.newInstance(Constructor.java:501), // org.fest.assertions.error.ConstructorInvoker.newInstance(ConstructorInvoker.java:34), // // We want to remove java.lang.reflect.Constructor.newInstance element because it is related to FEST. if (previous != null && previous.getClassName().equals("java.lang.reflect.Constructor") && element.getClassName().contains("org.fest.assertions.error.ConstructorInvoker")) { filtered.remove(previous); } } previous = element; } StackTraceElement[] newStackTrace = filtered.toArray(new StackTraceElement[filtered.size()]); throwable.setStackTrace(newStackTrace); } private Throwables() {} } fest-util-1.2.5/src/main/java/org/fest/util/ToString.java000066400000000000000000000060641243017530700232200ustar00rootroot00000000000000/* * Created on Oct 7, 2009 * * 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. * * Copyright @2009-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Arrays.isArray; import static org.fest.util.Strings.quote; import java.io.File; import java.util.*; /** * Obtains the {@code toString} representation of an object. * * @author Alex Ruiz * @author Joel Costigliola * @author Yvonne Wang */ public final class ToString { /** * Returns the {@code toString} representation of the given object. It may or not the object's own implementation of * {@code toString}. * * @param o the given object. * @return the {@code toString} representation of the given object. */ public static String toStringOf(Object o) { if (isArray(o)) { return Arrays.format(o); } if (o instanceof Calendar) { return toStringOf((Calendar) o); } if (o instanceof Class) { return toStringOf((Class) o); } if (o instanceof Collection) { return toStringOf((Collection) o); } if (o instanceof Date) { return toStringOf((Date) o); } if (o instanceof Float) { return toStringOf((Float) o); } if (o instanceof Long) { return toStringOf((Long) o); } if (o instanceof File) { return toStringOf((File) o); } if (o instanceof Map) { return toStringOf((Map) o); } if (o instanceof String) { return quote((String) o); } if (o instanceof Comparator) { return toStringOf((Comparator) o); } return o == null ? null : o.toString(); } private static String toStringOf(Comparator comparator) { String comparatorSimpleClassName = comparator.getClass().getSimpleName(); return quote(!comparatorSimpleClassName.isEmpty() ? comparatorSimpleClassName : "Anonymous Comparator class"); } private static String toStringOf(Calendar c) { return Dates.formatAsDatetime(c); } private static String toStringOf(Class c) { return c.getCanonicalName(); } private static String toStringOf(Collection c) { return Collections.format(c); } private static String toStringOf(Date d) { return Dates.formatAsDatetime(d); } private static String toStringOf(Float f) { return String.format("%sf", f); } private static String toStringOf(Long l) { return String.format("%sL", l); } private static String toStringOf(File f) { return f.getAbsolutePath(); } private static String toStringOf(Map m) { return Maps.format(m); } private ToString() {} } fest-util-1.2.5/src/main/java/org/fest/util/TypeFilter.java000066400000000000000000000040701243017530700235310ustar00rootroot00000000000000/* * Created on Nov 1, 2007 * * 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. * * Copyright @2007-2011 the original author or authors. */ package org.fest.util; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * Filters elements of a collection by their data type. * * @param the generic type of the objects returned by the filter. * * @author Yvonne Wang */ public class TypeFilter implements CollectionFilter { /** * Creates a new {@link TypeFilter}. * * @param the generic type of the target type. * @param type the target type for this filter. * @return the created filter. */ public static TypeFilter byType(Class type) { return new TypeFilter(type); } private final Class type; TypeFilter(Class type) { this.type = type; } /** * Filters the given collection by the type specified in this filter. * * @param target the collection to filter. * @return a list containing the filtered elements. * @throws IllegalArgumentException if the given collection is {@code null}. */ @Override @SuppressWarnings("unchecked") public List filter(Collection target) { if (target == null) { throw new IllegalArgumentException("The collection to filter should not be null"); } List filtered = new ArrayList(); for (Object o : target) { if (o == null) { continue; } if (type.isAssignableFrom(o.getClass())) { filtered.add(o); } } return (List) filtered; } } fest-util-1.2.5/src/main/java/org/fest/util/Types.java000066400000000000000000000026011243017530700225440ustar00rootroot00000000000000/* * Created on Oct 7, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import java.util.Collection; import java.util.List; import java.util.Queue; import java.util.Set; /** * Utilities related to Java data types. * * @author Alex Ruiz */ public final class Types { private static final Class[] PRIMITIVE_TYPES = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class, char.class }; private static final Class[] COLLECTION_TYPES = { Collection.class, List.class, Queue.class, Set.class }; public static List> primitiveTypes() { return newArrayList(PRIMITIVE_TYPES); } public static List> collectionTypes() { return newArrayList(COLLECTION_TYPES); } private Types() {} } fest-util-1.2.5/src/main/java/org/fest/util/VisibleForTesting.java000066400000000000000000000016031243017530700250430ustar00rootroot00000000000000/* * Created on Mar 18, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; /** * Indicates that the visibility of a type or member has been relaxed to make the code testable. Idea borrowed from * Google Collections :) * * @author Alex Ruiz * * @since 1.1.1 */ public @interface VisibleForTesting {} fest-util-1.2.5/src/main/java/org/fest/util/package.html000066400000000000000000000016751243017530700230700ustar00rootroot00000000000000

General-purpose utilities used by FEST modules.

fest-util-1.2.5/src/main/javadocs/000077500000000000000000000000001243017530700167425ustar00rootroot00000000000000fest-util-1.2.5/src/main/javadocs/overview.html000066400000000000000000000007231243017530700215000ustar00rootroot00000000000000

This document is the API specification for the FEST Utilities Module 0.2-SNAPSHOT.

fest-util-1.2.5/src/test/000077500000000000000000000000001243017530700152035ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/000077500000000000000000000000001243017530700161245ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/org/000077500000000000000000000000001243017530700167135ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/org/fest/000077500000000000000000000000001243017530700176545ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/org/fest/util/000077500000000000000000000000001243017530700206315ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/org/fest/util/ArrayFormatter_format_Test.java000066400000000000000000000066711243017530700270170ustar00rootroot00000000000000/* * Created on Mar 29, 2009 * * 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. * * Copyright @2009-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Strings.quote; import static org.junit.Assert.*; import org.junit.BeforeClass; import org.junit.Test; /** * Tests for {@link ArrayFormatter#format(Object)}. * * @author Alex Ruiz */ public class ArrayFormatter_format_Test { private static ArrayFormatter formatter; @BeforeClass public static void setUpOnce() { formatter = new ArrayFormatter(); } @Test public void should_return_null_if_array_is_null() { assertNull(formatter.format(null)); } @Test public void should_return_null_if_parameter_is_not_array() { assertNull(formatter.format("Hello")); } @Test public void should_format_boolean_array() { assertEquals("[true, false, true]", formatter.format(new boolean[] { true, false, true })); } @Test public void should_format_char_array() { assertEquals("[a, b, c]", formatter.format(new char[] { 'a', 'b', 'c' })); } @Test public void should_format_byte_array() { assertEquals("[6, 8]", formatter.format(new byte[] { 6, 8 })); } @Test public void should_format_short_array() { assertEquals("[6, 8]", formatter.format(new short[] { 6, 8 })); } @Test public void should_format_int_array() { assertEquals("[6, 8]", formatter.format(new int[] { 6, 8 })); } @Test public void should_format_longArray() { assertEquals("[6, 8]", formatter.format(new long[] { 6l, 8l })); } @Test public void should_format_float_array() { assertEquals("[6.0, 8.0]", formatter.format(new float[] { 6f, 8f })); } @Test public void should_format_double_array() { assertEquals("[6.0, 8.0]", formatter.format(new double[] { 6d, 8d })); } @Test public void should_format_String_array() { assertEquals("['Hello', 'World']", formatter.format(new Object[] { "Hello", "World" })); } @Test public void should_format_array_with_null_element() { assertEquals("['Hello', null]", formatter.format(new Object[] { "Hello", null })); } @Test public void should_format_Object_array() { assertEquals("['Hello', 'Anakin']", formatter.format(new Object[] { "Hello", new Person("Anakin") })); } @Test public void should_format_Object_array_that_has_primitive_array_as_element() { boolean booleans[] = { true, false }; Object[] array = { "Hello", booleans }; assertEquals("['Hello', [true, false]]", formatter.format(array)); } @Test public void should_format_Object_array_having_itself_as_element() { Object[] array1 = { "Hello", "World" }; Object[] array2 = { array1 }; array1[1] = array2; assertEquals("[['Hello', [...]]]", formatter.format(array2)); } private static class Person { private final String name; Person(String name) { this.name = name; } @Override public String toString() { return quote(name); } } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_array_Test.java000066400000000000000000000017471243017530700251430ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertSame; import org.junit.Test; /** * Tests for {@link Arrays#array(Object...)}. * * @author Alex Ruiz */ public class Arrays_array_Test { @Test public void should_return_parameter() { Object[] array = { "one", "two" }; assertSame(Arrays.array(array), array); } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_format_Test.java000066400000000000000000000046031243017530700253070ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Arrays#format(Object)}. * * @author Alex Ruiz */ public class Arrays_format_Test { @Test public void should_return_null_if_array_is_null() { assertNull(Arrays.format(null)); } @Test public void should_return_empty_brackets_if_array_is_empty() { assertEquals("[]", Arrays.format(new Object[0])); } @Test public void should_format_Object_array() { Object o = new Object[] { "First", 3 }; assertEquals("['First', 3]", Arrays.format(o)); } @Test public void should_format_boolean_array() { Object o = new boolean[] { true, false }; assertEquals("[true, false]", Arrays.format(o)); } @Test public void should_format_byte_array() { Object o = new byte[] { (byte) 3, (byte) 8 }; assertEquals("[3, 8]", Arrays.format(o)); } @Test public void should_format_char_array() { Object o = new char[] { 'a', 'b' }; assertEquals("[a, b]", Arrays.format(o)); } @Test public void should_format_double_array() { Object o = new double[] { 6.8, 8.3 }; assertEquals("[6.8, 8.3]", Arrays.format(o)); } @Test public void should_format_float_array() { Object o = new float[] { 6.1f, 8.6f }; assertEquals("[6.1, 8.6]", Arrays.format(o)); } @Test public void should_format_int_array() { Object o = new int[] { 78, 66 }; assertEquals("[78, 66]", Arrays.format(o)); } @Test public void should_format_long_array() { Object o = new long[] { 160l, 98l }; assertEquals("[160, 98]", Arrays.format(o)); } @Test public void should_format_short_array() { Object o = new short[] { (short) 5, (short) 8 }; assertEquals("[5, 8]", Arrays.format(o)); } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_hasOnlyNullElements_Test.java000066400000000000000000000032351243017530700277640ustar00rootroot00000000000000/* * Created on Jun 2, 2010 * * 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. * * Copyright @2010-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import static org.junit.rules.ExpectedException.none; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Arrays#hasOnlyNullElements(Object[])}. * * @author Alex Ruiz */ public class Arrays_hasOnlyNullElements_Test { @Rule public ExpectedException thrown = none(); @Test public void should_throw_error_if_array_is_null() { thrown.expect(NullPointerException.class); Arrays.hasOnlyNullElements(null); } @Test public void should_return_true_if_array_has_only_null_elements() { String[] array = { null, null }; assertTrue(Arrays.hasOnlyNullElements(array)); } @Test public void should_return_false_if_array_has_at_least_one_element_not_null() { String[] array = { null, "Frodo", null }; assertFalse(Arrays.hasOnlyNullElements(array)); } @Test public void should_return_false_if_array_is_empty() { assertFalse(Arrays.hasOnlyNullElements(new String[0])); } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_isArray_Test.java000066400000000000000000000023011243017530700254220ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Arrays#isArray(Object)}. * * @author Joel Costigliola */ public class Arrays_isArray_Test { @Test public void should_return_true_if_object_is_an_array() { assertTrue(Arrays.isArray(new String[0])); } @Test public void should_return_false_if_object_is_null() { assertFalse(Arrays.isArray(null)); } @Test public void should_return_false_if_object_is_not_an_array() { assertFalse(Arrays.isArray("I'm not an array")); } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_isNullOrEmpty_Test.java000066400000000000000000000023231243017530700266020ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Arrays#isNullOrEmpty(Object[])}. * * @author Alex Ruiz */ public class Arrays_isNullOrEmpty_Test { @Test public void should_return_true_if_array_is_empty() { assertTrue(Arrays.isNullOrEmpty(new String[0])); } @Test public void should_return_true_if_array_is_null() { assertTrue(Arrays.isNullOrEmpty(null)); } @Test public void should_return_false_if_array_has_elements() { assertFalse(Arrays.isNullOrEmpty(new String[] { "Tuzi" })); } } fest-util-1.2.5/src/test/java/org/fest/util/Arrays_nonNullElementsIn_Test.java000066400000000000000000000033561243017530700274340ustar00rootroot00000000000000/* * Created on May 13, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Arrays.nonNullElementsIn; import static org.junit.Assert.*; import java.util.List; import org.junit.Test; /** * Tests for {@link Arrays#nonNullElementsIn(Object[])}. * * @author Joel Costigliola * @author Alex Ruiz */ public class Arrays_nonNullElementsIn_Test { @Test public void should_return_empty_Collection_if_given_array_is_null() { assertTrue(Arrays.nonNullElementsIn(null).isEmpty()); } @Test public void should_return_an_empty_Collection_if_given_array_has_only_null_elements() { String[] array = new String[] { null }; assertTrue(Arrays.nonNullElementsIn(array).isEmpty()); } @Test public void should_return_an_empty_Collection_if_given_array_is_empty() { String[] array = new String[0]; assertTrue(Arrays.nonNullElementsIn(array).isEmpty()); } @Test public void should_return_a_Collection_without_null_elements() { String[] array = { "Frodo", null, "Sam", null }; List nonNull = nonNullElementsIn(array); assertArrayEquals(new String[] { "Frodo", "Sam" }, nonNull.toArray()); } } fest-util-1.2.5/src/test/java/org/fest/util/Closeables_closeQuietly_Test.java000066400000000000000000000041241243017530700273120ustar00rootroot00000000000000/* * Created on Jan 15, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertTrue; import java.io.Closeable; import java.io.IOException; import org.junit.Test; /** * Tests for {@link Closeables#closeQuietly(Closeable...)}. * * @author Yvonne Wang */ public class Closeables_closeQuietly_Test { @Test public void should_close_Closeables() { CloseableStub[] toClose = new CloseableStub[] { new CloseableStub(), new CloseableStub() }; Closeables.closeQuietly(toClose); assertClosed(toClose); } @Test public void should_ignore_thrown_errors() { CloseableStub[] toClose = new CloseableStub[] { new CloseableStub(new IOException("")), new CloseableStub() }; Closeables.closeQuietly(toClose); assertClosed(toClose); } @Test public void should_ignore_null_Closeables() { CloseableStub c = new CloseableStub(); CloseableStub[] toClose = new CloseableStub[] { null, c }; Closeables.closeQuietly(toClose); assertClosed(c); } private void assertClosed(CloseableStub... supposelyClosed) { for (CloseableStub c : supposelyClosed) { assertTrue(c.closed); } } private static class CloseableStub implements Closeable { boolean closed; IOException toThrow; public CloseableStub() {} public CloseableStub(IOException toThrow) { this.toThrow = toThrow; } @Override public void close() throws IOException { closed = true; if (toThrow != null) { throw toThrow; } } } } fest-util-1.2.5/src/test/java/org/fest/util/Collections_duplicatesFrom_Test.java000066400000000000000000000035441243017530700300200ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static java.util.Arrays.asList; import static org.fest.util.Collections.duplicatesFrom; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collection; import org.junit.Test; /** * Tests for {@link Collections#duplicatesFrom(Collection)}. * * @author Yvonne Wang * @author Alex Ruiz * @author Joel Costigliola */ public class Collections_duplicatesFrom_Test { @Test public void should_return_existing_duplicates() { Collection duplicates = duplicatesFrom(asList("Merry", "Frodo", "Merry", "Sam", "Frodo")); assertArrayEquals(new String[] { "Merry", "Frodo" }, duplicates.toArray()); } @Test public void should_not_return_any_duplicates() { Collection duplicates = duplicatesFrom(asList("Frodo", "Sam", "Gandalf")); assertTrue(duplicates.isEmpty()); } @Test public void should_not_return_any_duplicates_if_collection_is_empty() { Collection duplicates = duplicatesFrom(new ArrayList()); assertTrue(duplicates.isEmpty()); } @Test public void should_not_return_any_duplicates_if_collection_is_null() { Collection duplicates = duplicatesFrom(null); assertTrue(duplicates.isEmpty()); } } fest-util-1.2.5/src/test/java/org/fest/util/Collections_format_Test.java000066400000000000000000000026111243017530700263210ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2011 the original author or authors. */ package org.fest.util; import static java.util.Arrays.asList; import static org.junit.Assert.*; import java.util.*; import org.junit.Test; /** * Tests for {@link Collections#format(Collection)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Collections_format_Test { @Test public void should_return_null_if_Collection_is_null() { assertNull(Collections.format(null)); } @Test public void should_return_empty_brackets_if_Collection_is_empty() { assertEquals("[]", Collections.format(new ArrayList())); } @Test @SuppressWarnings("unchecked") public void should_format_Collection() { List list = asList("First", 3); assertEquals("['First', 3]", Collections.format(list)); } } fest-util-1.2.5/src/test/java/org/fest/util/Collections_isNullOrEmpty_Test.java000066400000000000000000000027021243017530700276200ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collection; import org.junit.Test; /** * Tests for {@link Collections#isNullOrEmpty(Collection)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Collections_isNullOrEmpty_Test { @Test public void should_return_true_if_Collection_is_empty() { Collection c = new ArrayList(); assertTrue(Collections.isNullOrEmpty(c)); } @Test public void should_return_true_if_Collection_is_null() { assertTrue(Collections.isNullOrEmpty(null)); } @Test public void should_return_false_if_Collection_has_elements() { Collection c = newArrayList("Frodo"); assertFalse(Collections.isNullOrEmpty(c)); } } fest-util-1.2.5/src/test/java/org/fest/util/Collections_nonNullElementsIn_Test.java000066400000000000000000000034751243017530700304530ustar00rootroot00000000000000/* * Created on Jun 17, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import static org.junit.Assert.*; import java.util.*; import org.junit.Test; /** * Tests for {@link Collections#nonNullElementsIn(Collection)}. * * @author Joel Costigliola * @author Alex Ruiz */ public class Collections_nonNullElementsIn_Test { @Test public void should_return_empty_List_if_given_Collection_is_null() { Collection c = null; assertTrue(Collections.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_empty_List_if_given_Collection_has_only_null_elements() { Collection c = new ArrayList(); c.add(null); assertTrue(Collections.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_empty_List_if_given_Collection_is_empty() { Collection c = new ArrayList(); assertTrue(Collections.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_a_list_without_null_elements() { List c = newArrayList("Frodo", null, "Sam", null); List nonNull = Collections.nonNullElementsIn(c); assertArrayEquals(new String[] { "Frodo", "Sam" }, nonNull.toArray()); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_dayOfMonthOf_Test.java000066400000000000000000000027621243017530700261570ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.dayOfMonthOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#dayOfMonthOf(Date)}. * * @author Joel Costigliola */ public class Dates_dayOfMonthOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_day_of_month_of_date() throws ParseException { String dateAsString = "26/08/1994"; Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateAsString); assertEquals(26, dayOfMonthOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); dayOfMonthOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_dayOfWeekOf_Test.java000066400000000000000000000027671243017530700257720ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.dayOfWeekOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.*; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#dayOfWeekOf(Date)}. * * @author Joel Costigliola */ public class Dates_dayOfWeekOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_day_of_month_of_date() throws ParseException { String dateAsString = "26/08/1994"; Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateAsString); assertEquals(Calendar.FRIDAY, dayOfWeekOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); dayOfWeekOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_format_with_date_time_format_Test.java000066400000000000000000000034251243017530700315250ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.formatAsDatetime; import static org.junit.Assert.*; import java.text.*; import java.util.*; import org.junit.Test; /** * Tests for {@link Dates#formatAsDatetime(Calendar)} and {@link Dates#formatAsDatetime(java.util.Date)} * * @author Joel Costigliola */ public class Dates_format_with_date_time_format_Test { @Test public void should_format_date_with_date_time_format() throws ParseException { String dateAsString = "26/08/1994"; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); assertEquals("1994-08-26T00:00:00", formatAsDatetime(formatter.parse(dateAsString))); } @Test public void should_return_null_if_date_is_null() { assertNull(formatAsDatetime((Date) null)); } @Test public void should_format_calendar_with_date_time_format() { Calendar calendar = new GregorianCalendar(); calendar.set(2011, 04, 15, 14, 59, 33); assertEquals("2011-05-15T14:59:33", formatAsDatetime(calendar)); } @Test public void should_return_null_if_calendar_is_null() { assertNull(formatAsDatetime((Calendar) null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_format_with_date_time_with_ms_format_Test.java000066400000000000000000000026321243017530700332560ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.formatAsDatetimeWithMs; import static org.junit.Assert.*; import java.text.*; import java.util.Date; import org.junit.Test; /** * Tests for {@link Dates#formatAsDatetimeWithMs(Date)}. * * @author Joel Costigliola */ public class Dates_format_with_date_time_with_ms_format_Test { @Test public void should_format_date_with_date_time_with_ms_format() throws ParseException { String dateAsString = "26/08/1994"; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); assertEquals("1994-08-26T00:00:00.000", formatAsDatetimeWithMs(formatter.parse(dateAsString))); } @Test public void should_return_null_if_date_is_null() { assertNull(formatAsDatetimeWithMs((Date) null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_hourOfDayOf_Test.java000066400000000000000000000027701243017530700260060ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.hourOfDay; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#hourOfDay(Date)}. * * @author Joel Costigliola */ public class Dates_hourOfDayOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_hour_of_day_of_date() throws ParseException { String dateAsString = "26/08/1994T22:35:00"; Date date = new SimpleDateFormat("dd/MM/yyyy'T'hh:mm:ss").parse(dateAsString); assertEquals(22, hourOfDay(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); hourOfDay(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_millisecondOf_Test.java000066400000000000000000000030201243017530700263750ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.millisecondOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#millisecondOf(Date)}. * * @author Joel Costigliola */ public class Dates_millisecondOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_millisecond_of_date() throws ParseException { String dateAsString = "26/08/1994T22:35:17:29"; Date date = new SimpleDateFormat("dd/MM/yyyy'T'hh:mm:ss:SS").parse(dateAsString); assertEquals(29, millisecondOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); millisecondOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_minuteOf_Test.java000066400000000000000000000027541243017530700254110ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.minuteOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#minuteOf(Date)}. * * @author Joel Costigliola */ public class Dates_minuteOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_minute_of_date() throws ParseException { String dateAsString = "26/08/1994T22:35:00"; Date date = new SimpleDateFormat("dd/MM/yyyy'T'hh:mm:ss").parse(dateAsString); assertEquals(35, minuteOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); minuteOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_monthOf_Test.java000066400000000000000000000027211243017530700252270ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.monthOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#monthOf(Date)}. * * @author Joel Costigliola */ public class Dates_monthOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_month_of_date() throws ParseException { String dateAsString = "26/08/1994"; Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateAsString); assertEquals(8, monthOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); monthOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_parse_Test.java000066400000000000000000000023741243017530700247330ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.parse; import static org.junit.Assert.*; import java.text.*; import org.junit.Test; /** * Tests for {@link Dates#parse(String)}. * * @author Joel Costigliola */ public class Dates_parse_Test { @Test public void should_parse_string() throws ParseException { String dateAsString = "26/08/1994"; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); assertEquals(formatter.parse(dateAsString), parse("1994-08-26")); } @Test public void should_return_null_if_string_to_parse_is_null() { assertNull(parse(null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_parse_date_Test.java000066400000000000000000000030121243017530700257160ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.*; import static org.junit.Assert.*; import static org.junit.rules.ExpectedException.none; import java.util.Date; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#parse(String)}. * * @author Joel Costigliola */ public class Dates_parse_date_Test { @Rule public ExpectedException thrown = none(); @Test public void should_parse_string_with_date_time_format() { Date date = parse("1994-08-26"); assertEquals("1994-08-26T00:00:00", formatAsDatetime(date)); } @Test public void should_return_null_if_string_to_parse_is_null() { assertNull(parse(null)); } @Test public void should_fail_if_string_does_not_respect_date_format() { thrown.expect(RuntimeException.class); assertNull(parse("invalid date format")); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_parse_date_time_Test.java000066400000000000000000000030701243017530700267400ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.*; import static org.junit.Assert.*; import static org.junit.rules.ExpectedException.none; import java.util.Date; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#parseDatetime(String)}. * * @author Joel Costigliola */ public class Dates_parse_date_time_Test { @Rule public ExpectedException thrown = none(); @Test public void should_parse_string_with_date_time_format() { Date date = parseDatetime("1994-08-26T00:00:00"); assertEquals("1994-08-26T00:00:00", formatAsDatetime(date)); } @Test public void should_return_null_if_string_to_parse_is_null() { assertNull(parseDatetime(null)); } @Test public void should_fail_if_string_does_not_respect_date_format() { thrown.expect(RuntimeException.class); assertNull(parseDatetime("invalid date format")); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_secondOf_Test.java000066400000000000000000000027541243017530700253630ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.secondOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#secondOf(Date)}. * * @author Joel Costigliola */ public class Dates_secondOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_second_of_date() throws ParseException { String dateAsString = "26/08/1994T22:35:17"; Date date = new SimpleDateFormat("dd/MM/yyyy'T'hh:mm:ss").parse(dateAsString); assertEquals(17, secondOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); secondOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_toCalendar_Test.java000066400000000000000000000027611243017530700256750ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.toCalendar; import static org.junit.Assert.*; import java.text.*; import java.util.*; import org.junit.Test; /** * Tests for {@link Dates#toCalendar(java.util.Date)}. * * @author Joel Costigliola */ public class Dates_toCalendar_Test { @Test public void should_convert_date_to_calendar() throws ParseException { String dateAsString = "26/08/1994"; Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateAsString); Calendar calendar = new GregorianCalendar(); // clear all fields to have a Date without time (no hours, minutes...). calendar.clear(); calendar.set(1994, 07, 26); // month is 0 value based. assertEquals(calendar, toCalendar(date)); } @Test public void should_return_null_if_date_to_convert_is_null() { assertNull(toCalendar(null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_truncateTime_Test.java000066400000000000000000000025441243017530700262640ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.truncateTime; import static org.junit.Assert.*; import java.text.*; import java.util.Date; import org.junit.Test; /** * Tests for {@link Dates#millisecondOf(Date)}. * * @author Joel Costigliola */ public class Dates_truncateTime_Test { @Test public void should_return_millisecond_of_date() throws ParseException { Date date = new SimpleDateFormat("dd/MM/yyyy'T'hh:mm:ss:SS").parse("26/08/1994T22:35:17:29"); Date expectedDate = new SimpleDateFormat("dd/MM/yyyy").parse("26/08/1994"); assertEquals(expectedDate, truncateTime(date)); } @Test public void should_return_null_if_date_is_null() { assertNull(truncateTime(null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Dates_yearOf_Test.java000066400000000000000000000027161243017530700250460ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.fest.util.Dates.yearOf; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import java.text.*; import java.util.Date; import org.junit.*; import org.junit.rules.ExpectedException; /** * Tests for {@link Dates#yearOf(Date)}. * * @author Joel Costigliola */ public class Dates_yearOf_Test { @Rule public ExpectedException thrown = none(); @Test public void should_return_year_of_date() throws ParseException { String dateAsString = "26/08/1994"; Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateAsString); assertEquals(1994, yearOf(date)); } @Test public void should_throws_NullPointerException_if_date_parameter_is_null() { thrown.expect(NullPointerException.class); yearOf(null); } } fest-util-1.2.5/src/test/java/org/fest/util/Employee.java000066400000000000000000000026701243017530700232600ustar00rootroot00000000000000/* * Created on Jun 28, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; /** * Class used for testing {@link Introspection}. * * @author Joel Costigliola */ public class Employee implements Comparable { // field public getter => valid property private final int age; public int getAge() { return age; } // fields without public getter => not a property private final String company = "google"; String getCompany() { return company; } private boolean firstJob; boolean isFirstJob() { return firstJob; } // field without getter => not a property @SuppressWarnings("unused") private final double salary; public Employee(double salary, int age) { super(); this.salary = salary; this.age = age; } @Override public int compareTo(Employee other) { return age - other.age; } } fest-util-1.2.5/src/test/java/org/fest/util/FileFixture.java000066400000000000000000000042731243017530700237300ustar00rootroot00000000000000/* * Created on Sep 25, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static java.lang.String.format; import static org.fest.util.Strings.*; import java.io.*; import java.util.logging.Logger; /** * Creates and deletes files in the file system. * * @author Yvonne Wang * @author Alex Ruiz */ public final class FileFixture { private static Logger logger = Logger.getLogger(FolderFixture.class.getName()); final String name; final FolderFixture parent; private File file; public FileFixture(String name, FolderFixture parent) throws IOException { this.name = name; this.parent = parent; create(); } private void create() throws IOException { String path = relativePath(); file = new File(path); if (!file.exists()) { boolean fileCreated = file.createNewFile(); if (!fileCreated) throw new AssertionError(format("Unable to create file %s", quote(path))); logger.info(format("Created file %s", quote(path))); } if (!file.isFile()) throw new AssertionError(format("%s should be a file", quote(path))); logger.info(format("The file %s exists", quote(path))); } public void delete() { String path = relativePath(); boolean fileDeleted = file.delete(); if (!fileDeleted) throw new AssertionError(String.format("Unable to delete file %s", quote(path))); logger.info(format("The file %s was deleted", quote(path))); } String relativePath() { return parent != null ? concat(parent.relativePath(), separator, name) : name; } String absolutePath() { return file.getAbsolutePath(); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_TestCase.java000066400000000000000000000024601243017530700243330ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import org.junit.After; import org.junit.Before; /** * Base test case for {@link Files}. * * @author Alex Ruiz * @author Yvonne Wang */ public abstract class Files_TestCase { FolderFixture root; @Before public final void setUp() throws Exception { root = new FolderFixture("root"); root.addFolder("dir_1").addFiles("file_1_1", "file_1_2").addFolder("dir_1_1").addFiles("file_1_1_1"); root.addFolder("dir_2").addFiles("file_2_1", "file_2_2", "file_2_3"); } @After public final void tearDown() { root.delete(); } static String systemTemporaryFolder() { return System.getProperty("java.io.tmpdir"); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_contentOf_Test.java000066400000000000000000000044751243017530700255660ustar00rootroot00000000000000/* * Created on Aug 21, 2012 * * 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. * * Copyright @2006-2012 the original author or authors. */ package org.fest.util; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static org.junit.rules.ExpectedException.none; import java.io.File; import java.nio.charset.Charset; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Files#contentOf(File, Charset)} and {@link Files#contentOf(File, String)}. * * @author Olivier Michallat */ public class Files_contentOf_Test { @Rule public ExpectedException thrown = none(); private final File sampleFile = new File("src/test/resources/utf8.txt"); private final String expectedContent = "A text file encoded in UTF-8, with diacritics:\né à"; @Test public void should_throw_exception_if_charset_is_null() { Charset charset = null; thrown.expect(NullPointerException.class); Files.contentOf(new File("test"), charset); } @Test public void should_throw_exception_if_charset_name_does_not_exist() { thrown.expect(IllegalArgumentException.class); Files.contentOf(new File("test"), "Klingon"); } @Test public void should_throw_exception_if_file_not_found() { File missingFile = new File("missing.txt"); assertFalse(missingFile.exists()); thrown.expect(FilesException.class); Files.contentOf(missingFile, Charset.defaultCharset()); } @Test public void should_load_file_using_charset() { // NB: UTF-8 must be supported by every Java implementation assertEquals(expectedContent, Files.contentOf(sampleFile, Charset.forName("UTF-8"))); } @Test public void should_load_file_using_charset_name() { assertEquals(expectedContent, Files.contentOf(sampleFile, "UTF-8")); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_currentFolder_Test.java000066400000000000000000000022211243017530700264300ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; import org.junit.Test; /** * Tests for {@link Files#currentFolder()}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_currentFolder_Test extends Files_TestCase { @Test public void should_return_current_folder() throws IOException { File e = new File("."); File a = Files.currentFolder(); assertEquals(e.getCanonicalPath(), a.getCanonicalPath()); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_delete_Test.java000066400000000000000000000025131243017530700250600ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertFalse; import java.io.File; import java.io.IOException; import org.junit.Test; /** * Tests for {@link Files#delete(File)}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_delete_Test extends Files_TestCase { @Test public void should_delete_folder() throws IOException { FolderFixture dir3 = new FolderFixture("dir_3"); dir3.addFiles("file_3_1").addFiles("file_3_2").addFiles("file_3_2"); dir3.addFolder("dir_3_1").addFiles("file_3_1_1").addFiles("file_3_1_2"); File d = dir3.dir(); String path = d.getCanonicalPath(); Files.delete(d); assertFalse(new File(path).exists()); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_fileNamesIn_Test.java000066400000000000000000000057251243017530700260200ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static org.fest.util.Lists.newArrayList; import static org.fest.util.Strings.concat; import static org.junit.Assert.*; import static org.junit.rules.ExpectedException.none; import java.io.File; import java.util.HashSet; import java.util.List; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Files#fileNamesIn(String, boolean)}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_fileNamesIn_Test extends Files_TestCase { @Rule public ExpectedException thrown = none(); @Test public void should_throw_error_if_directory_does_not_exist() { String path = concat("root", separator, "not_existing_dir"); thrown.expect(IllegalArgumentException.class); Files.fileNamesIn(path, false); } @Test public void should_throw_error_if_path_does_not_belong_to_a_directory() throws Exception { String fileName = "file_1"; root.addFiles(fileName); String path = concat("root", separator, fileName); thrown.expect(IllegalArgumentException.class); Files.fileNamesIn(path, false); } @Test public void should_return_names_of_files_in_given_directory_but_not_subdirectories() { String path = concat("root", separator, "dir_1"); assertThatContainsFiles(newArrayList("file_1_1", "file_1_2"), Files.fileNamesIn(path, false)); } @Test public void should_return_names_of_files_in_given_directory_and_its_subdirectories() { String path = concat("root", separator, "dir_1"); assertThatContainsFiles(newArrayList("file_1_1", "file_1_2", "file_1_1_1"), Files.fileNamesIn(path, true)); } private void assertThatContainsFiles(List expectedFiles, List actualFiles) { assertThereAreNoDuplicates(actualFiles); for (String fileName : actualFiles) { assertTrue(expectedFiles.remove(pathNameFor(fileName))); } assertTrue(expectedFiles.isEmpty()); } private String pathNameFor(String fileName) { return new File(fileName).getName(); } private void assertThereAreNoDuplicates(List actualFiles) { if (actualFiles == null || actualFiles.isEmpty()) { return; } HashSet withoutDuplicates = new HashSet(actualFiles); assertEquals(withoutDuplicates.size(), actualFiles.size()); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_newFile_Test.java000066400000000000000000000033611243017530700252110ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static org.fest.util.Strings.join; import static org.junit.Assert.assertTrue; import static org.junit.rules.ExpectedException.none; import java.io.File; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Files#newFile(String)}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_newFile_Test extends Files_TestCase { @Rule public ExpectedException thrown = none(); @Test public void should_throw_error_if_file_path_belongs_to_directory_that_is_not_empty() { thrown.expect(FilesException.class); Files.newFile("root"); } @Test public void should_throw_error_if_file_path_belongs_to_an_existing_file() { String path = join("root", "dir_1", "file_1_1").with(separator); thrown.expect(FilesException.class); Files.newFile(path); } @Test public void should_create_new_file() { File f = null; try { f = Files.newFile("file"); assertTrue(f.isFile()); } finally { if (f != null) f.delete(); } } } fest-util-1.2.5/src/test/java/org/fest/util/Files_newFolder_Test.java000066400000000000000000000021701243017530700255420ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertTrue; import java.io.File; import org.junit.Test; /** * Tests for {@link Files#newFolder(String)}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_newFolder_Test extends Files_TestCase { @Test public void should_create_new_folder() { File f = null; try { f = Files.newFolder("folder"); assertTrue(f.isDirectory()); } finally { if (f != null) f.delete(); } } } fest-util-1.2.5/src/test/java/org/fest/util/Files_newTemporaryFile_Test.java000066400000000000000000000022041243017530700271070ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertTrue; import java.io.File; import org.junit.Test; /** * Tests for {@link Files#newTemporaryFolder()}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_newTemporaryFile_Test extends Files_TestCase { @Test public void should_create_new_temporary_file() { File f = null; try { f = Files.newTemporaryFile(); assertTrue(f.isFile()); } finally { if (f != null) f.delete(); } } } fest-util-1.2.5/src/test/java/org/fest/util/Files_newTemporaryFolder_Test.java000066400000000000000000000022151243017530700274450ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertTrue; import java.io.File; import org.junit.Test; /** * Tests for {@link Files#newTemporaryFile()}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_newTemporaryFolder_Test extends Files_TestCase { @Test public void should_create_new_temporary_folder() { File f = null; try { f = Files.newTemporaryFolder(); assertTrue(f.isDirectory()); } finally { if (f != null) f.delete(); } } } fest-util-1.2.5/src/test/java/org/fest/util/Files_temporaryFolderPath_Test.java000066400000000000000000000022661243017530700276160ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static org.fest.util.Strings.append; import static org.junit.Assert.assertEquals; import org.junit.Test; /** * Tests for {@link Files#temporaryFolderPath()}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_temporaryFolderPath_Test extends Files_TestCase { @Test public void should_find_path_of_temporary_folder() { String a = Files.temporaryFolderPath(); String e = append(separator).to(systemTemporaryFolder()); assertEquals(e, a); } } fest-util-1.2.5/src/test/java/org/fest/util/Files_temporaryFolder_Test.java000066400000000000000000000024601243017530700267750ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static org.fest.util.Strings.append; import static org.junit.Assert.*; import java.io.File; import org.junit.Test; /** * Tests for {@link Files#temporaryFolder()}. * * @author Alex Ruiz * @author Yvonne Wang */ public class Files_temporaryFolder_Test extends Files_TestCase { @Test public void should_find_temporary_folder() { File temporaryFolder = Files.temporaryFolder(); assertTrue(temporaryFolder.isDirectory()); String a = append(separator).to(temporaryFolder.getAbsolutePath()); String e = append(separator).to(systemTemporaryFolder()); assertEquals(e, a); } } fest-util-1.2.5/src/test/java/org/fest/util/Flushables_flush_Test.java000066400000000000000000000040161243017530700257650ustar00rootroot00000000000000/* * Created on Jan 15, 2008 * * 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. * * Copyright @2008-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertTrue; import java.io.Flushable; import java.io.IOException; import org.junit.Test; /** * Tests for {@link Flushables#flush(Flushable...)}. * * @author Yvonne Wang */ public class Flushables_flush_Test { private static class FlushableStub implements Flushable { boolean flushed; IOException toThrow; public FlushableStub() {} public FlushableStub(IOException toThrow) { this.toThrow = toThrow; } public void flush() throws IOException { flushed = true; if (toThrow != null) throw toThrow; } } @Test public void should_flush_Flushables() { FlushableStub[] toFlush = new FlushableStub[] { new FlushableStub(), new FlushableStub() }; Flushables.flush(toFlush); assertFlushed(toFlush); } @Test public void should_ignore_thrown_errors() { FlushableStub[] toFlush = new FlushableStub[] { new FlushableStub(new IOException("")), new FlushableStub() }; Flushables.flush(toFlush); assertFlushed(toFlush); } @Test public void should_ignore_null_Flushables() { FlushableStub c = new FlushableStub(); FlushableStub[] toFlush = new FlushableStub[] { null, c }; Flushables.flush(toFlush); assertFlushed(c); } private void assertFlushed(FlushableStub... toFlush) { for (FlushableStub c : toFlush) assertTrue(c.flushed); } } fest-util-1.2.5/src/test/java/org/fest/util/FolderFixture.java000066400000000000000000000070251243017530700242620ustar00rootroot00000000000000/* * Created on Sep 25, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.io.File.separator; import static java.lang.String.format; import static org.fest.util.Arrays.isNullOrEmpty; import static org.fest.util.Strings.*; import static org.junit.Assert.assertTrue; import java.io.*; import java.util.*; import java.util.logging.Logger; /** * Creates and deletes directories in the file system. * * @author Yvonne Wang * @author Alex Ruiz */ public final class FolderFixture { private static Logger logger = Logger.getLogger(FolderFixture.class.getName()); private final List folders = new ArrayList(); private final List files = new ArrayList(); private final String name; private final FolderFixture parent; private File dir; public FolderFixture(String name) { this(name, null); } public FolderFixture(String name, FolderFixture parent) { this.name = name; this.parent = parent; create(); } File dir() { return dir; } private void create() { String path = relativePath(); dir = new File(path); if (!dir.exists()) { assertTrue(dir.mkdir()); logger.info(format("Created directory %s", quote(path))); return; } if (!dir.isDirectory()) throw new AssertionError(String.format("%s should be a directory", quote(path))); logger.info(format("The directory %s already exists", quote(path))); } public FolderFixture addFolder(String folderName) { FolderFixture child = new FolderFixture(folderName, this); folders.add(child); return child; } public FolderFixture addFiles(String... names) throws IOException { for (String file : names) files.add(new FileFixture(file, this)); return this; } public void delete() { for (FolderFixture folder : folders) folder.delete(); for (FileFixture file : files) file.delete(); String path = relativePath(); boolean dirDeleted = dir.delete(); if (!dirDeleted) throw new AssertionError(String.format("Unable to delete directory %s", quote(path))); logger.info(format("The directory %s was deleted", quote(path))); } String relativePath() { return parent != null ? concat(parent.relativePath(), separator, name) : name; } public FolderFixture folder(String path) { String[] names = path.split(separatorAsRegEx()); if (isNullOrEmpty(names)) return null; int i = 0; if (!name.equals(names[i++])) return null; FolderFixture current = this; for (; i < names.length; i++) { current = current.childFolder(names[i]); if (current == null) break; } return current; } private FolderFixture childFolder(String folderName) { for (FolderFixture folder : folders) if (folder.name.equals(folderName)) return folder; return null; } private String separatorAsRegEx() { String regex = separator; if ("\\".equals(regex)) regex = "\\\\"; return regex; } } fest-util-1.2.5/src/test/java/org/fest/util/Introspection_getProperty_Test.java000066400000000000000000000040201243017530700277330ustar00rootroot00000000000000/* * Created on Jun 28, 2010 * * 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. * * Copyright @2010-2012 the original author or authors. */ package org.fest.util; import static junit.framework.Assert.*; import static org.fest.util.Introspection.getProperty; import java.beans.PropertyDescriptor; import org.junit.*; /** * Tests for {@link Introspection#getProperty(String, Object)}. * * @author Joel Costigliola */ public class Introspection_getProperty_Test { private Employee judy; @Before public void initData() { judy = new Employee(100000.0, 31); } @Test public void get_descriptor_for_property() { PropertyDescriptor propertyDescriptor = getProperty("age", judy); assertNotNull(propertyDescriptor); assertEquals("age", propertyDescriptor.getName()); } @Test public void should_raise_an_error_because_of_missing_getter() { try { getProperty("salary", judy); } catch (IntrospectionError error) { assertEquals("No getter for property 'salary' in org.fest.util.Employee", error.getMessage()); } } @Test public void should_raise_an_error_because_of_non_public_getter() { try { getProperty("company", judy); } catch (IntrospectionError error) { assertEquals("No public getter for property 'company' in org.fest.util.Employee", error.getMessage()); } try { getProperty("firstJob", judy); } catch (IntrospectionError error) { assertEquals("No public getter for property 'firstJob' in org.fest.util.Employee", error.getMessage()); } } } fest-util-1.2.5/src/test/java/org/fest/util/Iterables_isNullOrEmpty_Test.java000066400000000000000000000040501243017530700272520ustar00rootroot00000000000000/* * Created on Aug 23, 2012 * * 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. * * Copyright @2012 Google, Inc. and others. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.Test; /** * Tests for {@link Iterables#isNullOrEmpty(Iterable)}. * * @author Alex Ruiz */ public class Iterables_isNullOrEmpty_Test { @Test public void should_return_true_if_Collection_is_empty() { Iterable c = new ArrayList(); assertTrue(Iterables.isNullOrEmpty(c)); } @Test public void should_return_false_if_Collection_has_elements() { Iterable c = newArrayList("Frodo"); assertFalse(Iterables.isNullOrEmpty(c)); } @Test public void should_return_true_if_Iterable_is_empty() { Iterable i = new StringIterable(); assertTrue(Iterables.isNullOrEmpty(i)); } @Test public void should_return_true_if_Iterable_is_null() { assertTrue(Iterables.isNullOrEmpty(null)); } @Test public void should_return_false_if_Iterable_has_elements() { Iterable i = new StringIterable("Frodo"); assertFalse(Iterables.isNullOrEmpty(i)); } private static class StringIterable implements Iterable { private final List elements; StringIterable(String...elements) { this.elements = Lists.newArrayList(elements); } @Override public Iterator iterator() { return elements.iterator(); } } } fest-util-1.2.5/src/test/java/org/fest/util/Iterables_nonNullElementsIn_Test.java000066400000000000000000000034511243017530700301010ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.fest.util.Lists.newArrayList; import static org.junit.Assert.*; import java.util.*; import org.junit.Test; /** * Tests for {@link Iterables#nonNullElementsIn(Iterable)}. * * @author Joel Costigliola * @author Alex Ruiz */ public class Iterables_nonNullElementsIn_Test { @Test public void should_return_empty_List_if_given_Iterable_is_null() { Collection c = null; assertTrue(Iterables.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_empty_List_if_given_Iterable_has_only_null_elements() { Collection c = new ArrayList(); c.add(null); assertTrue(Iterables.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_empty_List_if_given_Iterable_is_empty() { Collection c = new ArrayList(); assertTrue(Iterables.nonNullElementsIn(c).isEmpty()); } @Test public void should_return_a_list_without_null_elements() { List c = newArrayList("Frodo", null, "Sam", null); List nonNull = Iterables.nonNullElementsIn(c); assertArrayEquals(new String[] { "Frodo", "Sam" }, nonNull.toArray()); } } fest-util-1.2.5/src/test/java/org/fest/util/Iterables_sizeOf_Test.java000066400000000000000000000032411243017530700257240ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static junit.framework.Assert.assertEquals; import static org.fest.util.Lists.newArrayList; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import org.junit.Test; /** * Tests for {@link Iterables#sizeOf(Iterable)}. * * @author Joel Costigliola * @author Alex Ruiz */ public class Iterables_sizeOf_Test { @Test public void should_return_zero_if_iterable_is_empty() { assertEquals(0, Iterables.sizeOf(new ArrayList())); } @Test(expected = NullPointerException.class) public void should_throws_exception_if_iterable_is_null() { Iterables.sizeOf(null); } @Test public void should_return_iterable_size() { List list = newArrayList("Frodo", "Sam"); assertEquals(2, Iterables.sizeOf(list)); } @Test public void should_return_correct_size_for_non_collection_iterable() { Iterable sqlException = new SQLException(new Exception(new Exception())); assertEquals(3, Iterables.sizeOf(sqlException)); } } fest-util-1.2.5/src/test/java/org/fest/util/Lists_newArrayList_withIterable_Test.java000066400000000000000000000031131243017530700307760ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static java.util.Arrays.asList; import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; /** * Tests for {@link Lists#newArrayList(Iterable)}. * * @author Joel Costigliola */ public class Lists_newArrayList_withIterable_Test { @Test public void should_return_List_containing_all_elements_in_iterable() { String[] expected = { "One", "Two" }; Iterable elements = asList(expected); ArrayList list = Lists.newArrayList(elements); assertArrayEquals(expected, list.toArray()); } @Test public void should_return_null_if_iterable_is_null() { Iterable elements = null; assertNull(Lists.newArrayList(elements)); } @Test public void should_return_empty_List_if_iterable_is_empty() { Iterable elements = new ArrayList(); ArrayList list = Lists.newArrayList(elements); assertTrue(list.isEmpty()); } } fest-util-1.2.5/src/test/java/org/fest/util/Lists_newArrayList_withVarArgs_Test.java000066400000000000000000000026641243017530700306260ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; /** * Tests for {@link Lists#newArrayList(Object...)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Lists_newArrayList_withVarArgs_Test { @Test public void should_return_List_containing_all_elements_in_array() { String[] expected = { "One", "Two" }; ArrayList list = Lists.newArrayList(expected); assertArrayEquals(expected, list.toArray()); } @Test public void should_return_null_if_array_is_null() { Object[] elements = null; assertNull(Lists.newArrayList(elements)); } @Test public void should_return_empty_List_if_array_is_empty() { ArrayList list = Lists.newArrayList(new Object[0]); assertTrue(list.isEmpty()); } } fest-util-1.2.5/src/test/java/org/fest/util/Maps_format_Test.java000066400000000000000000000026731243017530700247530ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import java.io.File; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.junit.Test; /** * Tests for {@link Maps#format(Map)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Maps_format_Test { @Test public void should_return_null_if_Map_is_null() { assertNull(Maps.format(null)); } @Test public void should_return_empty_braces_if_Map_is_empty() { assertEquals(Maps.format(new HashMap()), "{}"); } @Test public void should_format_Map() { Map> map = new LinkedHashMap>(); map.put("One", String.class); map.put("Two", File.class); assertEquals("{'One'=java.lang.String, 'Two'=java.io.File}", Maps.format(map)); } } fest-util-1.2.5/src/test/java/org/fest/util/Maps_isNullOrEmpty_Test.java000066400000000000000000000025321243017530700262430ustar00rootroot00000000000000/* * Created on Apr 29, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Tests for {@link Maps#isNullOrEmpty(Map)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Maps_isNullOrEmpty_Test { @Test public void should_return_true_if_Map_is_empty() { assertTrue(Maps.isNullOrEmpty(new HashMap())); } @Test public void should_return_true_if_Map_is_null() { assertTrue(Maps.isNullOrEmpty(null)); } @Test public void should_return_false_if_Map_has_elements() { Map map = new HashMap(); map.put("First", 1); assertFalse(Maps.isNullOrEmpty(map)); } } fest-util-1.2.5/src/test/java/org/fest/util/Objects_areEqual_Test.java000066400000000000000000000050521243017530700257050ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Objects#areEqual(Object, Object)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Objects_areEqual_Test { @Test public void should_return_true_if_both_Objects_are_null() { assertTrue(Objects.areEqual(null, null)); } @Test public void should_return_true_if_Objects_are_equal() { assertTrue(Objects.areEqual("Yoda", "Yoda")); } @Test public void should_return_are_not_equal_if_first_Object_is_null_and_second_is_not() { assertFalse(Objects.areEqual(null, "Yoda")); } @Test public void should_return_are_not_equal_if_second_Object_is_null_and_first_is_not() { assertFalse(Objects.areEqual("Yoda", null)); } @Test public void should_return_are_not_equal_if_Objects_are_not_equal() { assertFalse(Objects.areEqual("Yoda", 2)); } @Test public void should_return_true_if_arrays_of_Objects_are_equal() { Object[] a1 = { "Luke", "Yoda", "Leia" }; Object[] a2 = { "Luke", "Yoda", "Leia" }; assertTrue(Objects.areEqual(a1, a1)); assertTrue(Objects.areEqual(a1, a2)); } @Test public void should_return_true_if_arrays_of_primitives_are_equal() { int[] a1 = { 6, 8, 10 }; int[] a2 = { 6, 8, 10 }; assertTrue(Objects.areEqual(a1, a2)); } @Test public void should_return_false_if_arrays_of_Objects_are_not_equal() { Object[] a1 = { "Luke", "Yoda", "Leia" }; Object[] a2 = new Object[0]; assertFalse(Objects.areEqual(a1, a2)); } @Test public void should_return_false_if_arrays_of_primitives_are_not_equal() { int[] a1 = { 6, 8, 10 }; boolean[] a2 = { true }; assertFalse(Objects.areEqual(a1, a2)); } @Test public void should_return_false_if_one_parameter_is_not_an_array() { Object[] a1 = { "Luke", "Yoda", "Leia" }; assertFalse(Objects.areEqual(a1, "")); assertFalse(Objects.areEqual("", a1)); } } fest-util-1.2.5/src/test/java/org/fest/util/Objects_castIfBelongsToType_Test.java000066400000000000000000000026451243017530700300430ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Objects#castIfBelongsToType(Object, Class)}. * * @author Yvonne Wang * @author Alex Ruiz * @author Joel Costigliola */ public class Objects_castIfBelongsToType_Test { @Test public void should_return_object_casted_to_given_type() { Object o = "Frodo"; String casted = Objects.castIfBelongsToType(o, String.class); assertSame(casted, o); } @Test public void should_return_null_if_object_does_not_belong_to_given_type() { Object o = 4; String casted = Objects.castIfBelongsToType(o, String.class); assertNull(casted); } @Test public void should_return_null_if_object_is_null() { assertNull(Objects.castIfBelongsToType(null, String.class)); } } fest-util-1.2.5/src/test/java/org/fest/util/Objects_hashCodeFor_Test.java000066400000000000000000000021751243017530700263360ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import org.junit.Test; /** * Tests for {@link Objects#hashCodeFor(Object)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Objects_hashCodeFor_Test { @Test public void should_return_hashCode_of_given_Object() { String s = "Yoda"; assertEquals(s.hashCode(), Objects.hashCodeFor(s)); } @Test public void should_return_zero_if_Object_is_null() { assertEquals(0, Objects.hashCodeFor(null)); } } fest-util-1.2.5/src/test/java/org/fest/util/Objects_namesOf_Test.java000066400000000000000000000027621243017530700255430ustar00rootroot00000000000000/* * Created on Sep 23, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static java.lang.String.format; import static org.junit.Assert.*; import java.util.Arrays; import org.junit.Test; /** * Tests for {@link Objects#namesOf(Class...)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Objects_namesOf_Test { @Test public void should_return_empty_array_if_type_array_is_null() { assertEquals(Objects.namesOf((Class[]) null).length, 0); } @Test public void should_return_empty_array_if_type_array_is_empty() { assertEquals(Objects.namesOf(new Class[0]).length, 0); } @Test public void should_return_class_names() { String[] e = { String.class.getName(), Integer.class.getName() }; String[] a = Objects.namesOf(String.class, Integer.class); assertTrue(format("expected:<%s> but got:<%s>", Arrays.toString(e), Arrays.toString(a)), Arrays.equals(e, a)); } } fest-util-1.2.5/src/test/java/org/fest/util/Sets_newLinkedHashSet_Test.java000066400000000000000000000026741243017530700267020ustar00rootroot00000000000000/* * Created on Oct 8, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import java.util.LinkedHashSet; import org.junit.Test; /** * Tests for {@link Sets#newLinkedHashSet(Object...)}. * * @author Yvonne Wang * @author Alex Ruiz */ public class Sets_newLinkedHashSet_Test { @Test public void should_return_Set_containing_all_elements_in_array() { String[] expected = { "One", "Two" }; LinkedHashSet set = Sets.newLinkedHashSet(expected); assertArrayEquals(expected, set.toArray()); } @Test public void should_return_null_if_array_is_null() { Object[] elements = null; assertNull(Sets.newLinkedHashSet(elements)); } @Test public void should_return_empty_Set_if_array_is_empty() { LinkedHashSet set = Sets.newLinkedHashSet(new Object[0]); assertTrue(set.isEmpty()); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_append_Test.java000066400000000000000000000021161243017530700254530ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import org.junit.Test; /** * Tests for {@link Strings#append(String)}. * * @author Alex Ruiz */ public class Strings_append_Test { @Test public void should_append_String() { assertEquals("abc", Strings.append("c").to("ab")); } @Test public void should_not_append_String_if_already_present() { assertEquals("abc", Strings.append("c").to("abc")); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_concat_Test.java000066400000000000000000000021241243017530700254520ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Strings#concat(Object...)}. * * @author Alex Ruiz */ public class Strings_concat_Test { @Test public void should_return_null_if_array_is_null() { assertNull(Strings.concat((Object[]) null)); } @Test public void should_concatenate_given_Strings() { assertEquals("OneTwoThree", Strings.concat("One", "Two", "Three")); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_isEmpty_Test.java000066400000000000000000000022671243017530700256450ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Strings#isNullOrEmpty(String)}. * * @author Alex Ruiz */ public class Strings_isEmpty_Test { @Test public void should_return_true_if_String_is_empty() { assertTrue(Strings.isNullOrEmpty("")); } @Test public void should_return_true_if_String_is_null() { assertTrue(Strings.isNullOrEmpty(null)); } @Test public void should_return_false_if_String_is_not_empty() { assertFalse(Strings.isNullOrEmpty("foo")); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_join_Test.java000066400000000000000000000027251243017530700251510ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import static org.junit.rules.ExpectedException.none; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; /** * Tests for {@link Strings#join(String...)}. * * @author Alex Ruiz */ public class Strings_join_Test { @Rule public ExpectedException thrown = none(); @Test public void should_throw_error_if_delimeter_is_null() { thrown.expect(IllegalArgumentException.class); Strings.join(null, "Uno", "Dos").with(null); } @Test public void should_return_empty_String_if_array_to_join_is_null() { assertEquals("", Strings.join((String[]) null).with("|")); } @Test public void should_join_using_delimeter() { assertEquals("Luke|Leia|Han", Strings.join("Luke", "Leia", "Han").with("|")); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_quoteObject_Test.java000066400000000000000000000021361243017530700264720ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import org.junit.Test; /** * Tests for {@link Strings#quote(Object)}. * * @author Alex Ruiz */ public class Strings_quoteObject_Test { @Test public void should_not_quote_Object_that_is_not_String() { assertEquals(9, Strings.quote(9)); } @Test public void should_quote_Object_that_is_String() { Object o = "Hello"; assertEquals("'Hello'", Strings.quote(o)); } } fest-util-1.2.5/src/test/java/org/fest/util/Strings_quoteString_Test.java000066400000000000000000000022121243017530700265250ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2011 the original author or authors. */ package org.fest.util; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for {@link Strings#quote(String)}. * * @author Alex Ruiz */ public class Strings_quoteString_Test { @Test public void should_quote_String() { assertEquals("'foo'", Strings.quote("foo")); } @Test public void should_quote_empty_String() { assertEquals("''", Strings.quote("")); } @Test public void should_return_null_if_String_is_null() { assertNull(Strings.quote(null)); } } fest-util-1.2.5/src/test/java/org/fest/util/SystemsProperties_lineSeparator_Test.java000066400000000000000000000020031243017530700311020ustar00rootroot00000000000000/* * Created on Feb 10, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import org.junit.Test; /** * Tests for {@link SystemProperties#LINE_SEPARATOR}. * * @author Yvonne Wang */ public class SystemsProperties_lineSeparator_Test { @Test public void should_return_line_separator() { assertEquals(System.getProperty("line.separator"), SystemProperties.LINE_SEPARATOR); } } Throwables_appendCurrentThreadStackTraceToThrowable_Test.java000066400000000000000000000045671243017530700347040ustar00rootroot00000000000000fest-util-1.2.5/src/test/java/org/fest/util/* * Created on Dec 13, 2008 * * 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. * * Copyright @2008-2012 the original author or authors. */ package org.fest.util; import static java.lang.Thread.currentThread; import static org.fest.util.Strings.concat; import static org.junit.Assert.assertEquals; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; import org.junit.Test; /** * Tests for {@link Throwables#appendStackTraceInCurentThreadToThrowable(Throwable, String)}. * * @author Alex Ruiz */ public class Throwables_appendCurrentThreadStackTraceToThrowable_Test { private AtomicReference exceptionReference; @Before public void setUp() { exceptionReference = new AtomicReference(); } @Test public void should_add_stack_trace_of_current_thread() { final CountDownLatch latch = new CountDownLatch(1); new Thread() { @Override public void run() { RuntimeException e = new RuntimeException("Thrown on purpose"); exceptionReference.set(e); latch.countDown(); } }.start(); try { latch.await(); } catch (InterruptedException e) { currentThread().interrupt(); } RuntimeException thrown = exceptionReference.get(); Throwables.appendStackTraceInCurentThreadToThrowable(thrown, "should_add_stack_trace_of_current_thread"); StackTraceElement[] stackTrace = thrown.getStackTrace(); assertEquals("org.fest.util.Throwables_appendCurrentThreadStackTraceToThrowable_Test$1.run", asString(stackTrace[0])); assertEquals( "org.fest.util.Throwables_appendCurrentThreadStackTraceToThrowable_Test.should_add_stack_trace_of_current_thread", asString(stackTrace[1])); } private String asString(StackTraceElement e) { return concat(e.getClassName(), ".", e.getMethodName()); } } fest-util-1.2.5/src/test/java/org/fest/util/Throwables_removeFestElementFromStackTrace_Test.java000066400000000000000000000034241243017530700331120ustar00rootroot00000000000000/* * Created on Dec 13, 2008 * * 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. * * Copyright @2008-2011-2010 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; /** * Tests for {@link Throwables#removeFestRelatedElementsFromStackTrace(Throwable)}. * * @author Joel Costigliola */ public class Throwables_removeFestElementFromStackTrace_Test { @Test public void should_add_stack_trace_of_current_thread() { try { throw new FestThrowable(); } catch (FestThrowable throwable) { assertTrue(hasStackTraceElementContainingFestClass(throwable)); Throwables.removeFestRelatedElementsFromStackTrace(throwable); assertFalse(hasStackTraceElementContainingFestClass(throwable)); } } private static boolean hasStackTraceElementContainingFestClass(FestThrowable throwable) { StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement stackTraceElement : stackTrace) { if (stackTraceElement.getClassName().contains("org.fest")) { return true; } } return false; } private static class FestThrowable extends Throwable { private static final long serialVersionUID = 1L; } } fest-util-1.2.5/src/test/java/org/fest/util/ToString_toStringOf_Test.java000066400000000000000000000116511243017530700264260ustar00rootroot00000000000000/* * Created on Sep 22, 2006 * * 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. * * Copyright @2006-2012 the original author or authors. */ package org.fest.util; import static junit.framework.Assert.assertFalse; import static org.fest.util.Arrays.array; import static org.fest.util.Lists.newArrayList; import static org.fest.util.ToString.toStringOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.junit.Test; /** * Tests for {@link ToString#toStringOf(Object)}. * * @author Joel Costigliola */ public class ToString_toStringOf_Test { @Test public void should_return_null_if_object_is_null() { assertNull(ToString.toStringOf(null)); } @Test public void should_quote_String() { assertEquals("'Hello'", ToString.toStringOf("Hello")); } @Test public void should_quote_empty_String() { assertEquals("''", ToString.toStringOf("")); } @Test public void should_return_toString_of_File() { final String path = "/someFile.txt"; @SuppressWarnings("serial") File o = new File(path) { @Override public String getAbsolutePath() { return path; } }; assertEquals(path, ToString.toStringOf(o)); } @Test public void should_return_toString_of_Class_with_its_name() { assertEquals("java.lang.Object", ToString.toStringOf(Object.class)); } @Test public void should_return_toString_of_Collection_of_String() { Collection collection = newArrayList("s1", "s2"); assertEquals("['s1', 's2']", ToString.toStringOf(collection)); } @Test public void should_return_toString_of_Collection_of_arrays() { List collection = newArrayList(array(true, false), array(true, false, true)); assertEquals("[[true, false], [true, false, true]]", ToString.toStringOf(collection)); } @Test public void should_return_toString_of_Collection_of_Collections() { Collection> collection = new ArrayList>(); collection.add(newArrayList("s1", "s2")); collection.add(newArrayList("s3", "s4", "s5")); assertEquals("[['s1', 's2'], ['s3', 's4', 's5']]", ToString.toStringOf(collection)); } @Test public void should_return_toString_of_Map() { Map map = new LinkedHashMap(); map.put("key1", "value1"); map.put("key2", "value2"); assertEquals("{'key1'='value1', 'key2'='value2'}", ToString.toStringOf(map)); } @Test public void should_return_toString_of_array() { assertEquals("['s1', 's2']", ToString.toStringOf(array("s1", "s2"))); } @Test public void should_return_toString_of_array_of_arrays() { String[][] array = array(array("s1", "s2"), array("s3", "s4", "s5")); assertEquals("[['s1', 's2'], ['s3', 's4', 's5']]", ToString.toStringOf(array)); } @Test public void should_return_toString_of_array_of_Class() { Class[] array = { String.class, File.class }; assertEquals("[java.lang.String, java.io.File]", ToString.toStringOf(array)); } @Test public void should_return_toString_of_calendar() { GregorianCalendar calendar = new GregorianCalendar(2011, Calendar.JANUARY, 18, 23, 53, 17); assertEquals("2011-01-18T23:53:17", ToString.toStringOf(calendar)); } @Test public void should_return_toString_of_date() { Date date = new GregorianCalendar(2011, Calendar.JUNE, 18, 23, 53, 17).getTime(); assertEquals("2011-06-18T23:53:17", ToString.toStringOf(date)); } @Test public void toString_with_anonymous_comparator() { Comparator anonymousComparator = new Comparator() { @Override public int compare(String s1, String s2) { return s1.length() - s2.length(); } }; assertEquals("'Anonymous Comparator class'", ToString.toStringOf(anonymousComparator)); } @Test public void should_format_longs_and_integers() { assertFalse(toStringOf(20L).equals(toStringOf(20))); assertEquals("20", toStringOf(20)); assertEquals("20L", toStringOf(20L)); } @Test public void should_format_doubles_and_floats() { assertFalse(toStringOf(20.0f).equals(toStringOf(20.0))); assertEquals("20.0", toStringOf(20.0)); assertEquals("20.0f", toStringOf(20.0f)); } } fest-util-1.2.5/src/test/java/org/fest/util/TypeFilter_filter_Test.java000066400000000000000000000023621243017530700261320ustar00rootroot00000000000000/* * Created on Nov 1, 2007 * * 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. * * Copyright @2007-2012 the original author or authors. */ package org.fest.util; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; import org.junit.Test; /** * Tests for {@link TypeFilter#filter(java.util.Collection)}. * * @author Yvonne Wang */ public class TypeFilter_filter_Test { @Test public void should_filter_Collection() { List original = new ArrayList(); original.add(1); original.add("Frodo"); original.add(5); List filtered = new TypeFilter(String.class).filter(original); assertEquals(1, filtered.size()); assertEquals("Frodo", filtered.get(0)); } } fest-util-1.2.5/src/test/resources/000077500000000000000000000000001243017530700172155ustar00rootroot00000000000000fest-util-1.2.5/src/test/resources/utf8.txt000066400000000000000000000000641243017530700206440ustar00rootroot00000000000000A text file encoded in UTF-8, with diacritics: é à