-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
253 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
cukedoctor-reporter/src/main/java/com/github/cukedoctor/util/Assert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package com.github.cukedoctor.util; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by rafael-pestano on 26/06/2015. | ||
*/ | ||
public class Assert implements Serializable { | ||
|
||
private Assert() { | ||
|
||
} | ||
|
||
/** | ||
* @return TRUE assertion when given objects is not null, FALSE otherwise | ||
*/ | ||
public static boolean notNull(Object object) { | ||
|
||
return object != null; | ||
} | ||
|
||
/** | ||
* @return TRUE assertion when given objects is null, FALSE otherwise | ||
*/ | ||
public static boolean isNull(Object object) { | ||
|
||
return object == null; | ||
} | ||
|
||
/** | ||
* just negates the assertion | ||
*/ | ||
public static boolean not(boolean assertion) { | ||
|
||
return !assertion; | ||
} | ||
|
||
/** | ||
* @return TRUE when given text has any character, FALSE otherwise | ||
*/ | ||
public static boolean hasText(String text) { | ||
if (notNull(text) && text.trim().length() > 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return TRUE when given text contains the given substring, FALSE | ||
* otherwise | ||
*/ | ||
public static boolean contains(String textToSearch, String substring) { | ||
if (notNull(textToSearch) && textToSearch.contains(substring)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return TRUE when given array has elements; that is, it must not be | ||
* {@code null} and must have at least one element. FALSE otherwise | ||
*/ | ||
public static boolean notEmpty(Object[] array) { | ||
if (array == null || array.length == 0) { | ||
return false; | ||
} | ||
for (Object element : array) { | ||
if (element != null) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return TRUE when given collection has elements; that is, it must not be | ||
* {@code null} and must have at least one element. @return FALSE otherwise | ||
*/ | ||
public static boolean notEmpty(Collection<?> collection) { | ||
if (notNull(collection) && !collection.isEmpty()) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @return TRUE if given Map has entries; that is, it must not be {@code null} | ||
* and must have at least one entry. Queue FALSE otherwise | ||
*/ | ||
public static boolean notEmpty(Map<?, ?> map) { | ||
if (map == null) { | ||
return false; | ||
} | ||
if (hasElements(map.entrySet().toArray())) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Assert that an array has no null elements. Note: Does not complain if the | ||
* array is empty! | ||
* | ||
* <pre class="code"> | ||
* Assert.noNullElements(array, "The array must have non-null elements"); | ||
* </pre> | ||
* | ||
* @param array the array | ||
*/ | ||
/** | ||
* @return TRUE when given array has no null elements; FALSE otherwise | ||
*/ | ||
public static boolean notNull(Object[] array) { | ||
if (array != null) { | ||
for (Object element : array) { | ||
if (element == null) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* TRUE when given array has at least one not null element; FALSE | ||
* otherwise | ||
*/ | ||
public static boolean hasElements(Object[] array) { | ||
if (hasElements(array)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.