pax_global_header 0000666 0000000 0000000 00000000064 12430205632 0014507 g ustar 00root root 0000000 0000000 52 comment=f58d3821531dfafd5f51d56f01a13b7b376b4845
fest-assert-2.0M10/ 0000775 0000000 0000000 00000000000 12430205632 0014066 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/.gitignore 0000664 0000000 0000000 00000000265 12430205632 0016061 0 ustar 00root root 0000000 0000000 #Maven build result directory
/target
#IntelliJ project files
/.idea
/*.iml
#Eclipse project files
/.settings
/.classpath
/.project
#Other
/clover.license
/actual.txt
/expected.txt
fest-assert-2.0M10/LICENSE.txt 0000664 0000000 0000000 00000026136 12430205632 0015721 0 ustar 00root root 0000000 0000000
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-assert-2.0M10/README.md 0000664 0000000 0000000 00000002520 12430205632 0015344 0 ustar 00root root 0000000 0000000 FEST-Assert provides a fluent interface for assertions.
Example:
```
int removed = employees.removeFired();
assertThat(removed).isZero();
List newEmployees = employees.hired(TODAY);
assertThat(newEmployees).hasSize(6)
.contains(frodo, sam);
assertThat(yoda).isInstanceOf(Jedi.class)
.isEqualTo(foundJedi)
.isNotEqualTo(foundSith);
```
The 2.x branch is an attempt to learn from mistakes made in the the 1.x release, in terms of readability and extensibility.
FEST's assertions are incredibly easy to write: just type **```assertThat```** followed the actual value and a dot, and any Java
IDE will show you all the assertions available for the type of the object to verify. No more confusion about the
order of the "expected" and "actual" values. Our assertions are very readable as well: they read very close to plain
English, making it easier for non-technical people to read test code.
For more details please visit :
* **[FEST-Assert's wiki](https://github.com/alexruiz/fest-assert-2.x/wiki)** for the most up to date documentation.
Many thanks to Cloudbees for their FOSS program that allows FEST to have a **[Jenkins CI server](https://fest.ci.cloudbees.com/#)**!

fest-assert-2.0M10/pom.xml 0000664 0000000 0000000 00000004057 12430205632 0015411 0 ustar 00root root 0000000 0000000
4.0.0
fest-assert-core
2.0M10
FEST Fluent Assertions (Core)
'Flexible' or 'fluent' assertions for testing
2007
http://fest.easytesting.org/assert
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-assert-2.x.git
scm:git:git://github.com/alexruiz/fest-assert-2.x.git
https://github.com/alexruiz/fest-assert-2.x
github
https://github.com/alexruiz/fest-assert-2.x/issues
org.easytesting
fest-util
1.2.5
compile
org.easytesting
fest-test
2.1.0
test
org.mockito
mockito-all
1.9.0
test
junit
junit
test
fest-assert-2.0M10/release-notes.txt 0000664 0000000 0000000 00000015217 12430205632 0017403 0 ustar 00root root 0000000 0000000 For the next release
--------------------
next version release notes (WIP)
-------------------
2.0M9 release notes
-------------------
bugfix release,
fix incompatibility with fest-reflect, you can use 2.0M9 along with fest-reflect 1.4.1 both depending on fest-util 1.2.4
github #138 : containsExactly() throws ArrayIndexOutOfBoundsException
github #131 : ObjectArrayAssert.containsExactly() works wrong
2.0M8 release notes
-------------------
Breaking changes :
Remove dependency on AWT : AWT assertions moved to a new module
Use java 6 instead of java 5
New features :
github#79 : String assertions are available on (small) file by calling contentOf(File) method (Olivier Michallat)
github#73 : new assertion ListAssert.has(Condition, Index) (Bo Gotthardt)
github#97 : new assertion ListAssert.is(Condition, Index) (Bo Gotthardt)
github#50 : new assertion StringAssert.containsOnlyOnce (Pauline Iogna)
Improvement :
github#87 : Fail.failBecauseExpectedExceptionWasNotThrown now takes a Throwable instead of an Exception
github#86 : tests : org.fest.assertions.internal contain too much classes
github#82 : tests : org.fest.assertions.api contain too much classes (Olivier Michallat)
github#91 : tests : move fail tests in a "fail" subpackage
github#106 : provide better extensibility by exposing assertion WritableAssertionInfo
github#74 : ObjectAssert lenient equals assertions now takes inherited fields into account
Bug :
github#92 : Fix BinaryDiff_diff_File_byteArray_Test test that was failing on windows
github#104 : containsExactly does not work with SortedSet
Refactoring
Move creation of ArrayLists into a Lists class
Move creation of Sets to Sets class
Move Iterable-related methods out of the Collections
Iterables : Rename 'isEmpty' to 'isNullOrEmpty'
Move back factory of primitive arrays from fest-util back to fest-assert
2.0M7 release notes
-------------------
New features :
github#43 : New File assertion : hasContent(String content) and hasBinaryContent(byte[] expected) (Olivier Michallat)
github#48 : Add hasTime assertion to DateAssert (Nicolas Francois and Guillaume Girou)
github#71 : New File assertions : canRead(), canWrite() (Olivier Demeijer)
Improvement :
github#12 : overridingErrorMessage should be ported in 2.0
github#54 : ObjectArrayAssert methods should use T parameter instead of Object
github#70 : Properties.from should use Iterable (Florent Biville)
github#73 : Maven build should assure that we build a java 5 compatible version
github#58 : Properties: add ofType() method to improve API fluency
Bug :
github#75 : ShouldHaveEqualContent unexpected MissingFormatArgumentException.
github#85 : ShouldHaveTime_create_Test test fails because of time zone dependency.
2.0M6 release notes
-------------------
New features :
github#29 : MapAssert should have containsKey(), containsValue() and counterparts (Nicolas Francois)
github#31 : Move isInstanceOf and friends to AbstractAssert (Nicolas Francois)
github#32 : add class related assertions : hasSameClassAs, doesNotHaveSameClassAs, isExactlyInstanceOf, isOfAnyClassIn and counterparts (Nicolas Francois)
github#35 : Port containsExactly to Fest 2.0 (was in Fest 1.x) (Nicolas Francois)
github#42 : Move hasSameSize to EnumerableAssert to make it available in *ArrayAssert (Nicolas Francois)
Improvement :
github#52 : Remove final on methods to provide better extensibility (FEST-475)
github#56 : Date assert error message improvement
Bug :
Fix some error compilation only occuring with oracle jdk 1.7.0_05, error being having two static import with same name.
github#56 : containsOnly does not handle null elements
2.0M5 release notes
-------------------
New features :
- github#34 : Add generic type to MapAssert (Nicolas Francois)
- github#22 : add base assertion isEqualsToByComparingFields (Nicolas Francois)
- github#23 : Filters now support null value (Joel Costigliola)
- FEST-358 : New numbers assertions : isNotPositive / isNotNegative (Nicolas Francois)
- FEST-476 : Improve error message when comparing numbers with offset (Joel Costigliola)
Improvement :
- github#22 : Use multiline error message to ease comparing actual and expected (Joel Costigliola)
- Make assertions more type safe (work in progress) (Mikhail Mazursky)
Bug :
- github#26 : fix Lenient Equals By Ignoring Fields (Nicolas Francois)
2.0M4 release notes
-------------------
- Improve type safety (Mikhail Mazursky)
- Refactor custom comparators : introducing customElementComparator for group assertions (Mikhail Mazursky)
- github#20 : new group assertions : containsAll(Iterable) (Joel Costigliola)
- github#16 : new BigDecimalAssert assertions : isEqualTo(String) and isEqualByComparingTo(String) (Joel Costigliola)
2.0M3 release notes
-------------------
- FEST-404 : Filter API on iterable/array
- FEST-470 : Lenient Equals (allows specifying on which properties equality should be performed)
- FEST-447 : Increase ComparableAssert API flexibility
- FEST-478 : Add support for parametrized types in AbstractAssert
- FEST-221 : Array and Iterable new assertion : hasSameSizeAs
- FEST-481 : isIn() and isNotIn() assertions should take Iterable> instead of Collection>
- github#17 : DateAssert isNotBetween error message must be improved
- github#13 : Improve error messages
2.0M2 release notes
-------------------
- github#9 : Allow custom assertions to have access to their description using descriptionText()
2.0M1 release notes
-------------------
- Date assertions : 28 assertions !
- Using a custom comparator instead of equals() to compare objects in assertions
- Assertions class now exposes all assertions related API : assertThat, fail API, entry for Map assertions and anyOf condition
- Richer conditions : has, are, areAtLeast, areAtMost, ...
- OR assertions with anyOf conditions
- isEqualTo assertion error message improvement
- Iterable assertions
- InputStream assertions
- 3 new exception assertions : hasMessageStartingWith, hasMessageContaining, hasMessageEndingWith
- When an assertion fails, the exception stack is filtered to avoidshowing fest stack trace elements
- New List and array assertion : isSorted
- isGreaterThan, isLessThan, isGreaterThanOrEqualTo and isLessThanOrEqualTo work now with primitive wrappers
- Fail API : fail() method removed
- Fail API learned failBecauseExceptionWasNotThrown(exception class)
- New collection/array assertions : containsNull, doesNotContainNull
- New collection assertions : isSubsetOf
Jira release note :
http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=11920&version=18363
1.4 -> 2.0 Migration guide
--------------------------
Migration steps are detailed in Fest Assertions github wiki :
https://github.com/alexruiz/fest-assert-2.x/wiki/Migrating-from-fest-assert-1.4
fest-assert-2.0M10/src/ 0000775 0000000 0000000 00000000000 12430205632 0014655 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/formatters/ 0000775 0000000 0000000 00000000000 12430205632 0017043 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/formatters/fest-eclipse-formatter.xml 0000664 0000000 0000000 00000074315 12430205632 0024163 0 ustar 00root root 0000000 0000000
fest-assert-2.0M10/src/formatters/fest-idea-formatter.xml 0000664 0000000 0000000 00000003130 12430205632 0023424 0 ustar 00root root 0000000 0000000
fest-assert-2.0M10/src/formatters/intellij-codestyle.jar 0000664 0000000 0000000 00000002763 12430205632 0023354 0 ustar 00root root 0000000 0000000 PK
ӽ@
templates/PK
ӽ@ fileTemplates/PK
ӽ@ fileTemplates/internal/PK
ӽ@ fileTemplates/j2ee/PK
ӽ@ fileTemplates/code/PK
ӽ@ fileTemplates/includes/PK
`@ codestyles/PK ǰ@ # codestyles/FEST.xmlUM0W [Zd@&b]7DH!6RR{of0C@W/~Wowz9LDW^] $Z8|k؆\W)Jr2*4XV'}~
~uy
y;;dT-rAߌB%^MU)6=\cC |)ʼns"D + >0FBD1ČobM3`!T
SdO!{"0zc/Y(YrQ`1&kIJ{sH(R+±#)Bvs\a ")+TeR}87B5̲cӸ.|c1@}ʈ + o i>DC-QwWDB79G*ܶu
F.䚙iSBomcM@&i{]7+B`ó9hv'PK
ذ@ IntelliJ IDEA Global SettingsPK
ӽ@
templates/PK
ӽ@ ( fileTemplates/PK
ӽ@ T fileTemplates/internal/PK
ӽ@ fileTemplates/j2ee/PK
ӽ@ fileTemplates/code/PK
ӽ@ fileTemplates/includes/PK
`@ codestyles/PK ǰ@ # I codestyles/FEST.xmlPK
ذ@ ] IntelliJ IDEA Global SettingsPK E fest-assert-2.0M10/src/main/ 0000775 0000000 0000000 00000000000 12430205632 0015601 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/ 0000775 0000000 0000000 00000000000 12430205632 0016522 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/ 0000775 0000000 0000000 00000000000 12430205632 0017311 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/ 0000775 0000000 0000000 00000000000 12430205632 0020252 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/assertions/ 0000775 0000000 0000000 00000000000 12430205632 0022444 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ 0000775 0000000 0000000 00000000000 12430205632 0023215 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/assertions/api/AbstractAssert.java 0000664 0000000 0000000 00000021420 12430205632 0027004 0 ustar 00root root 0000000 0000000 /*
* Created on Nov 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-2011 the original author or authors.
*/
package org.fest.assertions.api;
import static java.lang.String.format;
import java.util.Comparator;
import org.fest.assertions.core.Assert;
import org.fest.assertions.core.Condition;
import org.fest.assertions.core.WritableAssertionInfo;
import org.fest.assertions.description.Description;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Base class for all assertions.
*
* @param the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation "
* for more details.
* @param the type of the "actual" value.
*
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public abstract class AbstractAssert, A> implements Assert {
@VisibleForTesting
Objects objects = Objects.instance();
@VisibleForTesting
Conditions conditions = Conditions.instance();
@VisibleForTesting
final WritableAssertionInfo info;
// visibility is protected to allow us write custom assertions that need access to actual
@VisibleForTesting
protected final A actual;
protected final S myself;
// we prefer not to use Class extends S> selfType because it would force inherited
// constructor to cast with a compiler warning
// let's keep compiler warning internal to fest (when we can) and not expose them to our end users.
@SuppressWarnings("unchecked")
protected AbstractAssert(A actual, Class> selfType) {
myself = (S) selfType.cast(this);
this.actual = actual;
info = new WritableAssertionInfo();
}
/**
* Exposes the {@link WritableAssertionInfo} used in the current assertion for better extensibility. When writing
* your own assertion class, you can use the returned {@link WritableAssertionInfo} to change the error message and
* still keep the description set by the assertion user.
*
* @return the {@link WritableAssertionInfo} used in the current assertion
*/
protected WritableAssertionInfo getWritableAssertionInfo() {
return info;
}
/** {@inheritDoc} */
public S as(String description) {
return describedAs(description);
}
/** {@inheritDoc} */
public S as(Description description) {
return describedAs(description);
}
/** {@inheritDoc} */
public S describedAs(String description) {
info.description(description);
return myself;
}
/** {@inheritDoc} */
public S describedAs(Description description) {
info.description(description);
return myself;
}
/** {@inheritDoc} */
public S isEqualTo(A expected) {
objects.assertEqual(info, actual, expected);
return myself;
}
/** {@inheritDoc} */
public S isNotEqualTo(A other) {
objects.assertNotEqual(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public void isNull() {
objects.assertNull(info, actual);
}
/** {@inheritDoc} */
public S isNotNull() {
objects.assertNotNull(info, actual);
return myself;
}
/** {@inheritDoc} */
public S isSameAs(A expected) {
objects.assertSame(info, actual, expected);
return myself;
}
/** {@inheritDoc} */
public S isNotSameAs(A other) {
objects.assertNotSame(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S isIn(A... values) {
objects.assertIsIn(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S isNotIn(A... values) {
objects.assertIsNotIn(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S isIn(Iterable extends A> values) {
objects.assertIsIn(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S isNotIn(Iterable extends A> values) {
objects.assertIsNotIn(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S is(Condition super A> condition) {
conditions.assertIs(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S isNot(Condition super A> condition) {
conditions.assertIsNot(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S has(Condition super A> condition) {
conditions.assertHas(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S doesNotHave(Condition super A> condition) {
conditions.assertDoesNotHave(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S isInstanceOf(Class> type) {
objects.assertIsInstanceOf(info, actual, type);
return myself;
}
/** {@inheritDoc} */
public S isInstanceOfAny(Class>... types) {
objects.assertIsInstanceOfAny(info, actual, types);
return myself;
}
/** {@inheritDoc} */
public S isNotInstanceOf(Class> type) {
objects.assertIsNotInstanceOf(info, actual, type);
return myself;
}
/** {@inheritDoc} */
public S isNotInstanceOfAny(Class>... types) {
objects.assertIsNotInstanceOfAny(info, actual, types);
return myself;
}
/** {@inheritDoc} */
public S hasSameClassAs(Object other) {
objects.assertHasSameClassAs(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S doesNotHaveSameClassAs(Object other) {
objects.assertDoesNotHaveSameClassAs(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S isExactlyInstanceOf(Class> type) {
objects.assertIsExactlyInstanceOf(info, actual, type);
return myself;
}
/** {@inheritDoc} */
public S isNotExactlyInstanceOf(Class> type) {
objects.assertIsNotExactlyInstanceOf(info, actual, type);
return myself;
}
/** {@inheritDoc} */
public S isOfAnyClassIn(Class>... types) {
objects.assertIsOfAnyClassIn(info, actual, types);
return myself;
}
/** {@inheritDoc} */
public S isNotOfAnyClassIn(Class>... types) {
objects.assertIsNotOfAnyClassIn(info, actual, types);
return myself;
}
/**
* The description of this assertion set with {@link #describedAs(String)} or {@link #describedAs(Description)}.
*
* @return the description String representation of this assertion.
*/
public String descriptionText() {
return info.descriptionText();
}
/**
* Overrides Fest default error message by the given one, the new error message can be built using
* {@link String#format(String, Object...)}, hence the presence of args parameter.
*
* Example :
*
*
* assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player)
* .isTrue();
*
*
* @param newErrorMessage the error message that will replace the default one provided by Fest.
* @param args the args used to fill error message as in {@link String#format(String, Object...)}.
* @return this assertion object.
* @throws exception see {@link String#format(String, Object...)} exception clause.
*/
public S overridingErrorMessage(String newErrorMessage, Object... args) {
info.overridingErrorMessage(format(newErrorMessage, args));
return myself;
}
/** {@inheritDoc} */
public S usingComparator(Comparator super A> customComparator) {
// using a specific strategy to compare actual with other objects.
this.objects = new Objects(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public S usingDefaultComparator() {
// fall back to default strategy to compare actual with other objects.
this.objects = Objects.instance();
return myself;
}
/** {@inheritDoc} */
@Override
public final boolean equals(Object obj) {
throw new UnsupportedOperationException("'equals' is not supported...maybe you intended to call 'isEqualTo'");
}
/**
* Always returns 1.
*
* @return 1.
*/
@Override
public final int hashCode() {
return 1;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/AbstractComparableAssert.java 0000664 0000000 0000000 00000005210 12430205632 0030771 0 ustar 00root root 0000000 0000000 /*
* Created on Nov 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-2011 the original author or authors.
*/
package org.fest.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ComparableAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Base class for all implementations of {@link ComparableAssert}
.
* @param the "self" type of this assertion class. Please read "Emulating
* 'self types' using Java Generics to simplify fluent API implementation " for more details.
* @param the type of the "actual" value.
*
* @author Alex Ruiz
* @author Mikhail Mazursky
*/
public abstract class AbstractComparableAssert, A extends Comparable super A>> extends
AbstractAssert implements ComparableAssert {
@VisibleForTesting
Comparables comparables = Comparables.instance();
protected AbstractComparableAssert(A actual, Class> selfType) {
super(actual, selfType);
}
/** {@inheritDoc} */
public S isLessThan(A other) {
comparables.assertLessThan(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S isLessThanOrEqualTo(A other) {
comparables.assertLessThanOrEqualTo(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S isGreaterThan(A other) {
comparables.assertGreaterThan(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S isGreaterThanOrEqualTo(A other) {
comparables.assertGreaterThanOrEqualTo(info, actual, other);
return myself;
}
@Override
public S usingComparator(Comparator super A> customComparator) {
super.usingComparator(customComparator);
this.comparables = new Comparables(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public S usingDefaultComparator() {
super.usingDefaultComparator();
this.comparables = Comparables.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/AbstractIterableAssert.java 0000664 0000000 0000000 00000017551 12430205632 0030466 0 ustar 00root root 0000000 0000000 /*
* Created on Nov 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-2011 the original author or authors.
*/
package org.fest.assertions.api;
import java.util.Collection;
import java.util.Comparator;
import org.fest.assertions.core.Condition;
import org.fest.assertions.core.ObjectEnumerableAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Base class for implementations of {@link ObjectEnumerableAssert}
whose actual value type is
* {@link Collection}
.
* @param the "self" type of this assertion class. Please read "Emulating
* 'self types' using Java Generics to simplify fluent API implementation " for more details.
* @param the type of the "actual" value.
* @param the type of elements of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Mathieu Baechler
* @author Joel Costigliola
* @author Maciej Jaskowski
* @author Nicolas François
* @author Mikhail Mazursky
*/
public abstract class AbstractIterableAssert, A extends Iterable, T> extends
AbstractAssert implements ObjectEnumerableAssert {
@VisibleForTesting
Iterables iterables = Iterables.instance();
protected AbstractIterableAssert(A actual, Class> selfType) {
super(actual, selfType);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
iterables.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
iterables.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public S isNotEmpty() {
iterables.assertNotEmpty(info, actual);
return myself;
}
/** {@inheritDoc} */
public S hasSize(int expected) {
iterables.assertHasSize(info, actual, expected);
return myself;
}
/** {@inheritDoc} */
public S hasSameSizeAs(Object[] other) {
iterables.assertHasSameSizeAs(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S hasSameSizeAs(Iterable> other) {
iterables.assertHasSameSizeAs(info, actual, other);
return myself;
}
/** {@inheritDoc} */
public S contains(T... values) {
iterables.assertContains(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S containsOnly(T... values) {
iterables.assertContainsOnly(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S containsExactly(T... values) {
iterables.assertContainsExactly(info, actual, values);
return myself;
}
/**
* Verifies that all the elements of the actual {@code Iterable} are present in the given {@code Iterable}.
* @param values the {@code Iterable} that should contain all actual elements.
* @return this assertion object.
* @throws AssertionError if the actual {@code Iterable} is {@code null}.
* @throws NullPointerException if the given {@code Iterable} is {@code null}.
* @throws AssertionError if the actual {@code Iterable} is not subset of set {@code Iterable}.
*/
public S isSubsetOf(Iterable extends T> values) {
iterables.assertIsSubsetOf(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S containsSequence(T... sequence) {
iterables.assertContainsSequence(info, actual, sequence);
return myself;
}
/** {@inheritDoc} */
public S doesNotContain(T... values) {
iterables.assertDoesNotContain(info, actual, values);
return myself;
}
/** {@inheritDoc} */
public S doesNotHaveDuplicates() {
iterables.assertDoesNotHaveDuplicates(info, actual);
return myself;
}
/** {@inheritDoc} */
public S startsWith(T... sequence) {
iterables.assertStartsWith(info, actual, sequence);
return myself;
}
/** {@inheritDoc} */
public S endsWith(T... sequence) {
iterables.assertEndsWith(info, actual, sequence);
return myself;
}
/** {@inheritDoc} */
public S containsNull() {
iterables.assertContainsNull(info, actual);
return myself;
}
/** {@inheritDoc} */
public S doesNotContainNull() {
iterables.assertDoesNotContainNull(info, actual);
return myself;
}
/** {@inheritDoc} */
public S are(Condition super T> condition) {
iterables.assertAre(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S areNot(Condition super T> condition) {
iterables.assertAreNot(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S have(Condition super T> condition) {
iterables.assertHave(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S doNotHave(Condition super T> condition) {
iterables.assertDoNotHave(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public S areAtLeast(int times, Condition super T> condition) {
iterables.assertAreAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S areNotAtLeast(int times, Condition super T> condition) {
iterables.assertAreNotAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S areAtMost(int times, Condition super T> condition) {
iterables.assertAreAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S areNotAtMost(int times, Condition super T> condition) {
iterables.assertAreNotAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S areExactly(int times, Condition super T> condition) {
iterables.assertAreExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S areNotExactly(int times, Condition super T> condition) {
iterables.assertAreNotExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S haveAtLeast(int times, Condition super T> condition) {
iterables.assertHaveAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S doNotHaveAtLeast(int times, Condition super T> condition) {
iterables.assertDoNotHaveAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S haveAtMost(int times, Condition super T> condition) {
iterables.assertHaveAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S doNotHaveAtMost(int times, Condition super T> condition) {
iterables.assertDoNotHaveAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S haveExactly(int times, Condition super T> condition) {
iterables.assertHaveExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S doNotHaveExactly(int times, Condition super T> condition) {
iterables.assertDoNotHaveExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public S containsAll(Iterable extends T> iterable) {
iterables.assertContainsAll(info, actual, iterable);
return myself;
}
/** {@inheritDoc} */
public S usingElementComparator(Comparator super T> customComparator) {
this.iterables = new Iterables(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public S usingDefaultElementComparator() {
this.iterables = Iterables.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/AbstractUnevenComparableAssert.java 0000664 0000000 0000000 00000003474 12430205632 0032164 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 8, 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.assertions.api;
import org.fest.assertions.core.UnevenComparableAssert;
/**
* Base class for all implementations of {@link UnevenComparableAssert}
.
* @param the "self" type of this assertion class. Please read "Emulating
* 'self types' using Java Generics to simplify fluent API implementation " for more details.
* @param the type of the "actual" value.
*
* @author Alex Ruiz
* @author Mikhail Mazursky
*/
public abstract class AbstractUnevenComparableAssert, A extends Comparable super A>>
extends AbstractComparableAssert implements UnevenComparableAssert {
protected AbstractUnevenComparableAssert(A actual, Class> selfType) {
super(actual, selfType);
}
/** {@inheritDoc} */
public S isEqualByComparingTo(A expected) {
comparables.assertEqualByComparison(info, actual, expected);
return myself;
}
/** {@inheritDoc} */
public S isNotEqualByComparingTo(A other) {
comparables.assertNotEqualByComparison(info, actual, other);
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/Assertions.java 0000664 0000000 0000000 00000061765 12430205632 0026231 0 ustar 00root root 0000000 0000000 /*
* Created on Sep 30, 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.assertions.api;
import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.fest.assertions.api.filter.Filters;
import org.fest.assertions.condition.AllOf;
import org.fest.assertions.condition.AnyOf;
import org.fest.assertions.condition.DoesNotHave;
import org.fest.assertions.condition.Not;
import org.fest.assertions.core.Condition;
import org.fest.assertions.data.Index;
import org.fest.assertions.data.MapEntry;
import org.fest.assertions.data.Offset;
import org.fest.assertions.groups.Properties;
import org.fest.util.Files;
import org.fest.util.FilesException;
/**
* Entry point for assertion methods for different data types. Each method in this class is a static factory for the type-specific
* assertion objects. The purpose of this class is to make test code more readable.
*
* For example:
*
*
* int removed = employees.removeFired();
* {@link Assertions#assertThat(int) assertThat}(removed).{@link IntegerAssert#isZero isZero}();
*
* List<Employee> newEmployees = employees.hired(TODAY);
* {@link Assertions#assertThat(Iterable) assertThat}(newEmployees).{@link IterableAssert#hasSize(int) hasSize}(6);
*
*
*
* @author Alex Ruiz
* @author Yvonne Wang
* @author David DIDIER
* @author Ted Young
* @author Joel Costigliola
* @author Matthieu Baechler
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class Assertions {
/**
* Creates a new instance of {@link BigDecimalAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static BigDecimalAssert assertThat(BigDecimal actual) {
return new BigDecimalAssert(actual);
}
/**
* Creates a new instance of {@link BooleanAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static BooleanAssert assertThat(boolean actual) {
return new BooleanAssert(actual);
}
/**
* Creates a new instance of {@link BooleanAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static BooleanAssert assertThat(Boolean actual) {
return new BooleanAssert(actual);
}
/**
* Creates a new instance of {@link BooleanArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static BooleanArrayAssert assertThat(boolean[] actual) {
return new BooleanArrayAssert(actual);
}
/**
* Creates a new instance of {@link ByteAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ByteAssert assertThat(byte actual) {
return new ByteAssert(actual);
}
/**
* Creates a new instance of {@link ByteAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ByteAssert assertThat(Byte actual) {
return new ByteAssert(actual);
}
/**
* Creates a new instance of {@link ByteArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ByteArrayAssert assertThat(byte[] actual) {
return new ByteArrayAssert(actual);
}
/**
* Creates a new instance of {@link CharacterAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static CharacterAssert assertThat(char actual) {
return new CharacterAssert(actual);
}
/**
* Creates a new instance of {@link CharArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static CharArrayAssert assertThat(char[] actual) {
return new CharArrayAssert(actual);
}
/**
* Creates a new instance of {@link CharacterAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static CharacterAssert assertThat(Character actual) {
return new CharacterAssert(actual);
}
/**
* Creates a new instance of {@link IterableAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static IterableAssert assertThat(Iterable actual) {
return new IterableAssert(actual);
}
/**
* Creates a new instance of {@link DoubleAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static DoubleAssert assertThat(double actual) {
return new DoubleAssert(actual);
}
/**
* Creates a new instance of {@link DoubleAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static DoubleAssert assertThat(Double actual) {
return new DoubleAssert(actual);
}
/**
* Creates a new instance of {@link DoubleArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static DoubleArrayAssert assertThat(double[] actual) {
return new DoubleArrayAssert(actual);
}
/**
* Creates a new instance of {@link FileAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static FileAssert assertThat(File actual) {
return new FileAssert(actual);
}
/**
* Creates a new instance of {@link InputStreamAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static InputStreamAssert assertThat(InputStream actual) {
return new InputStreamAssert(actual);
}
/**
* Creates a new instance of {@link FloatAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static FloatAssert assertThat(float actual) {
return new FloatAssert(actual);
}
/**
* Creates a new instance of {@link FloatAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static FloatAssert assertThat(Float actual) {
return new FloatAssert(actual);
}
/**
* Creates a new instance of {@link FloatArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static FloatArrayAssert assertThat(float[] actual) {
return new FloatArrayAssert(actual);
}
/**
* Creates a new instance of {@link IntegerAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static IntegerAssert assertThat(int actual) {
return new IntegerAssert(actual);
}
/**
* Creates a new instance of {@link IntArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static IntArrayAssert assertThat(int[] actual) {
return new IntArrayAssert(actual);
}
/**
* Creates a new instance of {@link IntegerAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static IntegerAssert assertThat(Integer actual) {
return new IntegerAssert(actual);
}
/**
* Creates a new instance of {@link ListAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ListAssert assertThat(List actual) {
return new ListAssert(actual);
}
/**
* Creates a new instance of {@link LongAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static LongAssert assertThat(long actual) {
return new LongAssert(actual);
}
/**
* Creates a new instance of {@link LongAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static LongAssert assertThat(Long actual) {
return new LongAssert(actual);
}
/**
* Creates a new instance of {@link LongArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static LongArrayAssert assertThat(long[] actual) {
return new LongArrayAssert(actual);
}
/**
* Creates a new instance of {@link ObjectAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ObjectAssert assertThat(T actual) {
return new ObjectAssert(actual);
}
/**
* Creates a new instance of {@link ObjectArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ObjectArrayAssert assertThat(T[] actual) {
return new ObjectArrayAssert(actual);
}
/**
* Creates a new instance of {@link MapAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static MapAssert assertThat(Map actual) {
return new MapAssert(actual);
}
/**
* Creates a new instance of {@link ShortAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ShortAssert assertThat(short actual) {
return new ShortAssert(actual);
}
/**
* Creates a new instance of {@link ShortAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ShortAssert assertThat(Short actual) {
return new ShortAssert(actual);
}
/**
* Creates a new instance of {@link ShortArrayAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static ShortArrayAssert assertThat(short[] actual) {
return new ShortArrayAssert(actual);
}
/**
* Creates a new instance of {@link StringAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static StringAssert assertThat(String actual) {
return new StringAssert(actual);
}
/**
* Creates a new instance of {@link DateAssert}
.
* @param actual the actual value.
* @return the created assertion object.
*/
public static DateAssert assertThat(Date actual) {
return new DateAssert(actual);
}
/**
* Creates a new instance of {@link ThrowableAssert}
.
* @param actual the actual value.
* @return the created assertion Throwable.
*/
public static ThrowableAssert assertThat(Throwable actual) {
return new ThrowableAssert(actual);
}
// -------------------------------------------------------------------------------------------------
// fail methods : not assertions but here to have a single entry point to all Fest Assert features.
// -------------------------------------------------------------------------------------------------
/**
* Only delegate to {@link Fail#setRemoveFestRelatedElementsFromStackTrace(boolean)} so that Assertions offers a full feature
* entry point to all Fest Assert features (but you can use {@link Fail} if you prefer).
*/
public static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace) {
Fail.setRemoveFestRelatedElementsFromStackTrace(removeFestRelatedElementsFromStackTrace);
}
/**
* Only delegate to {@link Fail#fail(String)} so that Assertions offers a full feature entry point to all Fest Assert features
* (but you can use Fail if you prefer).
*/
public static void fail(String failureMessage) {
Fail.fail(failureMessage);
}
/**
* Only delegate to {@link Fail#fail(String, Throwable)} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use Fail if you prefer).
*/
public static void fail(String failureMessage, Throwable realCause) {
Fail.fail(failureMessage, realCause);
}
/**
* Only delegate to {@link Fail#failBecauseExceptionWasNotThrown(Class)} so that Assertions offers a full feature entry point to
* all Fest Assert features (but you can use Fail if you prefer).
*/
public static void failBecauseExceptionWasNotThrown(Class extends Exception> exceptionClass) {
Fail.failBecauseExceptionWasNotThrown(exceptionClass);
}
// ------------------------------------------------------------------------------------------------------
// properties methods : not assertions but here to have a single entry point to all Fest Assert features.
// ------------------------------------------------------------------------------------------------------
/**
* Only delegate to {@link Properties#extractProperty(String)} so that Assertions offers a full feature entry point to all Fest
* Assert features (but you can use {@link Properties} if you prefer).
*
* Typical usage is to chain extractProperty
with from
method, see examples below :
*
*
* // extract simple property values having a java standard type (here String)
* assertThat(extractProperty("name", String.class).from(fellowshipOfTheRing))
* .contains("Boromir", "Gandalf", "Frodo", "Legolas")
* .doesNotContain("Sauron", "Elrond");
*
* // extracting property works also with user's types (here Race)
* assertThat(extractProperty("race", String.class).from(fellowshipOfTheRing))
* .contains(HOBBIT, ELF)
* .doesNotContain(ORC);
*
* // extract nested property on Race
* assertThat(extractProperty("race.name", String.class).from(fellowshipOfTheRing))
* .contains("Hobbit", "Elf")
* .doesNotContain("Orc");
*
*/
public static Properties extractProperty(String propertyName, Class propertyType) {
return Properties.extractProperty(propertyName, propertyType);
}
/**
* Only delegate to {@link Properties#extractProperty(String)} so that Assertions offers a full feature entry point to all Fest
* Assert features (but you can use {@link Properties} if you prefer).
*
* Typical usage is to chain extractProperty
with from
method, see examples below :
*
*
* // extract simple property values, as no type has been defined the extracted property will be considered as Object
* // to define the real property type (here String) use extractProperty("name", String.class) instead.
* assertThat(extractProperty("name").from(fellowshipOfTheRing))
* .contains("Boromir", "Gandalf", "Frodo", "Legolas")
* .doesNotContain("Sauron", "Elrond");
*
* // extracting property works also with user's types (here Race), even though it will be considered as Object
* // to define the real property type (here String) use extractProperty("name", Race.class) instead.
* assertThat(extractProperty("race").from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC);
*
* // extract nested property on Race
* assertThat(extractProperty("race.name").from(fellowshipOfTheRing)).contains("Hobbit", "Elf").doesNotContain("Orc");
*
*/
public static Properties extractProperty(String propertyName) {
return Properties.extractProperty(propertyName);
}
// ------------------------------------------------------------------------------------------------------
// Data utility methods : not assertions but here to have a single entry point to all Fest Assert features.
// ------------------------------------------------------------------------------------------------------
/**
* Only delegate to {@link MapEntry#entry(Object, Object)} so that Assertions offers a full feature entry point to all Fest
* Assert features (but you can use {@link MapEntry} if you prefer).
*
* Typical usage is to call entry
in MapAssert contains
assertion, see examples below :
*
*
* assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
*
*/
public static MapEntry entry(Object key, Object value) {
return MapEntry.entry(key, value);
}
/**
* Only delegate to {@link Index#atIndex(int)} so that Assertions offers a full feature entry point to all Fest Assert features
* (but you can use {@link Index} if you prefer).
*
* Typical usage :
*
*
* List elvesRings = newArrayList(vilya, nenya, narya);
* assertThat(elvesRings).contains(vilya, atIndex(0)).contains(nenya, atIndex(1)).contains(narya, atIndex(2));
*
*/
public static Index atIndex(int index) {
return Index.atIndex(index);
}
/**
* Only delegate to {@link Offset#offset(Double)} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use {@link Offset} if you prefer).
*
* Typical usage :
*
*
* assertThat(8.1).isEqualTo(8.0, offset(0.1));
*
*/
public static Offset offset(Double value) {
return Offset.offset(value);
}
/**
* Only delegate to {@link Offset#offset(Float)} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use {@link Offset} if you prefer).
*
* Typical usage :
*
*
* assertThat(8.2f).isEqualTo(8.0f, offset(0.2f));
*
*/
public static Offset offset(Float value) {
return Offset.offset(value);
}
// ------------------------------------------------------------------------------------------------------
// Condition methods : not assertions but here to have a single entry point to all Fest Assert features.
// ------------------------------------------------------------------------------------------------------
/**
* Creates a new {@link AllOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given array is {@code null}.
* @throws NullPointerException if any of the elements in the given array is {@code null}.
*/
public static Condition allOf(Condition super T>... conditions) {
return AllOf.allOf(conditions);
}
/**
* Creates a new {@link AllOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given iterable is {@code null}.
* @throws NullPointerException if any of the elements in the given iterable is {@code null}.
*/
public static Condition allOf(Iterable extends Condition super T>> conditions) {
return AllOf.allOf(conditions);
}
/**
* Only delegate to {@link AnyOf#anyOf(Condition...)} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use {@link AnyOf} if you prefer).
*
* Typical usage (jedi
and sith
are {@link Condition}) :
*
*
* assertThat("Vader").is(anyOf(jedi, sith));
*
*/
public static Condition anyOf(Condition super T>... conditions) {
return AnyOf.anyOf(conditions);
}
/**
* Creates a new {@link AnyOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given iterable is {@code null}.
* @throws NullPointerException if any of the elements in the given iterable is {@code null}.
*/
public static Condition anyOf(Iterable extends Condition super T>> conditions) {
return AnyOf.anyOf(conditions);
}
/**
* Creates a new {@link DoesNotHave}.
*
* @param condition the condition to inverse.
* @return The Not condition created.
*/
public static DoesNotHave doesNotHave(Condition super T> condition) {
return DoesNotHave.doesNotHave(condition);
}
/**
* Creates a new {@link Not}.
*
* @param condition the condition to inverse.
* @return The Not condition created.
*/
public static Not not(Condition super T> condition) {
return Not.not(condition);
}
// --------------------------------------------------------------------------------------------------
// Filter methods : not assertions but here to have a single entry point to all Fest Assert features.
// --------------------------------------------------------------------------------------------------
/**
* Only delegate to {@link Filters#filter(Object[])} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use {@link Filters} if you prefer).
*
* Note that the given array is not modified, the filters are performed on an {@link Iterable} copy of the array.
*
* Typical usage with {@link Condition} :
*
*
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
* and with filter language based on java bean property :
*
*
* assertThat(filter(players).with("pointsPerGame").greaterThan(20)
* .and("assistsPerGame").greaterThan(7)
* .get()).containsOnly(james, rose);
*/
public static Filters filter(E[] array) {
return Filters.filter(array);
}
/**
* Only delegate to {@link Filters#filter(Object[])} so that Assertions offers a full feature entry point to all Fest Assert
* features (but you can use {@link Filters} if you prefer).
*
* Note that the given {@link Iterable} is not modified, the filters are performed on a copy.
*
* Typical usage with {@link Condition} :
*
*
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
* and with filter language based on java bean property :
*
*
* assertThat(filter(players).with("pointsPerGame").greaterThan(20)
* .and("assistsPerGame").greaterThan(7)
* .get()).containsOnly(james, rose);
*/
public static Filters filter(Iterable iterableToFilter) {
return Filters.filter(iterableToFilter);
}
// --------------------------------------------------------------------------------------------------
// File methods : not assertions but here to have a single entry point to all Fest Assert features.
// --------------------------------------------------------------------------------------------------
/**
* Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
*
* Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
* {@link #assertThat(File)}.
*
* @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) {
return Files.contentOf(file, charset);
}
/**
* Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
*
* Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
* {@link #assertThat(File)}.
*
* @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) {
return Files.contentOf(file, charsetName);
}
/**
* Loads the text content of a file with the default character set, so that it can be passed to {@link #assertThat(String)}.
*
* Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
* {@link #assertThat(File)}.
*
* @param file the file.
* @return the content of the file.
* @throws FilesException if an I/O exception occurs.
*/
public static String contentOf(File file) {
return Files.contentOf(file, Charset.defaultCharset());
}
/** Creates a new {@link Assertions}. */
protected Assertions() {}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/BigDecimalAssert.java 0000664 0000000 0000000 00000006474 12430205632 0027235 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 8, 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.assertions.api;
import java.math.BigDecimal;
import java.util.Comparator;
import org.fest.assertions.core.NumberAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@link BigDecimal}
s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(BigDecimal)}
.
*
*
* @author David DIDIER
* @author Ted M. Young
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class BigDecimalAssert extends AbstractUnevenComparableAssert implements
NumberAssert {
@VisibleForTesting
BigDecimals bigDecimals = BigDecimals.instance();
protected BigDecimalAssert(BigDecimal actual) {
super(actual, BigDecimalAssert.class);
}
/** {@inheritDoc} */
public BigDecimalAssert isZero() {
bigDecimals.assertIsZero(info, actual);
return myself;
}
/** {@inheritDoc} */
public BigDecimalAssert isNotZero() {
bigDecimals.assertIsNotZero(info, actual);
return myself;
}
/** {@inheritDoc} */
public BigDecimalAssert isPositive() {
bigDecimals.assertIsPositive(info, actual);
return myself;
}
/** {@inheritDoc} */
public BigDecimalAssert isNegative() {
bigDecimals.assertIsNegative(info, actual);
return myself;
}
/** {@inheritDoc} */
public BigDecimalAssert isNotPositive() {
bigDecimals.assertIsNotPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public BigDecimalAssert isNotNegative() {
bigDecimals.assertIsNotNegative(info, actual);
return this;
}
/**
* Same as {@link AbstractAssert#isEqualTo(Object) isEqualTo(BigDecimal)} but takes care of converting given String to
* {@link BigDecimal} for you.
*/
public BigDecimalAssert isEqualTo(String expected) {
return super.isEqualTo(new BigDecimal(expected));
}
/**
* Same as {@link AbstractUnevenComparableAssert#isEqualByComparingTo(Comparable) isEqualByComparingTo(BigDecimal)} but takes
* care of converting given String to {@link BigDecimal} for you.
*/
public BigDecimalAssert isEqualByComparingTo(String expected) {
return super.isEqualByComparingTo(new BigDecimal(expected));
}
@Override
public BigDecimalAssert usingComparator(Comparator super BigDecimal> customComparator) {
super.usingComparator(customComparator);
this.bigDecimals = new BigDecimals(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public BigDecimalAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.bigDecimals = BigDecimals.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/BooleanArrayAssert.java 0000664 0000000 0000000 00000022423 12430205632 0027623 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 14, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.BooleanArrays;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code boolean}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(boolean[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class BooleanArrayAssert extends AbstractAssert implements
EnumerableAssert, ArraySortedAssert {
@VisibleForTesting
BooleanArrays arrays = BooleanArrays.instance();
protected BooleanArrayAssert(boolean[] actual) {
super(actual, BooleanArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public BooleanArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public BooleanArrayAssert contains(boolean... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public BooleanArrayAssert containsOnly(boolean... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public BooleanArrayAssert containsSequence(boolean... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public BooleanArrayAssert contains(boolean value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public BooleanArrayAssert doesNotContain(boolean... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public BooleanArrayAssert doesNotContain(boolean value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public BooleanArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(boolean...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public BooleanArrayAssert startsWith(boolean... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(boolean...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public BooleanArrayAssert endsWith(boolean... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert isSortedAccordingTo(Comparator super Boolean> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public BooleanArrayAssert usingElementComparator(Comparator super Boolean> customComparator) {
throw new UnsupportedOperationException("custom element Comparator is not supported for Boolean array comparison");
}
/** {@inheritDoc} */
public BooleanArrayAssert usingDefaultElementComparator() {
throw new UnsupportedOperationException("custom element Comparator is not supported for Boolean array comparison");
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/BooleanAssert.java 0000664 0000000 0000000 00000006203 12430205632 0026622 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 21, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.internal.Booleans;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for bytes.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Boolean)}
or
* {@link Assertions#assertThat(boolean)}
.
*
*
* @author Alex Ruiz
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Mikhail Mazursky
*/
public class BooleanAssert extends AbstractAssert {
@VisibleForTesting
Booleans booleans = Booleans.instance();
protected BooleanAssert(Boolean actual) {
super(actual, BooleanAssert.class);
}
/**
* Verifies that the actual value is {@code true}.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not {@code true}.
*/
public BooleanAssert isTrue() {
return isEqualTo(true);
}
/**
* Verifies that the actual value is {@code false}.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not {@code false}.
*/
public BooleanAssert isFalse() {
return isEqualTo(false);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public BooleanAssert isEqualTo(boolean expected) {
booleans.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public BooleanAssert isNotEqualTo(boolean other) {
booleans.assertNotEqual(info, actual, other);
return this;
}
@Override
public BooleanAssert usingComparator(Comparator super Boolean> customComparator) {
throw new UnsupportedOperationException("custom Comparator is not supported for Boolean comparison");
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ByteArrayAssert.java 0000664 0000000 0000000 00000022102 12430205632 0027141 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 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-2011 the original author or authors.
*/
package org.fest.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code byte}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(byte[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class ByteArrayAssert extends AbstractAssert implements EnumerableAssert,
ArraySortedAssert {
@VisibleForTesting
ByteArrays arrays = ByteArrays.instance();
protected ByteArrayAssert(byte[] actual) {
super(actual, ByteArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public ByteArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public ByteArrayAssert contains(byte... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public ByteArrayAssert containsOnly(byte... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public ByteArrayAssert containsSequence(byte... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public ByteArrayAssert contains(byte value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public ByteArrayAssert doesNotContain(byte... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public ByteArrayAssert doesNotContain(byte value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public ByteArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(byte...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public ByteArrayAssert startsWith(byte... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(byte...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public ByteArrayAssert endsWith(byte... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert isSortedAccordingTo(Comparator super Byte> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public ByteArrayAssert usingElementComparator(Comparator super Byte> customComparator) {
this.arrays = new ByteArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public ByteArrayAssert usingDefaultElementComparator() {
this.arrays = ByteArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ByteAssert.java 0000664 0000000 0000000 00000012604 12430205632 0026150 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 21, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.NumberAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for bytes.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Byte)}
or
* {@link Assertions#assertThat(byte)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Alex Ruiz
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class ByteAssert extends AbstractComparableAssert implements NumberAssert {
@VisibleForTesting
Bytes bytes = Bytes.instance();
protected ByteAssert(Byte actual) {
super(actual, ByteAssert.class);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public ByteAssert isEqualTo(byte expected) {
bytes.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public ByteAssert isNotEqualTo(byte other) {
bytes.assertNotEqual(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ByteAssert isZero() {
bytes.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteAssert isNotZero() {
bytes.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteAssert isPositive() {
bytes.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteAssert isNegative() {
bytes.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteAssert isNotNegative() {
bytes.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public ByteAssert isNotPositive() {
bytes.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public ByteAssert isLessThan(byte other) {
bytes.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public ByteAssert isLessThanOrEqualTo(byte other) {
bytes.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public ByteAssert isGreaterThan(byte other) {
bytes.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public ByteAssert isGreaterThanOrEqualTo(byte other) {
bytes.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public ByteAssert usingComparator(Comparator super Byte> customComparator) {
super.usingComparator(customComparator);
this.bytes = new Bytes(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public ByteAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.bytes = Bytes.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/CharArrayAssert.java 0000664 0000000 0000000 00000022126 12430205632 0027121 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code char}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(char[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class CharArrayAssert extends AbstractAssert implements
EnumerableAssert, ArraySortedAssert {
@VisibleForTesting
CharArrays arrays = CharArrays.instance();
protected CharArrayAssert(char[] actual) {
super(actual, CharArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public CharArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public CharArrayAssert contains(char... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public CharArrayAssert containsOnly(char... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public CharArrayAssert containsSequence(char... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public CharArrayAssert contains(char value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public CharArrayAssert doesNotContain(char... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public CharArrayAssert doesNotContain(char value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public CharArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(char...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public CharArrayAssert startsWith(char... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(char...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public CharArrayAssert endsWith(char... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert isSortedAccordingTo(Comparator super Character> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public CharArrayAssert usingElementComparator(Comparator super Character> customComparator) {
this.arrays = new CharArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public CharArrayAssert usingDefaultElementComparator() {
this.arrays = CharArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/CharacterAssert.java 0000664 0000000 0000000 00000012704 12430205632 0027142 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 23, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for characters.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Character)}
or
* {@link Assertions#assertThat(char)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class CharacterAssert extends AbstractComparableAssert {
@VisibleForTesting
Characters characters = Characters.instance();
protected CharacterAssert(Character actual) {
super(actual, CharacterAssert.class);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public CharacterAssert isEqualTo(char expected) {
characters.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public CharacterAssert isNotEqualTo(char other) {
characters.assertNotEqual(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public CharacterAssert isLessThan(char other) {
characters.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public CharacterAssert isLessThanOrEqualTo(char other) {
characters.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public CharacterAssert isGreaterThan(char other) {
characters.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public CharacterAssert isGreaterThanOrEqualTo(char other) {
characters.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is a lowercase character.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not a lowercase character.
*/
public CharacterAssert isLowerCase() {
characters.assertLowerCase(info, actual);
return this;
}
/**
* Verifies that the actual value is a uppercase character.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not a uppercase character.
*/
public CharacterAssert isUpperCase() {
characters.assertUpperCase(info, actual);
return this;
}
@Override
public CharacterAssert usingComparator(Comparator super Character> customComparator) {
super.usingComparator(customComparator);
this.characters = new Characters(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public CharacterAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.characters = Characters.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/DateAssert.java 0000664 0000000 0000000 00000126754 12430205632 0026136 0 ustar 00root root 0000000 0000000 package org.fest.assertions.api;
import static org.fest.util.Dates.ISO_DATE_FORMAT;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.fest.assertions.core.Assert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
*
* Assertions for {@code Date}s.
*
* To create a new instance of this class invoke {@link Assertions#assertThat(Date)}
.
*
* Note that assertions with date parameter comes with two flavor, one is obviously a {@link Date} and the other is a String
* representing a Date.
* For the latter, the default format follows ISO 8901 : "yyyy-MM-dd", user can override it with a custom format by calling
* {@link #withDateFormat(DateFormat)}.
* The user custom format will then be used for all next Date assertions (i.e not limited to the current assertion) in the test
* suite.
* To turn back to default format, simply call {@link #withIsoDateFormat()}.
*
* @author Tomasz Nurkiewicz (thanks for giving assertions idea)
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class DateAssert extends AbstractAssert {
@VisibleForTesting
Dates dates = Dates.instance();
/**
* Used in String based Date assertions - like {@link #isAfter(String)} - to convert input date represented as string to Date.
* The format used can be overriden by invoking {@link #withDateFormat(DateFormat)}
*/
@VisibleForTesting
static DateFormat dateFormat = ISO_DATE_FORMAT;
/**
* Creates a new {@link DateAssert}.
* @param actual the target to verify.
*/
protected DateAssert(Date actual) {
super(actual, DateAssert.class);
}
/**
* Same assertion as {@link AbstractAssert#isEqualTo(Object) isEqualTo(Date date)} but given Date is represented as String
* either with ISO date format (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual and given Date represented as String are not equal.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isEqualTo(String dateAsString) {
return isEqualTo(parse(dateAsString));
}
/**
* Same assertion as {@link AbstractAssert#isNotEqualTo(Object) isNotEqualTo(Date date)} but given Date is represented as String
* either with ISO date format (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual and given Date represented as String are equal.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isNotEqualTo(String dateAsString) {
return isNotEqualTo(parse(dateAsString));
}
/**
* Same assertion as {@link Assert#isIn(Object...)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param datesAsString the given Dates represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual is not in given Dates represented as String.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isIn(String... datesAsString) {
Date[] dates = new Date[datesAsString.length];
for (int i = 0; i < datesAsString.length; i++) {
dates[i] = parse(datesAsString[i]);
}
return isIn(dates);
}
/**
* Same assertion as {@link Assert#isIn(Iterable)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* Method signature could not be isIn(Collection<String>)
because it would be same signature as
* isIn(Collection<Date>)
since java collection type are erased at runtime.
* @param datesAsString the given Dates represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual is not in given Dates represented as String.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isInWithStringDateCollection(Collection datesAsString) {
Collection dates = new ArrayList(datesAsString.size());
for (String dateAsString : datesAsString) {
dates.add(parse(dateAsString));
}
return isIn(dates);
}
/**
* Same assertion as {@link Assert#isNotIn(Object...)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param datesAsString the given Dates represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual is in given Dates represented as String.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isNotIn(String... datesAsString) {
Date[] dates = new Date[datesAsString.length];
for (int i = 0; i < datesAsString.length; i++) {
dates[i] = parse(datesAsString[i]);
}
return isNotIn(dates);
}
/**
* Same assertion as {@link Assert#isNotIn(Iterable)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* Method signature could not be isNotIn(Collection<String>)
because it would be same signature as
* isNotIn(Collection<Date>)
since java collection type are erased at runtime.
* @param datesAsString the given Dates represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if actual is in given Dates represented as String.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isNotInWithStringDateCollection(Collection datesAsString) {
Collection dates = new ArrayList(datesAsString.size());
for (String dateAsString : datesAsString) {
dates.add(parse(dateAsString));
}
return isNotIn(dates);
}
/**
* Verifies that the actual {@code Date} is strictly before the given one.
* @param other the given Date.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if other {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not strictly before the given one.
*/
public DateAssert isBefore(Date other) {
dates.assertIsBefore(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isBefore(Date)} but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
* user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if given date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not strictly before the given Date represented as String.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isBefore(String dateAsString) {
return isBefore(parse(dateAsString));
}
/**
* Verifies that the actual {@code Date} is before or equals to the given one.
* @param other the given Date.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if other {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not before or equals to the given one.
*/
public DateAssert isBeforeOrEqualsTo(Date other) {
dates.assertIsBeforeOrEqualsTo(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isBeforeOrEqualsTo(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if given date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not before or equals to the given Date represented as String.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isBeforeOrEqualsTo(String dateAsString) {
return isBeforeOrEqualsTo(parse(dateAsString));
}
/**
* Verifies that the actual {@code Date} is strictly after the given one.
* @param other the given Date.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if other {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not strictly after the given one.
*/
public DateAssert isAfter(Date other) {
dates.assertIsAfter(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isAfter(Date)} but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
* user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if given date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not strictly after the given Date represented as String.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isAfter(String dateAsString) {
return isAfter(parse(dateAsString));
}
/**
* Verifies that the actual {@code Date} is after or equals to the given one.
* @param other the given Date.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if other {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not after or equals to the given one.
*/
public DateAssert isAfterOrEqualsTo(Date other) {
dates.assertIsAfterOrEqualsTo(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isAfterOrEqualsTo(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if given date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not after or equals to the given Date represented as String.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isAfterOrEqualsTo(String dateAsString) {
return isAfterOrEqualsTo(parse(dateAsString));
}
/**
* Verifies that the actual {@code Date} is in [start, end[ period (start included, end excluded).
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if start {@code Date} is {@code null}.
* @throws NullPointerException if end {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in [start, end[ period.
*/
public DateAssert isBetween(Date start, Date end) {
return isBetween(start, end, true, false);
}
/**
* Same assertion as {@link #isBetween(Date, Date)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if start Date as String is {@code null}.
* @throws NullPointerException if end Date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in [start, end[ period.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isBetween(String start, String end) {
return isBetween(parse(start), parse(end));
}
/**
* Verifies that the actual {@code Date} is in the given period defined by start and end dates.
* To include start in the period set inclusiveStart parameter to true
.
* To include end in the period set inclusiveEnd parameter to true
.
* @param start the period start, expected not to be null.
* @param end the period end, expected not to be null.
* @param inclusiveStart wether to include start date in period.
* @param inclusiveEnd wether to include end date in period.
* @return this assertion object.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws NullPointerException if start {@code Date} is {@code null}.
* @throws NullPointerException if end {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in (start, end) period.
*/
public DateAssert isBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {
dates.assertIsBetween(info, actual, start, end, inclusiveStart, inclusiveEnd);
return this;
}
/**
* Same assertion as {@link #isBetween(Date, Date, boolean, boolean)} but given Dates are represented as String either with ISO
* date format (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param start the period start, expected not to be null.
* @param end the period end, expected not to be null.
* @param inclusiveStart wether to include start date in period.
* @param inclusiveEnd wether to include end date in period.
* @return this assertion object.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws NullPointerException if start Date as String is {@code null}.
* @throws NullPointerException if end Date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in (start, end) period.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd) {
dates.assertIsBetween(info, actual, parse(start), parse(end), inclusiveStart, inclusiveEnd);
return this;
}
/**
* Verifies that the actual {@code Date} is not in the given period defined by start and end dates.
* To include start in the period set inclusiveStart parameter to true
.
* To include end in the period set inclusiveEnd parameter to true
.
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @param inclusiveStart wether to include start date in period.
* @param inclusiveEnd wether to include end date in period.
* @return this assertion object.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws NullPointerException if start {@code Date} is {@code null}.
* @throws NullPointerException if end {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in (start, end) period.
*/
public DateAssert isNotBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {
dates.assertIsNotBetween(info, actual, start, end, inclusiveStart, inclusiveEnd);
return this;
}
/**
* Same assertion as {@link #isNotBetween(Date, Date, boolean, boolean)} but given Dates are represented as String either with
* ISO date format (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @param inclusiveStart wether to include start date in period.
* @param inclusiveEnd wether to include end date in period.
* @return this assertion object.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws NullPointerException if start Date as String is {@code null}.
* @throws NullPointerException if end Date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in (start, end) period.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isNotBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd) {
return isNotBetween(parse(start), parse(end), inclusiveStart, inclusiveEnd);
}
/**
* Verifies that the actual {@code Date} is not in [start, end[ period
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if start {@code Date} is {@code null}.
* @throws NullPointerException if end {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is in [start, end[ period.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isNotBetween(Date start, Date end) {
return isNotBetween(start, end, true, false);
}
/**
* Same assertion as {@link #isNotBetween(Date, Date)} but given Dates are represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param start the period start (inclusive), expected not to be null.
* @param end the period end (exclusive), expected not to be null.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws NullPointerException if start Date as String is {@code null}.
* @throws NullPointerException if end Date as String is {@code null}.
* @throws AssertionError if the actual {@code Date} is in [start, end[ period.
* @throws AssertionError if one of the given date as String could not be converted to a Date.
*/
public DateAssert isNotBetween(String start, String end) {
return isNotBetween(parse(start), parse(end), true, false);
}
/**
* Verifies that the actual {@code Date} is strictly in the past.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in the past.
*/
public DateAssert isInThePast() {
dates.assertIsInThePast(info, actual);
return this;
}
/**
* Verifies that the actual {@code Date} is today, that is matching current year, month and day (no check on hour, minute,
* second, milliseconds).
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not today.
*/
public DateAssert isToday() {
dates.assertIsToday(info, actual);
return this;
}
/**
* Verifies that the actual {@code Date} is strictly in the future.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} is not in the future.
*/
public DateAssert isInTheFuture() {
dates.assertIsInTheFuture(info, actual);
return this;
}
/**
* Verifies that the actual {@code Date} is strictly before the given year.
* @param year the year to compare actual year to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} year is after or equals to the given year.
*/
public DateAssert isBeforeYear(int year) {
dates.assertIsBeforeYear(info, actual, year);
return this;
}
/**
* Verifies that the actual {@code Date} is strictly after the given year.
* @param year the year to compare actual year to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} year is before or equals to the given year.
*/
public DateAssert isAfterYear(int year) {
dates.assertIsAfterYear(info, actual, year);
return this;
}
/**
* Verifies that the actual {@code Date} year is equal to the given year.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param year the year to compare actual year to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} year is not equal to the given year.
*/
public DateAssert isWithinYear(int year) {
dates.assertIsWithinYear(info, actual, year);
return this;
}
/**
* Verifies that the actual {@code Date} month is equal to the given month, month value starting at 1 (January=1,
* February=2, ...).
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param month the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} month is not equal to the given month.
*/
public DateAssert isWithinMonth(int month) {
dates.assertIsWithinMonth(info, actual, month);
return this;
}
/**
* Verifies that the actual {@code Date} day of month is equal to the given day of month.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param dayOfMonth the day of month to compare actual day of month to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} month is not equal to the given day of month.
*/
public DateAssert isWithinDayOfMonth(int dayOfMonth) {
dates.assertIsWithinDayOfMonth(info, actual, dayOfMonth);
return this;
}
/**
* Verifies that the actual {@code Date} day of week is equal to the given day of week (see {@link Calendar#DAY_OF_WEEK} for
* valid values).
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid values
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} week is not equal to the given day of week.
*/
public DateAssert isWithinDayOfWeek(int dayOfWeek) {
dates.assertIsWithinDayOfWeek(info, actual, dayOfWeek);
return this;
}
/**
* Verifies that the actual {@code Date} hour od day is equal to the given hour of day (24-hour clock).
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock)
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} hour is not equal to the given hour.
*/
public DateAssert isWithinHourOfDay(int hourOfDay) {
dates.assertIsWithinHourOfDay(info, actual, hourOfDay);
return this;
}
/**
* Verifies that the actual {@code Date} minute is equal to the given minute.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param minute the minute to compare actual minute to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} minute is not equal to the given minute.
*/
public DateAssert isWithinMinute(int minute) {
dates.assertIsWithinMinute(info, actual, minute);
return this;
}
/**
* Verifies that the actual {@code Date} second is equal to the given second.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param second the second to compare actual second to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} second is not equal to the given second.
*/
public DateAssert isWithinSecond(int second) {
dates.assertIsWithinSecond(info, actual, second);
return this;
}
/**
* Verifies that the actual {@code Date} millisecond is equal to the given millisecond.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param millisecond the millisecond to compare actual millisecond to
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond.
*/
public DateAssert isWithinMillisecond(int millisecond) {
dates.assertIsWithinMillisecond(info, actual, millisecond);
return this;
}
/**
* Verifies that actual and given {@code Date} are in the same year.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same year.
*/
public DateAssert isInSameYearAs(Date other) {
dates.assertIsInSameYearAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameYearAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given Date represented as String are not in the same year.
* @throws AssertionError if the given date as String could not be converted to a Date.
*/
public DateAssert isInSameYearAs(String dateAsString) {
return isInSameYearAs(parse(dateAsString));
}
/**
* Verifies that actual and given {@code Date} are chronologically in the same month (and thus in the same year).
*
* If you want to compare month only (without year), use : assertThat(myDate).isWithinMonth(monthOf(otherDate))
* See {@link org.fest.util.Dates#monthOf(Date)} to get the month of a given Date.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same month.
*/
public DateAssert isInSameMonthAs(Date other) {
dates.assertIsInSameMonthAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameMonthAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same month.
*/
public DateAssert isInSameMonthAs(String dateAsString) {
return isInSameMonthAs(parse(dateAsString));
}
/**
* Verifies that actual and given {@code Date} are chronologically in the same day of month (and thus in the same month and
* year).
*
* If you want to compare day of month only (without month and year), you could write :
* assertThat(myDate).isWithinDayOfMonth(dayOfMonthOf(otherDate))
* see {@link org.fest.util.Dates#dayOfMonthOf(Date)} to get the day of month of a given Date.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same day of month.
*/
public DateAssert isInSameDayAs(Date other) {
dates.assertIsInSameDayAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameDayAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same day of month.
*/
public DateAssert isInSameDayAs(String dateAsString) {
return isInSameDayAs(parse(dateAsString));
}
/**
* Verifies that actual and given {@code Date} are chronologically in the same hour (and thus in the same day, month and year).
*
* If you want to compare hour only (without day, month and year), you could write :
* assertThat(myDate).isWithinHour(hourOfDayOf(otherDate))
* see {@link org.fest.util.Dates#hourOfDay(Date)} to get the hour of a given Date.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same hour.
*/
public DateAssert isInSameHourAs(Date other) {
dates.assertIsInSameHourAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameHourAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same hour.
*/
public DateAssert isInSameHourAs(String dateAsString) {
return isInSameHourAs(parse(dateAsString));
}
/**
* Verifies that actual and given {@code Date} are chronologically in the same minute (and thus in the same hour, day, month and
* year).
*
* If you want to compare minute only (without hour, day, month and year), you could write :
* assertThat(myDate).isWithinMinute(minuteOf(otherDate))
* see {@link org.fest.util.Dates#minuteOf(Date)} to get the minute of a given Date.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same minute.
*/
public DateAssert isInSameMinuteAs(Date other) {
dates.assertIsInSameMinuteAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameMinuteAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same minute.
*/
public DateAssert isInSameMinuteAs(String dateAsString) {
return isInSameMinuteAs(parse(dateAsString));
}
/**
* Verifies that actual and given {@code Date} are chronologically in the same second (and thus in the same minute, hour, day,
* month and year).
*
* If you want to compare second only (without minute, hour, day, month and year), you could write :
* assertThat(myDate).isWithinSecond(secondOf(otherDate))
* see {@link org.fest.util.Dates#secondOf(Date)} to get the second of a given Date.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
*
* @param other the given {@code Date} to compare actual {@code Date} to.
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same second.
*/
public DateAssert isInSameSecondAs(Date other) {
dates.assertIsInSameSecondAs(info, actual, other);
return this;
}
/**
* Same assertion as {@link #isInSameSecondAs(Date)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if actual and given {@code Date} are not in the same second.
*/
public DateAssert isInSameSecondAs(String dateAsString) {
return isInSameSecondAs(parse(dateAsString));
}
/**
* Verifies that the actual {@code Date} is close to the other date by less than delta (expressed in milliseconds), if
* difference is equals to delta it's ok.
*
* One can use handy {@link TimeUnit} to convert a duration in milliseconds, for example you can express a delta of 5 seconds
* with TimeUnit.SECONDS.toMillis(5)
.
*
* Note that using a custom comparator has no effect on this assertion (see {@link #usingComparator(Comparator)}.
* @param other the date to compare actual to
* @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds
* @return this assertion object.
* @throws NullPointerException if {@code Date} parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} week is not close to the given date by less than delta.
*/
public DateAssert isCloseTo(Date other, long deltaInMilliseconds) {
dates.assertIsCloseTo(info, actual, other, deltaInMilliseconds);
return this;
}
/**
* Same assertion as {@link #isCloseTo(Date, long)} but given Date is represented as String either with ISO date format
* (yyyy-MM-dd) or user custom date format (set with method {@link #withDateFormat(DateFormat)}).
* @param dateAsString the given Date represented as String in default or custom date format.
* @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds
* @return this assertion object.
* @throws NullPointerException if dateAsString parameter is {@code null}.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} week is not close to the given date by less than delta.
*/
public DateAssert isCloseTo(String dateAsString, long deltaInMilliseconds) {
return isCloseTo(parse(dateAsString), deltaInMilliseconds);
}
/**
* Verifies that the actual {@code Date} has the same time as the given timestamp.
*
* Both time or timestamp express a number of milliseconds since January 1, 1970, 00:00:00 GMT.
* @param timestamp the timestamp to compare actual time to.
* @return this assertion object.
* @throws AssertionError if the actual {@code Date} is {@code null}.
* @throws AssertionError if the actual {@code Date} time is not equal to the given timestamp.
* @see Date#getTime()
*/
public DateAssert hasTime(long timestamp) {
dates.assertHasTime(info, actual, timestamp);
return this;
}
/**
* For String based Date assertions like {@link #isBefore(String)}, given String is expected to follow the default Date format,
* that is ISO 8601 format : "yyyy-MM-dd".
*
* With this method, user can specify its own date format, replacing the current date format for all future Date assertions in
* the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
*
* To revert to default format simply call {@link #withIsoDateFormat()}.
*
* @param userCustomDateFormat the new Date format used for String based Date assertions.
* @return this assertion object.
*/
public DateAssert withDateFormat(DateFormat userCustomDateFormat) {
useDateFormat(userCustomDateFormat);
return this;
}
/**
* For String based Date assertions like {@link #isBefore(String)}, given String is expected to follow the default Date format,
* that is ISO 8601 format : "yyyy-MM-dd".
*
* With this method, user can specify its own date format, replacing the current date format for all future Date assertions in
* the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
*
* To revert to default format simply call {@link #useIsoDateFormat()} (static method) or {@link #withIsoDateFormat()}.
*
* @param userCustomDateFormat the new Date format used for String based Date assertions.
*/
public static void useDateFormat(DateFormat userCustomDateFormat) {
if (userCustomDateFormat == null) throw new NullPointerException("The given date format should not be null");
dateFormat = userCustomDateFormat;
}
/**
* Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.
* @return this assertion object.
*/
public DateAssert withIsoDateFormat() {
useIsoDateFormat();
return this;
}
/**
* Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.
*/
public static void useIsoDateFormat() {
dateFormat = ISO_DATE_FORMAT;
}
/**
* Utillity method to parse a Date with {@link #dateFormat}, note that it is thread safe.
* Returns null
if dateAsString parameter is null
.
* @param dateAsString the string to parse as a Date with {@link #dateFormat}
* @return the corrresponding Date, null if dateAsString parameter is null.
* @throws AssertionError if the string can't be parsed as a Date
*/
private static Date parse(String dateAsString) {
if (dateAsString == null) { return null; }
try {
// synchronized is used because SimpleDateFormat which is not thread safe (sigh).
synchronized (dateFormat) {
return dateFormat.parse(dateAsString);
}
} catch (ParseException e) {
throw Failures.instance().failure("Failed to parse " + dateAsString + " with date format " + dateFormat);
}
}
@Override
public DateAssert usingComparator(Comparator super Date> customComparator) {
super.usingComparator(customComparator);
this.dates = new Dates(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public DateAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.dates = Dates.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/DoubleArrayAssert.java 0000664 0000000 0000000 00000022236 12430205632 0027460 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code double}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(double[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class DoubleArrayAssert extends AbstractAssert implements
EnumerableAssert, ArraySortedAssert {
@VisibleForTesting
DoubleArrays arrays = DoubleArrays.instance();
protected DoubleArrayAssert(double[] actual) {
super(actual, DoubleArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public DoubleArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public DoubleArrayAssert contains(double... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public DoubleArrayAssert containsOnly(double... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public DoubleArrayAssert containsSequence(double... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public DoubleArrayAssert contains(double value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public DoubleArrayAssert doesNotContain(double... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public DoubleArrayAssert doesNotContain(double value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public DoubleArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(double...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public DoubleArrayAssert startsWith(double... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(double...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public DoubleArrayAssert endsWith(double... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert isSortedAccordingTo(Comparator super Double> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public DoubleArrayAssert usingElementComparator(Comparator super Double> customComparator) {
this.arrays = new DoubleArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public DoubleArrayAssert usingDefaultElementComparator() {
this.arrays = DoubleArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/DoubleAssert.java 0000664 0000000 0000000 00000015172 12430205632 0026462 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 25, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.FloatingPointNumberAssert;
import org.fest.assertions.data.Offset;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for doubles.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Double)}
or
* {@link Assertions#assertThat(double)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Alex Ruiz
* @author Ansgar Konermann
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class DoubleAssert extends AbstractComparableAssert implements FloatingPointNumberAssert {
@VisibleForTesting
Doubles doubles = Doubles.instance();
protected DoubleAssert(Double actual) {
super(actual, DoubleAssert.class);
}
/** {@inheritDoc} */
public DoubleAssert isNaN() {
doubles.assertIsNaN(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isNotNaN() {
doubles.assertIsNotNaN(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isZero() {
doubles.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isNotZero() {
doubles.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isPositive() {
doubles.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isNegative() {
doubles.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isNotNegative() {
doubles.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isNotPositive() {
doubles.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public DoubleAssert isEqualTo(double expected) {
doubles.assertEqual(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public DoubleAssert isEqualTo(Double expected, Offset offset) {
doubles.assertEqual(info, actual, expected, offset);
return this;
}
/**
* Verifies that the actual value is equal to the given one, within a positive offset.
* @param expected the given value to compare the actual value to.
* @param offset the given positive offset.
* @return {@code this} assertion object.
* @throws NullPointerException if the given offset is {@code null}.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public DoubleAssert isEqualTo(double expected, Offset offset) {
doubles.assertEqual(info, actual, expected, offset);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public DoubleAssert isNotEqualTo(double other) {
doubles.assertNotEqual(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public DoubleAssert isLessThan(double other) {
doubles.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public DoubleAssert isLessThanOrEqualTo(double other) {
doubles.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public DoubleAssert isGreaterThan(double other) {
doubles.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public DoubleAssert isGreaterThanOrEqualTo(double other) {
doubles.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public DoubleAssert usingComparator(Comparator super Double> customComparator) {
super.usingComparator(customComparator);
this.doubles = new Doubles(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public DoubleAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.doubles = Doubles.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/Fail.java 0000664 0000000 0000000 00000005541 12430205632 0024740 0 ustar 00root root 0000000 0000000 /*
* Created on Mar 19, 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.assertions.api;
import static java.lang.String.format;
import org.fest.assertions.internal.Failures;
/**
* Common failures.
*
* @author Alex Ruiz
* @author Yvonne Wang
* @author Joel Costigliola
*/
public final class Fail {
/**
* Sets wether we remove elements related to Fest from assertion error stack trace.
* @param removeFestRelatedElementsFromStackTrace flag.
*/
public static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace) {
Failures.instance().setRemoveFestRelatedElementsFromStackTrace(removeFestRelatedElementsFromStackTrace);
}
/**
* Fails with the given message.
* @param failureMessage error message.
* @throws AssertionError with the given message.
*/
public static void fail(String failureMessage) {
throw Failures.instance().failure(failureMessage);
}
/**
* Throws an {@link AssertionError} with the given message and with the {@link Throwable} that caused the failure.
* @param failureMessage the description of the failed assertion. It can be {@code null}.
* @param realCause cause of the error.
* @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.
*/
public static void fail(String failureMessage, Throwable realCause) {
AssertionError error = Failures.instance().failure(failureMessage);
error.initCause(realCause);
throw error;
}
/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
* @param throwableClass the Throwable class that was expected to be thrown.
* @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had
* not been.
*/
public static void failBecauseExceptionWasNotThrown(Class extends Throwable> throwableClass) {
throw Failures.instance().failure(format("Expected %s to be thrown", throwableClass.getSimpleName()));
}
/**
* This constructor is protected to make it possible to subclass this class. Since all its methods are static, there is no point
* on creating a new instance of it.
*/
protected Fail() {}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/FileAssert.java 0000664 0000000 0000000 00000021170 12430205632 0026122 0 ustar 00root root 0000000 0000000 /*
* Created on Jan 28, 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
<<<<<<< HEAD
*
* 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.
=======
*
* 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.
>>>>>>> refs/heads/github-71
*/
package org.fest.assertions.api;
import java.io.File;
import java.nio.charset.Charset;
import org.fest.assertions.internal.Files;
import org.fest.util.FilesException;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@link File}
s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(File)}
.
*
*
* @author David DIDIER
* @author Yvonne Wang
* @author Alex Ruiz
* @author Olivier Michallat
* @author Olivier Demeijer
*/
public class FileAssert extends AbstractAssert {
@VisibleForTesting
Files files = Files.instance();
@VisibleForTesting
Charset charset = Charset.defaultCharset();
protected FileAssert(File actual) {
super(actual, FileAssert.class);
}
/**
* Verifies that the actual {@code File} exists, regardless it's a file or directory.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} does not exist.
*/
public FileAssert exists() {
files.assertExists(info, actual);
return this;
}
/**
* Verifies that the actual {@code File} does not exist.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} exists.
*/
public FileAssert doesNotExist() {
files.assertDoesNotExist(info, actual);
return this;
}
/**
* Verifies that the actual {@code File} is an existing file.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an existing file.
*/
public FileAssert isFile() {
files.assertIsFile(info, actual);
return this;
}
/**
* Verifies that the actual {@code File} is an existing directory.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an existing file.
*/
public FileAssert isDirectory() {
files.assertIsDirectory(info, actual);
return this;
}
/**
* Verifies that the actual {@code File} is an absolute path.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an absolute path.
*/
public FileAssert isAbsolute() {
files.assertIsAbsolute(info, actual);
return this;
}
/**
* Verifies that the actual {@code File} is a relative path.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not a relative path.
*/
public FileAssert isRelative() {
files.assertIsRelative(info, actual);
return this;
}
/**
* Verifies that the content of the actual {@code File} is equal to the content of the given one.
* @param expected the given {@code File} to compare the actual {@code File} to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} is not an existing file.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an existing file.
* @throws FilesException if an I/O error occurs.
* @throws AssertionError if the content of the actual {@code File} is not equal to the content of the given one.
*/
public FileAssert hasContentEqualTo(File expected) {
files.assertEqualContent(info, actual, expected);
return this;
}
/**
* Verifies that the binary content of the actual {@code File} is exactly equal to the given one.
* @param expected the expected binary content to compare the actual {@code File}'s content to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given content is {@code null}.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an existing file.
* @throws FilesException if an I/O error occurs.
* @throws AssertionError if the content of the actual {@code File} is not equal to the given binary content.
*/
public FileAssert hasBinaryContent(byte[] expected) {
files.assertHasBinaryContent(info, actual, expected);
return this;
}
/**
* Specifies the name of the charset to use for text-based assertions on the file's contents.
*
* @param charsetName the name of the charset to use.
* @return {@code this} assertion object.
* @throws IllegalArgumentException if the given encoding is not supported on this platform.
*/
public FileAssert usingCharset(String charsetName) {
if (!Charset.isSupported(charsetName)) throw new IllegalArgumentException(String.format("Charset:<'%s'> is not supported on this system", charsetName));
return usingCharset(Charset.forName(charsetName));
}
/**
* Specifies the charset to use for text-based assertions on the file's contents.
*
* @param charset the charset to use.
* @return {@code this} assertion object.
* @throws NullPointerException if the given charset is {@code null}.
*/
public FileAssert usingCharset(Charset charset) {
if (charset == null) throw new NullPointerException("The charset should not be null");
this.charset = charset;
return this;
}
/**
* Verifies that the text content of the actual {@code File} is exactly equal to the given one.
* The charset to use when reading the file should be provided with {@link #usingCharset(Charset)} or
* {@link #usingCharset(String)} prior to calling this method; if not, the platform's default charset (as returned by
* {@link Charset#defaultCharset()}) will be used.
* @param expected the expected text content to compare the actual {@code File}'s content to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given content is {@code null}.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} is not an existing file.
* @throws FilesException if an I/O error occurs.
* @throws AssertionError if the content of the actual {@code File} is not equal to the given binary content.
*/
public FileAssert hasContent(String expected) {
files.assertHasContent(info, actual, expected, charset);
return this;
}
/**
*
* Verifies that the actual {@code File} can be modified by the application.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} can not be modified by the application.
*/
public FileAssert canWrite() {
files.assertCanWrite(info, actual);
return this;
}
/**
*
* Verifies that the actual {@code File} can be read by the application.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code File} is {@code null}.
* @throws AssertionError if the actual {@code File} can not be read by the application.
*/
public FileAssert canRead() {
files.assertCanRead(info, actual);
return this;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/FloatArrayAssert.java 0000664 0000000 0000000 00000022157 12430205632 0027315 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code float}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(float[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class FloatArrayAssert extends AbstractAssert implements
EnumerableAssert, ArraySortedAssert {
@VisibleForTesting
FloatArrays arrays = FloatArrays.instance();
protected FloatArrayAssert(float[] actual) {
super(actual, FloatArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public FloatArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public FloatArrayAssert contains(float... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public FloatArrayAssert containsOnly(float... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public FloatArrayAssert containsSequence(float... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public FloatArrayAssert contains(float value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public FloatArrayAssert doesNotContain(float... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public FloatArrayAssert doesNotContain(float value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public FloatArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(float...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public FloatArrayAssert startsWith(float... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(float...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public FloatArrayAssert endsWith(float... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert isSortedAccordingTo(Comparator super Float> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public FloatArrayAssert usingElementComparator(Comparator super Float> customComparator) {
this.arrays = new FloatArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public FloatArrayAssert usingDefaultElementComparator() {
this.arrays = FloatArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/FloatAssert.java 0000664 0000000 0000000 00000015006 12430205632 0026311 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 24, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.FloatingPointNumberAssert;
import org.fest.assertions.data.Offset;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for floats.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Float)}
or
* {@link Assertions#assertThat(float)}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Ansgar Konermann
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class FloatAssert extends AbstractComparableAssert implements FloatingPointNumberAssert {
@VisibleForTesting
Floats floats = Floats.instance();
protected FloatAssert(Float actual) {
super(actual, FloatAssert.class);
}
/** {@inheritDoc} */
public FloatAssert isNaN() {
floats.assertIsNaN(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isNotNaN() {
floats.assertIsNotNaN(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isZero() {
floats.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isNotZero() {
floats.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isPositive() {
floats.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isNegative() {
floats.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isNotNegative() {
floats.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public FloatAssert isNotPositive() {
floats.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public FloatAssert isEqualTo(float expected) {
floats.assertEqual(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public FloatAssert isEqualTo(Float expected, Offset offset) {
floats.assertEqual(info, actual, expected, offset);
return this;
}
/**
* Verifies that the actual value is equal to the given one, within a positive offset.
* @param expected the given value to compare the actual value to.
* @param offset the given positive offset.
* @return {@code this} assertion object.
* @throws NullPointerException if the given offset is {@code null}.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public FloatAssert isEqualTo(float expected, Offset offset) {
floats.assertEqual(info, actual, expected, offset);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public FloatAssert isNotEqualTo(float other) {
floats.assertNotEqual(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public FloatAssert isLessThan(float other) {
floats.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public FloatAssert isLessThanOrEqualTo(float other) {
floats.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public FloatAssert isGreaterThan(float other) {
floats.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public FloatAssert isGreaterThanOrEqualTo(float other) {
floats.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public FloatAssert usingComparator(Comparator super Float> customComparator) {
super.usingComparator(customComparator);
this.floats = new Floats(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public FloatAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.floats = Floats.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/InputStreamAssert.java 0000664 0000000 0000000 00000002665 12430205632 0027526 0 ustar 00root root 0000000 0000000 package org.fest.assertions.api;
import java.io.InputStream;
import org.fest.assertions.internal.InputStreams;
import org.fest.assertions.internal.InputStreamsException;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@link InputStream}
s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(InputStream)}
.
*
* @author Matthieu Baechler
*/
public class InputStreamAssert extends AbstractAssert {
@VisibleForTesting
InputStreams inputStreams = InputStreams.instance();
public InputStreamAssert(InputStream actual) {
super(actual, InputStreamAssert.class);
}
/**
* Verifies that the content of the actual {@code InputStream} is equal to the content of the given one.
*
* @param expected the given {@code InputStream} to compare the actual {@code InputStream} to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given {@code InputStream} is {@code null}.
* @throws AssertionError if the actual {@code InputStream} is {@code null}.
* @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one.
* @throws InputStreamsException if an I/O error occurs.
*/
public InputStreamAssert hasContentEqualTo(InputStream expected) {
inputStreams.assertEqualContent(info, actual, expected);
return this;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/IntArrayAssert.java 0000664 0000000 0000000 00000022045 12430205632 0026776 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 14, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code int}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(int[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class IntArrayAssert extends AbstractAssert implements EnumerableAssert,
ArraySortedAssert {
@VisibleForTesting
IntArrays arrays = IntArrays.instance();
protected IntArrayAssert(int[] actual) {
super(actual, IntArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public IntArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public IntArrayAssert contains(int... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public IntArrayAssert containsOnly(int... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public IntArrayAssert containsSequence(int... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public IntArrayAssert contains(int value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public IntArrayAssert doesNotContain(int... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public IntArrayAssert doesNotContain(int value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public IntArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(int...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public IntArrayAssert startsWith(int... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(int...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public IntArrayAssert endsWith(int... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert isSortedAccordingTo(Comparator super Integer> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public IntArrayAssert usingElementComparator(Comparator super Integer> customComparator) {
this.arrays = new IntArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public IntArrayAssert usingDefaultElementComparator() {
this.arrays = IntArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/IntegerAssert.java 0000664 0000000 0000000 00000013033 12430205632 0026637 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 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-2011 the original author or authors.
*/
package org.fest.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.NumberAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for integers.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Integer)}
or
* {@link Assertions#assertThat(int)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class IntegerAssert extends AbstractComparableAssert implements NumberAssert {
@VisibleForTesting
Integers integers = Integers.instance();
protected IntegerAssert(Integer actual) {
super(actual, IntegerAssert.class);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public IntegerAssert isEqualTo(int expected) {
integers.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public IntegerAssert isNotEqualTo(int other) {
integers.assertNotEqual(info, actual, other);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isZero() {
integers.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isNotZero() {
integers.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isPositive() {
integers.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isNegative() {
integers.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isNotNegative() {
integers.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public IntegerAssert isNotPositive() {
integers.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public IntegerAssert isLessThan(int other) {
integers.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public IntegerAssert isLessThanOrEqualTo(int other) {
integers.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public IntegerAssert isGreaterThan(int other) {
integers.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public IntegerAssert isGreaterThanOrEqualTo(int other) {
integers.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public IntegerAssert usingComparator(Comparator super Integer> customComparator) {
super.usingComparator(customComparator);
this.integers = new Integers(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public IntegerAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.integers = Integers.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/IterableAssert.java 0000664 0000000 0000000 00000002316 12430205632 0026773 0 ustar 00root root 0000000 0000000 /*
* Created on Jul 26, 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.assertions.api;
/**
* Assertion methods for {@link Iterable}.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Iterable)}
.
*
* @param the type of elements of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Matthieu Baechler
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class IterableAssert extends AbstractIterableAssert, Iterable, T> {
protected IterableAssert(Iterable actual) {
super(actual, IterableAssert.class);
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ListAssert.java 0000664 0000000 0000000 00000015037 12430205632 0026163 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 26, 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.assertions.api;
import java.util.Comparator;
import java.util.List;
import org.fest.assertions.core.Condition;
import org.fest.assertions.core.IndexedObjectEnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@link List}
s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(List)}
.
*
* @param the type of elements of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
// TODO inherits from IterableAssert and remove AbstractIterableAssert ?
public class ListAssert extends AbstractIterableAssert, List, T> implements
IndexedObjectEnumerableAssert, T> {
@VisibleForTesting
Lists lists = Lists.instance();
protected ListAssert(List actual) {
super(actual, ListAssert.class);
}
/** {@inheritDoc} */
public ListAssert contains(T value, Index index) {
lists.assertContains(info, actual, value, index);
return this;
}
/** {@inheritDoc} */
public ListAssert doesNotContain(T value, Index index) {
lists.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual object at the given index in the actual group satisfies the given condition.
* @param condition the given condition.
* @param index the index where the object should be stored in the actual group.
* @return this assertion object.
* @throws AssertionError if the given {@code List} is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the given
* {@code List}.
* @throws NullPointerException if the given {@code Condition} is {@code null}.
* @throws AssertionError if the value in the given {@code List} at the given index does not satisfy the given {@code Condition}
* .
*/
public ListAssert has(Condition super T> condition, Index index) {
lists.assertHas(info, actual, condition, index);
return this;
}
/**
* Verifies that the actual object at the given index in the actual group satisfies the given condition.
* @param condition the given condition.
* @param index the index where the object should be stored in the actual group.
* @return this assertion object.
* @throws AssertionError if the given {@code List} is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the given
* {@code List}.
* @throws NullPointerException if the given {@code Condition} is {@code null}.
* @throws AssertionError if the value in the given {@code List} at the given index does not satisfy the given {@code Condition}
* .
*/
public ListAssert is(Condition super T> condition, Index index) {
lists.assertIs(info, actual, condition, index);
return this;
}
/**
* Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.
*
* All list elements must implement the {@link Comparable} interface and must be mutually comparable (that is, e1.compareTo(e2)
* must not throw a ClassCastException for any elements e1 and e2 in the list), examples :
*
* a list composed of {"a1", "a2", "a3"} is ok because the element type (String) is Comparable
* a list composed of Rectangle {r1, r2, r3} is NOT ok because Rectangle is not Comparable
* a list composed of {True, "abc", False} is NOT ok because elements are not mutually comparable
*
* Empty lists are considered sorted. Unique element lists are considered sorted unless the element type is not Comparable.
*
* @return {@code this} assertion object.
*
* @throws AssertionError if the actual list is not sorted into ascending order according to the natural ordering of its
* elements.
* @throws AssertionError if the actual list is null
.
* @throws AssertionError if the actual list element type does not implement {@link Comparable}.
* @throws AssertionError if the actual list elements are not mutually {@link Comparable}.
*/
public ListAssert isSorted() {
lists.assertIsSorted(info, actual);
return this;
}
/**
* Verifies that the actual list is sorted according to the given comparator. Empty lists are considered sorted whatever
* the comparator is. One element lists are considered sorted if element is compatible with comparator.
*
* @param comparator the {@link Comparator} used to compare list elements
*
* @return {@code this} assertion object.
*
* @throws AssertionError if the actual list is not sorted according to the given comparator.
* @throws AssertionError if the actual list is null
.
* @throws NullPointerException if the given comparator is null
.
* @throws AssertionError if the actual list elements are not mutually comparable according to given Comparator.
*/
public ListAssert isSortedAccordingTo(Comparator super T> comparator) {
lists.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
@Override
public ListAssert usingElementComparator(Comparator super T> customComparator) {
super.usingElementComparator(customComparator);
this.lists = new Lists(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public ListAssert usingDefaultElementComparator() {
super.usingDefaultElementComparator();
this.lists = Lists.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/LongArrayAssert.java 0000664 0000000 0000000 00000022102 12430205632 0027135 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code long}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(long[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class LongArrayAssert extends AbstractAssert implements EnumerableAssert,
ArraySortedAssert {
@VisibleForTesting
LongArrays arrays = LongArrays.instance();
protected LongArrayAssert(long[] actual) {
super(actual, LongArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public LongArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public LongArrayAssert contains(long... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public LongArrayAssert containsOnly(long... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public LongArrayAssert containsSequence(long... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public LongArrayAssert contains(long value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public LongArrayAssert doesNotContain(long... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public LongArrayAssert doesNotContain(long value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public LongArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(long...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public LongArrayAssert startsWith(long... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(long...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public LongArrayAssert endsWith(long... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert isSortedAccordingTo(Comparator super Long> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public LongArrayAssert usingElementComparator(Comparator super Long> customComparator) {
this.arrays = new LongArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public LongArrayAssert usingDefaultElementComparator() {
this.arrays = LongArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/LongAssert.java 0000664 0000000 0000000 00000012641 12430205632 0026145 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.NumberAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for longs.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Long)}
or
* {@link Assertions#assertThat(long)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class LongAssert extends AbstractComparableAssert implements NumberAssert {
@VisibleForTesting
Longs longs = Longs.instance();
protected LongAssert(Long actual) {
super(actual, LongAssert.class);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public LongAssert isEqualTo(long expected) {
longs.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public LongAssert isNotEqualTo(long other) {
longs.assertNotEqual(info, actual, other);
return this;
}
/** {@inheritDoc} */
public LongAssert isZero() {
longs.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public LongAssert isNotZero() {
longs.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public LongAssert isPositive() {
longs.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public LongAssert isNegative() {
longs.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public LongAssert isNotNegative() {
longs.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public LongAssert isNotPositive() {
longs.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public LongAssert isLessThan(long other) {
longs.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public LongAssert isLessThanOrEqualTo(long other) {
longs.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public LongAssert isGreaterThan(long other) {
longs.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public LongAssert isGreaterThanOrEqualTo(long other) {
longs.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public LongAssert usingComparator(Comparator super Long> customComparator) {
super.usingComparator(customComparator);
this.longs = new Longs(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public LongAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.longs = Longs.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/MapAssert.java 0000664 0000000 0000000 00000012561 12430205632 0025764 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 21, 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.assertions.api;
import java.util.Comparator;
import java.util.Map;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.MapEntry;
import org.fest.assertions.internal.Maps;
import org.fest.util.VisibleForTesting;
/**
* Assertions for {@link Map}
s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(Map)}
.
*
*
* @author David DIDIER
* @author Yvonne Wang
* @author Alex Ruiz
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class MapAssert extends AbstractAssert, Map> implements
EnumerableAssert, MapEntry> {
@VisibleForTesting
Maps maps = Maps.instance();
protected MapAssert(Map actual) {
super(actual, MapAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
maps.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
maps.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public MapAssert isNotEmpty() {
maps.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public MapAssert hasSize(int expected) {
maps.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public MapAssert hasSameSizeAs(Object[] other) {
maps.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public MapAssert hasSameSizeAs(Iterable> other) {
maps.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual map contains the given entries, in any order.
* @param entries the given entries.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws NullPointerException if any of the entries in the given array is {@code null}.
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map does not contain the given entries.
*/
public MapAssert contains(MapEntry... entries) {
maps.assertContains(info, actual, entries);
return this;
}
/**
* Verifies that the actual map does not contain the given entries.
* @param entries the given entries.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map contains any of the given entries.
*/
public MapAssert doesNotContain(MapEntry... entries) {
maps.assertDoesNotContain(info, actual, entries);
return this;
}
/**
* Verifies that the actual map contains the given key.
* @param key the given key
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map does not contain the given key.
*/
public MapAssert containsKey(K key) {
maps.assertContainsKey(info, actual, key);
return this;
}
/**
* Verifies that the actual map does not contain the given key.
* @param key the given key
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map contains the given key.
*/
public MapAssert doesNotContainKey(K key) {
maps.assertDoesNotContainKey(info, actual, key);
return this;
}
/**
* Verifies that the actual map contains the given value.
* @param value the value to look for.
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map does not contain the given value.
*/
public MapAssert containsValue(V value) {
maps.assertContainsValue(info, actual, value);
return this;
}
/**
* Verifies that the actual map does not contain the given value.
* @param value the value that should not be in actual map.
* @throws AssertionError if the actual map is {@code null}.
* @throws AssertionError if the actual map contains the given value.
*/
public MapAssert doesNotContainValue(V value) {
maps.assertDoesNotContainValue(info, actual, value);
return this;
}
/** {@inheritDoc} */
public MapAssert usingElementComparator(Comparator super MapEntry> customComparator) {
throw new UnsupportedOperationException("custom element Comparator is not supported for MapEntry comparison");
}
/** {@inheritDoc} */
public MapAssert usingDefaultElementComparator() {
throw new UnsupportedOperationException("custom element Comparator is not supported for MapEntry comparison");
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ObjectArrayAssert.java 0000664 0000000 0000000 00000020123 12430205632 0027445 0 ustar 00root root 0000000 0000000 /*
* Created on Jul 26, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.Condition;
import org.fest.assertions.core.IndexedObjectEnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of objects.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(T[])}
.
*
* @param the type of elements of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Nicolas François
* @author Mikhail Mazursky
*/
public class ObjectArrayAssert extends AbstractAssert, T[]> implements
IndexedObjectEnumerableAssert, T>, ArraySortedAssert, T> {
@VisibleForTesting
ObjectArrays arrays = ObjectArrays.instance();
protected ObjectArrayAssert(T[] actual) {
super(actual, ObjectArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public ObjectArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert contains(T... values) {
arrays.assertContains(info, actual, values);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert containsOnly(T... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert containsExactly(T... values) {
objects.assertEqual(info, actual, values);
return this;
};
/** {@inheritDoc} */
public ObjectArrayAssert containsSequence(T... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert contains(T value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert doesNotContain(T value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert doesNotContain(T... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert startsWith(T... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert endsWith(T... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert containsNull() {
arrays.assertContainsNull(info, actual);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert doesNotContainNull() {
arrays.assertDoesNotContainNull(info, actual);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert are(Condition super T> condition) {
arrays.assertAre(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areNot(Condition super T> condition) {
arrays.assertAreNot(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert have(Condition super T> condition) {
arrays.assertHave(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert doNotHave(Condition super T> condition) {
arrays.assertDoNotHave(info, actual, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areAtLeast(int times, Condition super T> condition) {
arrays.assertAreAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areNotAtLeast(int times, Condition super T> condition) {
arrays.assertAreNotAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areAtMost(int times, Condition super T> condition) {
arrays.assertAreAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areNotAtMost(int times, Condition super T> condition) {
arrays.assertAreNotAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areExactly(int times, Condition super T> condition) {
arrays.assertAreExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert areNotExactly(int times, Condition super T> condition) {
arrays.assertAreNotExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert haveAtLeast(int times, Condition super T> condition) {
arrays.assertHaveAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert doNotHaveAtLeast(int times, Condition super T> condition) {
arrays.assertDoNotHaveAtLeast(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert haveAtMost(int times, Condition super T> condition) {
arrays.assertHaveAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert doNotHaveAtMost(int times, Condition super T> condition) {
arrays.assertDoNotHaveAtMost(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert haveExactly(int times, Condition super T> condition) {
arrays.assertHaveExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert doNotHaveExactly(int times, Condition super T> condition) {
arrays.assertDoNotHaveExactly(info, actual, times, condition);
return myself;
}
/** {@inheritDoc} */
public ObjectArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert isSortedAccordingTo(Comparator super T> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public ObjectArrayAssert containsAll(Iterable extends T> iterable) {
arrays.assertContainsAll(info, actual, iterable);
return this;
}
public ObjectArrayAssert usingElementComparator(Comparator super T> customComparator) {
this.arrays = new ObjectArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
public ObjectArrayAssert usingDefaultElementComparator() {
this.arrays = ObjectArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ObjectAssert.java 0000664 0000000 0000000 00000015445 12430205632 0026461 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 26, 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.assertions.api;
import org.fest.util.IntrospectionError;
/**
* Assertion methods for {@code Object}s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(Object)}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Nicolas François
* @author Mikhail Mazursky
*/
public class ObjectAssert extends AbstractAssert, T> {
protected ObjectAssert(T actual) {
super(actual, ObjectAssert.class);
}
/**
* Assert that the actual object is lenient equals to given one by comparing only actual and not null other
* fields (including inherited fields).
*
* It means that if an actual field is not null and the corresponding field in other is null, field will be ignored by
* lenient comparison, but the inverse will make assertion fail (null field in actual, not null in other).
*
*
* Example:
*
* TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
* TolkienCharacter mysteriousHobbit = new TolkienCharacter(null, 33, HOBBIT);
*
* // Null fields in other/expected object are ignored, the mysteriousHobbit has null name thus name is ignored
* assertThat(frodo).isLenientEqualsToByIgnoringNullFields(mysteriousHobbit); //=> OK
*
* // ... but the lenient equality is not reversible !
* assertThat(mysteriousHobbit).isLenientEqualsToByIgnoringNullFields(frodo); //=> FAIL
*
*
*
* @param other the object to compare {@code actual} to.
* @throws NullPointerException if the actual type is {@code null}.
* @throws NullPointerException if the other type is {@code null}.
* @throws AssertionError if the actual and the given object are not lenient equals.
* @throws AssertionError if the other object is not an instance of the actual type.
*/
public ObjectAssert isLenientEqualsToByIgnoringNullFields(T other) {
objects.assertIsLenientEqualsToByIgnoringNullFields(info, actual, other);
return this;
}
/**
* Assert that the actual object is lenient equals to given one by only comparing actual and other on the given
* "accepted" fields only ("accepted" fields can be inherited fields).
*
* Example:
*
*
* TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
* TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);
*
* // frodo and sam both are hobbits, so they are lenient equals on race
* assertThat(frodo).isLenientEqualsToByAcceptingFields(sam, "race"); // => OK
*
* // ... but not when accepting name and race
* assertThat(frodo).isLenientEqualsToByAcceptingFields(sam, "name", "race"); // => FAIL
*
*
*
* @param other the object to compare {@code actual} to.
* @param fields accepted fields for lenient equality.
* @throws NullPointerException if the actual type is {@code null}.
* @throws NullPointerException if the other type is {@code null}.
* @throws AssertionError if the actual and the given object are not lenient equals.
* @throws AssertionError if the other object is not an instance of the actual type.
* @throws IntrospectionError if a field does not exist in actual.
*/
public ObjectAssert isLenientEqualsToByAcceptingFields(T other, String... fields) {
objects.assertIsLenientEqualsToByAcceptingFields(info, actual, other, fields);
return this;
}
/**
* Assert that the actual object is lenient equals to given one by comparing actual and other fields (including
* inherited fields) except the given "ignored" fields.
*
*
* Example:
*
* TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
* TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);
*
* // frodo and sam both are lenient equals ignoring name and age since only remaining property is race and frodo and sam both are HOBBIT
* assertThat(frodo).isLenientEqualsToByIgnoringFields(sam, "name", "age"); //=> OK
*
* // ... but they are not lenient equals if only age is ignored because their names differ.
* assertThat(frodo).isLenientEqualsToByIgnoringFields(sam, "age"); //=> FAIL
*
*
*
* @param other the object to compare {@code actual} to.
* @param fields ignored fields for lenient equality.
* @throws NullPointerException if the actual type is {@code null}.
* @throws NullPointerException if the other type is {@code null}.
* @throws AssertionError if the actual and the given object are not lenient equals.
* @throws AssertionError if the other object is not an instance of the actual type.
*/
public ObjectAssert isLenientEqualsToByIgnoringFields(T other, String... fields) {
objects.assertIsLenientEqualsToByIgnoringFields(info, actual, other, fields);
return this;
}
/**
* Assert that the actual object is equals fields by fields to another object, inherited fields are taken into
* account.
*
* This can be handy if equals
implementation of objects to compare does not suit you.
*
*
* Example:
*
* TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
* TolkienCharacter frodoClone = new TolkienCharacter("Frodo", 33, HOBBIT);
*
* // Fail if equals has not been overriden in TolkienCharacter as equals default implementation only compares references
* assertThat(frodo).isEqualsTo(frodoClone); // Fail if equals has not been overriden in TolkienCharacter
*
* // frodo and frodoClone are equals by comparing fields
* assertThat(frodo).isEqualsToByComparingFields(frodoClone); // OK
*
*
*
* @param other the object to compare {@code actual} to.
* @throws NullPointerException if the actual type is {@code null}.
* @throws NullPointerException if the other type is {@code null}.
* @throws AssertionError if the actual and the given object are not equals fields by fields.
* @throws AssertionError if the other object is not an instance of the actual type.
*/
public ObjectAssert isEqualsToByComparingFields(T other) {
objects.assertIsLenientEqualsToByIgnoringFields(info, actual, other);
return this;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ShortArrayAssert.java 0000664 0000000 0000000 00000022157 12430205632 0027347 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 21, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.ArraySortedAssert;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.data.Index;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for arrays of {@code short}s.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(short[])}
.
*
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class ShortArrayAssert extends AbstractAssert implements
EnumerableAssert, ArraySortedAssert {
@VisibleForTesting
ShortArrays arrays = ShortArrays.instance();
protected ShortArrayAssert(short[] actual) {
super(actual, ShortArrayAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
arrays.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
arrays.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public ShortArrayAssert isNotEmpty() {
arrays.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert hasSize(int expected) {
arrays.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert hasSameSizeAs(Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert hasSameSizeAs(Iterable> other) {
arrays.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual array contains the given values, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values.
*/
public ShortArrayAssert contains(short... values) {
arrays.assertContains(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains only the given values and nothing else, in any order.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some or none of
* the given values, or the actual array contains more values than the given ones.
*/
public ShortArrayAssert containsOnly(short... values) {
arrays.assertContainsOnly(info, actual, values);
return this;
}
/**
* Verifies that the actual array contains the given sequence, without any other values between them.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual array does not contain the given sequence.
*/
public ShortArrayAssert containsSequence(short... sequence) {
arrays.assertContainsSequence(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array contains the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of the actual
* array.
* @throws AssertionError if the actual array does not contain the given value at the given index.
*/
public ShortArrayAssert contains(short value, Index index) {
arrays.assertContains(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain the given values.
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains any of the given values.
*/
public ShortArrayAssert doesNotContain(short... values) {
arrays.assertDoesNotContain(info, actual, values);
return this;
}
/**
* Verifies that the actual array does not contain the given value at the given index.
* @param value the value to look for.
* @param index the index where the value should be stored in the actual array.
* @return this assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the actual array contains the given value at the given index.
*/
public ShortArrayAssert doesNotContain(short value, Index index) {
arrays.assertDoesNotContain(info, actual, value, index);
return this;
}
/**
* Verifies that the actual array does not contain duplicates.
* @return {@code this} assertion object.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array contains duplicates.
*/
public ShortArrayAssert doesNotHaveDuplicates() {
arrays.assertDoesNotHaveDuplicates(info, actual);
return this;
}
/**
* Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(short...)}
, but it also verifies that the first element in the sequence is also first
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not start with the given sequence.
*/
public ShortArrayAssert startsWith(short... sequence) {
arrays.assertStartsWith(info, actual, sequence);
return this;
}
/**
* Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
* {@link #containsSequence(short...)}
, but it also verifies that the last element in the sequence is also last
* element of the actual array.
* @param sequence the sequence of values to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual array is {@code null}.
* @throws AssertionError if the actual array does not end with the given sequence.
*/
public ShortArrayAssert endsWith(short... sequence) {
arrays.assertEndsWith(info, actual, sequence);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert isSorted() {
arrays.assertIsSorted(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert isSortedAccordingTo(Comparator super Short> comparator) {
arrays.assertIsSortedAccordingToComparator(info, actual, comparator);
return this;
}
/** {@inheritDoc} */
public ShortArrayAssert usingElementComparator(Comparator super Short> customComparator) {
this.arrays = new ShortArrays(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
/** {@inheritDoc} */
public ShortArrayAssert usingDefaultElementComparator() {
this.arrays = ShortArrays.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ShortAssert.java 0000664 0000000 0000000 00000012666 12430205632 0026354 0 ustar 00root root 0000000 0000000 /*
* Created on Oct 20, 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.assertions.api;
import java.util.Comparator;
import org.fest.assertions.core.NumberAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for shorts.
*
* To create an instance of this class, invoke {@link Assertions#assertThat(Short)}
or
* {@link Assertions#assertThat(short)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Alex Ruiz
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class ShortAssert extends AbstractComparableAssert implements NumberAssert {
@VisibleForTesting
Shorts shorts = Shorts.instance();
protected ShortAssert(Short actual) {
super(actual, ShortAssert.class);
}
/**
* Verifies that the actual value is equal to the given one.
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public ShortAssert isEqualTo(short expected) {
shorts.assertEqual(info, actual, expected);
return this;
}
/**
* Verifies that the actual value is not equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public ShortAssert isNotEqualTo(short other) {
shorts.assertNotEqual(info, actual, other);
return this;
}
/** {@inheritDoc} */
public ShortAssert isZero() {
shorts.assertIsZero(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortAssert isNotZero() {
shorts.assertIsNotZero(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortAssert isPositive() {
shorts.assertIsPositive(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortAssert isNegative() {
shorts.assertIsNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortAssert isNotNegative() {
shorts.assertIsNotNegative(info, actual);
return this;
}
/** {@inheritDoc} */
public ShortAssert isNotPositive() {
shorts.assertIsNotPositive(info, actual);
return this;
}
/**
* Verifies that the actual value is less than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or greater than the given one.
*/
public ShortAssert isLessThan(short other) {
shorts.assertLessThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is less than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is greater than the given one.
*/
public ShortAssert isLessThanOrEqualTo(short other) {
shorts.assertLessThanOrEqualTo(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to or less than the given one.
*/
public ShortAssert isGreaterThan(short other) {
shorts.assertGreaterThan(info, actual, other);
return this;
}
/**
* Verifies that the actual value is greater than or equal to the given one.
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is less than the given one.
*/
public ShortAssert isGreaterThanOrEqualTo(short other) {
shorts.assertGreaterThanOrEqualTo(info, actual, other);
return this;
}
@Override
public ShortAssert usingComparator(Comparator super Short> customComparator) {
super.usingComparator(customComparator);
this.shorts = new Shorts(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public ShortAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.shorts = Shorts.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/StringAssert.java 0000664 0000000 0000000 00000022247 12430205632 0026517 0 ustar 00root root 0000000 0000000 /*
* Created on Dec 22, 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.assertions.api;
import java.util.Comparator;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.fest.assertions.core.EnumerableAssert;
import org.fest.assertions.internal.*;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@code String}s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(String)}
.
*
*
* @author Yvonne Wang
* @author David DIDIER
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas Francois
*/
public class StringAssert extends AbstractAssert implements EnumerableAssert {
@VisibleForTesting
Strings strings = Strings.instance();
protected StringAssert(String actual) {
super(actual, StringAssert.class);
}
/** {@inheritDoc} */
public void isNullOrEmpty() {
strings.assertNullOrEmpty(info, actual);
}
/** {@inheritDoc} */
public void isEmpty() {
strings.assertEmpty(info, actual);
}
/** {@inheritDoc} */
public StringAssert isNotEmpty() {
strings.assertNotEmpty(info, actual);
return this;
}
/** {@inheritDoc} */
public StringAssert hasSize(int expected) {
strings.assertHasSize(info, actual, expected);
return this;
}
/** {@inheritDoc} */
public StringAssert hasSameSizeAs(Object[] other) {
strings.assertHasSameSizeAs(info, actual, other);
return this;
}
/** {@inheritDoc} */
public StringAssert hasSameSizeAs(Iterable> other) {
strings.assertHasSameSizeAs(info, actual, other);
return this;
}
/**
* Verifies that the actual {@code String} is equal to the given one, ignoring case considerations.
* @param expected the given {@code String} to compare the actual {@code String} to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code String} is not equal to the given one.
*/
public StringAssert isEqualToIgnoringCase(String expected) {
strings.assertEqualsIgnoringCase(info, actual, expected);
return this;
}
/**
* Verifies that the actual {@code String} contains only once the given sequence.
*
* @param sequence the sequence to search for.
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code String} does not contain the given one, or contain it multiple times.
*/
public StringAssert containsOnlyOnce(String sequence) {
strings.assertContainsOnlyOnce(info, actual, sequence);
return this;
}
/**
* Verifies that the actual {@code String} contains the given sequence.
*
* @param sequence the sequence to search for.
* @return {@code this} assertion object.
* @throws NullPointerException if the given sequence is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not contain the given one.
*/
public StringAssert contains(String sequence) {
strings.assertContains(info, actual, sequence);
return this;
}
/**
* Verifies that the actual {@code String} contains the given sequence, ignoring case considerations.
* @param sequence the sequence to search for.
* @return {@code this} assertion object.
* @throws NullPointerException if the given sequence is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not contain the given one.
*/
public StringAssert containsIgnoringCase(String sequence) {
strings.assertContainsIgnoringCase(info, actual, sequence);
return this;
}
/**
* Verifies that the actual {@code String} does not contain the given sequence.
* @param sequence the sequence to search for.
* @return {@code this} assertion object.
* @throws NullPointerException if the given sequence is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} contains the given one.
*/
public StringAssert doesNotContain(String sequence) {
strings.assertDoesNotContain(info, actual, sequence);
return this;
}
/**
* Verifies that the actual {@code String} starts with the given prefix.
* @param prefix the given prefix.
* @return {@code this} assertion object.
* @throws NullPointerException if the given prefix is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not start with the given prefix.
*/
public StringAssert startsWith(String prefix) {
strings.assertStartsWith(info, actual, prefix);
return this;
}
/**
* Verifies that the actual {@code String} ends with the given suffix.
* @param suffix the given suffix.
* @return {@code this} assertion object.
* @throws NullPointerException if the given suffix is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not end with the given suffix.
*/
public StringAssert endsWith(String suffix) {
strings.assertEndsWith(info, actual, suffix);
return this;
}
/**
* Verifies that the actual {@code String} matches the given regular expression.
* @param regex the regular expression to which the actual {@code String} is to be matched.
* @return {@code this} assertion object.
* @throws NullPointerException if the given pattern is {@code null}.
* @throws PatternSyntaxException if the regular expression's syntax is invalid.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not match the given regular expression.
*/
public StringAssert matches(String regex) {
strings.assertMatches(info, actual, regex);
return this;
}
/**
* Verifies that the actual {@code String} does not match the given regular expression.
* @param regex the regular expression to which the actual {@code String} is to be matched.
* @return {@code this} assertion object.
* @throws NullPointerException if the given pattern is {@code null}.
* @throws PatternSyntaxException if the regular expression's syntax is invalid.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} matches the given regular expression.
*/
public StringAssert doesNotMatch(String regex) {
strings.assertDoesNotMatch(info, actual, regex);
return this;
}
/**
* Verifies that the actual {@code String} matches the given regular expression.
* @param pattern the regular expression to which the actual {@code String} is to be matched.
* @return {@code this} assertion object.
* @throws NullPointerException if the given pattern is {@code null}.
* @throws AssertionError if the actual {@code String} is {@code null}.
* @throws AssertionError if the actual {@code String} does not match the given regular expression.
*/
public StringAssert matches(Pattern pattern) {
strings.assertMatches(info, actual, pattern);
return this;
}
/**
* Verifies that the actual {@code String} does not match the given regular expression.
* @param pattern the regular expression to which the actual {@code String} is to be matched.
* @return {@code this} assertion object.
* @throws NullPointerException if the given pattern is {@code null}.
* @throws AssertionError if the actual {@code String} does not match the given regular expression.
*/
public StringAssert doesNotMatch(Pattern pattern) {
strings.assertDoesNotMatch(info, actual, pattern);
return this;
}
/** {@inheritDoc} */
public StringAssert usingElementComparator(Comparator super String> customComparator) {
// TODO maybe use Comparator super Character>
throw new UnsupportedOperationException("custom element Comparator is not supported for String comparison");
}
/** {@inheritDoc} */
public StringAssert usingDefaultElementComparator() {
throw new UnsupportedOperationException("custom element Comparator is not supported for String comparison");
}
@Override
public StringAssert usingComparator(Comparator super String> customComparator) {
super.usingComparator(customComparator);
this.strings = new Strings(new ComparatorBasedComparisonStrategy(customComparator));
return myself;
}
@Override
public StringAssert usingDefaultComparator() {
super.usingDefaultComparator();
this.strings = Strings.instance();
return myself;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/ThrowableAssert.java 0000664 0000000 0000000 00000007726 12430205632 0027205 0 ustar 00root root 0000000 0000000 /*
* Created on Jan 28, 2011
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this Throwable 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.assertions.api;
import org.fest.assertions.internal.Throwables;
import org.fest.util.VisibleForTesting;
/**
* Assertion methods for {@link Throwable}
s.
*
* To create a new instance of this class, invoke {@link Assertions#assertThat(Throwable)}
.
*
*
* @author David DIDIER
* @author Alex Ruiz
* @author Joel Costigliola
*/
public class ThrowableAssert extends AbstractAssert {
@VisibleForTesting
Throwables throwables = Throwables.instance();
protected ThrowableAssert(Throwable actual) {
super(actual, ThrowableAssert.class);
}
/**
* Verifies that the message of the actual {@code Throwable} is equal to the given one.
* @param message the expected message.
* @return this assertion object.
* @throws AssertionError if the actual {@code Throwable} is {@code null}.
* @throws AssertionError if the message of the actual {@code Throwable} is not equal to the given one.
*/
public ThrowableAssert hasMessage(String message) {
throwables.assertHasMessage(info, actual, message);
return this;
}
/**
* Verifies that the actual {@code Throwable} does not have a cause.
* @return this assertion object.
* @throws AssertionError if the actual {@code Throwable} is {@code null}.
* @throws AssertionError if the actual {@code Throwable} has a cause.
*/
public ThrowableAssert hasNoCause() {
throwables.assertHasNoCause(info, actual);
return this;
}
/**
* Verifies that the message of the actual {@code Throwable} starts with the given description.
* @param description the description expected to start the actual {@code Throwable}'s message.
* @return this assertion object.
* @throws AssertionError if the actual {@code Throwable} is {@code null}.
* @throws AssertionError if the message of the actual {@code Throwable} does not start with the given description.
*/
public ThrowableAssert hasMessageStartingWith(String description) {
throwables.assertHasMessageStartingWith(info, actual, description);
return this;
}
/**
* Verifies that the message of the actual {@code Throwable} contains with the given description.
* @param description the description expected to be contained in the actual {@code Throwable}'s message.
* @return this assertion object.
* @throws AssertionError if the actual {@code Throwable} is {@code null}.
* @throws AssertionError if the message of the actual {@code Throwable} does not contain the given description.
*/
public ThrowableAssert hasMessageContaining(String description) {
throwables.assertHasMessageContaining(info, actual, description);
return this;
}
/**
* Verifies that the message of the actual {@code Throwable} ends with the given description.
* @param description the description expected to end the actual {@code Throwable}'s message.
* @return this assertion object.
* @throws AssertionError if the actual {@code Throwable} is {@code null}.
* @throws AssertionError if the message of the actual {@code Throwable} does not end with the given description.
*/
public ThrowableAssert hasMessageEndingWith(String description) {
throwables.assertHasMessageEndingWith(info, actual, description);
return this;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/api/filter/ 0000775 0000000 0000000 00000000000 12430205632 0024502 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/assertions/api/filter/Filters.java 0000664 0000000 0000000 00000040571 12430205632 0026764 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 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.assertions.api.filter;
import static org.fest.util.Lists.newArrayList;
import static org.fest.util.Objects.areEqual;
import java.util.ArrayList;
import java.util.List;
import org.fest.assertions.core.Condition;
import org.fest.assertions.internal.PropertySupport;
import org.fest.util.IntrospectionError;
import org.fest.util.VisibleForTesting;
/**
* Filters the elements of a given {@link Iterable}
or array according to the specified filter criteria.
*
* Filter criteria can be expressed either by a {@link Condition} or a pseudo filter language on elements properties.
*
* Note that the given {@link Iterable} or array is not modified, the filters are performed on a copy.
*
* With {@link Condition} :
*
*
* List<Player> players = ...;
*
* Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){
* public boolean matches(Player player) {
* return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7;
* };
* };
*
* // use filter static method to build Filters
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose)
*
*
* With pseudo filter language on element properties :
*
*
* assertThat(filter(players).with("pointsPerGame").greaterThan(20)
* .and("assistsPerGame").greaterThan(7)
* .get()).containsOnly(james, rose);
*
* @param the type of element of group to filter.
*
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class Filters {
// initialIterable is never modified, it represents the group before any filters have been performed
@VisibleForTesting
final Iterable initialIterable;
Iterable filteredIterable;
private PropertySupport propertySupport = PropertySupport.instance();
/**
* The name of the property used for filtering.
*/
private String propertyNameToFilterOn;
/**
* Creates a new {@link Filters}
with the {@link Iterable} to filter.
*
* Chain this call to express filter criteria either by a {@link Condition} or a pseudo filter language on elements properties.
*
* Note that the given {@link Iterable} is not modified, the filters are performed on a copy.
*
* - With {@link Condition} :
*
*
* List<Player> players = ...;
*
* Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){
* public boolean matches(Player player) {
* return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7;
* };
* };
*
* // use filter static method to build Filters
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose)
*
*
* - With pseudo filter language on element properties :
*
*
* assertThat(filter(players).with("pointsPerGame").greaterThan(20)
* .and("assistsPerGame").greaterThan(7).get())
* .containsOnly(james, rose);
*
* @param iterable the {@code Iterable} to filter.
* @throws NullPointerException if the given iterable is {@code null}.
* @return the created {@link Filters}
.
*/
public static Filters filter(Iterable iterable) {
if (iterable == null) throw new NullPointerException("The iterable to filter should not be null");
return new Filters(iterable);
}
/**
* Creates a new {@link Filters}
with the array to filter.
*
* Chain this call to express filter criteria either by a {@link Condition} or a pseudo filter language on elements properties.
*
* Note that the given array is not modified, the filters are performed on an {@link Iterable} copy of the array.
*
* With {@link Condition} :
*
*
* List<Player> players = ...;
*
* Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP"){
* public boolean matches(Player player) {
* return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7;
* };
* };
*
* // use filter static method to build Filters
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
*
*
* With pseudo filter language on element properties :
*
*
* assertThat(filter(players).with("pointsPerGame").greaterThan(20)
* .and("assistsPerGame").greaterThan(7)
* .get()).containsOnly(james, rose);
* @param array the array to filter.
* @throws NullPointerException if the given array is {@code null}.
* @return the created {@link Filters}
.
*/
public static Filters filter(E[] array) {
if (array == null) throw new NullPointerException("The array to filter should not be null");
return new Filters(array);
}
@VisibleForTesting
Filters(Iterable iterable) {
this.initialIterable = iterable;
// copy list to avoid modifying iterable
this.filteredIterable = newArrayList(iterable);
}
@VisibleForTesting
Filters(E[] array) {
List iterable = new ArrayList(array.length);
for (int i = 0; i < array.length; i++) {
iterable.add(array[i]);
}
this.initialIterable = iterable;
// copy list to avoid modifying iterable
this.filteredIterable = newArrayList(iterable);
}
/**
* Filter the underlying group, keeping only elements satisfying the given {@link Condition}.
* Same as {@link #having(Condition)} - pick the method you prefer to have the most readable code.
*
*
* List<Player> players = ...;
*
* Condition<Player> potentialMVP = new Condition<Player>("is a possible MVP") {
* public boolean matches(Player player) {
* return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7;
* };
* };
*
* // use filter static method to build Filters
* assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
*
* @param condition the filter {@link Condition}.
* @return this {@link Filters} to chain other filter operations.
* @throws NullPointerException if the given condition is {@code null}.
*/
public Filters being(Condition super E> condition) {
if (condition == null) throw new NullPointerException("The filter condition should not be null");
return applyFilterCondition(condition);
}
/**
* Filter the underlying group, keeping only elements satisfying the given {@link Condition}.
* Same as {@link #being(Condition)} - pick the method you prefer to have the most readable code.
*
*
* List<Player> players = ...;
*
* Condition<Player> mvpStats = new Condition<Player>("is a possible MVP") {
* public boolean matches(Player player) {
* return player.getPointsPerGame() > 20 && player.getAssistsPerGame() > 7;
* };
* };
*
* // use filter static method to build Filters
* assertThat(filter(players).having(mvpStats).get()).containsOnly(james, rose);
*
* @param condition the filter {@link Condition}.
* @return this {@link Filters} to chain other filter operations.
* @throws NullPointerException if the given condition is {@code null}.
*/
public Filters having(Condition super E> condition) {
if (condition == null) throw new NullPointerException("The filter condition should not be null");
return applyFilterCondition(condition);
}
private Filters applyFilterCondition(Condition super E> condition) {
List newFilteredIterable = new ArrayList();
for (E element : filteredIterable) {
if (condition.matches(element)) {
newFilteredIterable.add(element);
}
}
this.filteredIterable = newFilteredIterable;
return this;
}
/**
* Filter the underlying group, keeping only elements with a property equals to given value.
*
* Let's, for example, filter Employees with name "Alex" :
*
*
* filter(employees).with("name", "Alex").get();
*
* which is shortcut of :
*
*
* filter(employees).with("name").equalsTo("Alex").get();
*
*
* @param propertyName the name of the property whose value will compared to given value. It may be a nested property.
* @param propertyValue the expected property value.
* @return this {@link Filters} to chain other filter operations.
* @throws IntrospectionError if an element in the given {@code Iterable} does not have a property with a given propertyName.
* @throws NullPointerException if the given propertyName is {@code null}.
*/
public Filters with(String propertyName, Object propertyValue) {
if (propertyName == null) throw new NullPointerException("The property name to filter on should not be null");
propertyNameToFilterOn = propertyName;
return equalsTo(propertyValue);
}
/**
* Sets the name of the property used for filtering, it may be a nested property like "adress.street.name"
.
*
* The typical usage is to chain this call with a comparison method, for example :
*
*
* filter(employees).with("name").equalsTo("Alex").get();
*
*
* @param propertyName the name of the property used for filtering. It may be a nested property.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the given propertyName is {@code null}.
*/
public Filters with(String propertyName) {
if (propertyName == null) throw new NullPointerException("The property name to filter on should not be null");
propertyNameToFilterOn = propertyName;
return this;
}
/**
* Alias of {@link #with(String)} for synthetic sugar to write things like :.
*
*
* filter(employees).with("name").equalsTo("Alex").and("job").notEqualsTo("lawyer").get();
*
*
* @param propertyName the name of the property used for filtering. It may be a nested property.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the given propertyName is {@code null}.
*/
public Filters and(String propertyName) {
return with(propertyName);
}
/**
* Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) equals to given
* value.
*
* Typical usage :
*
*
* filter(employees).with("name").equalsTo("Luke").get();
*
*
* @param propertyValue the filter value.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the property name to filter on has not been set.
*/
public Filters equalsTo(Object propertyValue) {
checkPropertyNameToFilterOnIsNotNull();
List newFilteredIterable = new ArrayList();
for (E element : filteredIterable) {
// As we don't know the propertyValue class, we use Object.class
Class extends Object> propertyValueClass = propertyValue == null ? Object.class : propertyValue.getClass();
Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValueClass, element);
if (areEqual(propertyValueOfCurrentElement, propertyValue)) {
newFilteredIterable.add(element);
}
}
this.filteredIterable = newFilteredIterable;
return this;
}
/**
* Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) not equals to given
* value.
*
* Typical usage :
*
*
* filter(employees).with("name").notEqualsTo("Vader").get();
*
*
* @param propertyValue the filter value.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the property name to filter on has not been set.
*/
public Filters notEqualsTo(Object propertyValue) {
checkPropertyNameToFilterOnIsNotNull();
List newFilteredIterable = new ArrayList();
for (E element : filteredIterable) {
Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValue.getClass(),
element);
if (!areEqual(propertyValueOfCurrentElement, propertyValue)) {
newFilteredIterable.add(element);
}
}
this.filteredIterable = newFilteredIterable;
return this;
}
private void checkPropertyNameToFilterOnIsNotNull() {
if (propertyNameToFilterOn == null)
throw new NullPointerException("The property name to filter on has not been set - no filtering is possible");
}
/**
* Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) equals to one of the
* given values.
*
* Typical usage :
*
*
* filter(players).with("team").in("Bulls", "Lakers").get();
*
*
* @param propertyValues the filter values.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the property name to filter on has not been set.
*/
public Filters in(Object... propertyValues) {
checkPropertyNameToFilterOnIsNotNull();
List newFilteredIterable = new ArrayList();
for (E element : filteredIterable) {
Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValues.getClass()
.getComponentType(), element);
if (isItemInArray(propertyValueOfCurrentElement, propertyValues)) {
newFilteredIterable.add(element);
}
}
this.filteredIterable = newFilteredIterable;
return this;
}
/**
* Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) not in the given
* values.
*
* Typical usage :
*
*
* filter(players).with("team").notIn("Heat", "Lakers").get();
*
*
* @param propertyValues the filter values.
* @return this {@link Filters} to chain other filter operation.
* @throws NullPointerException if the property name to filter on has not been set.
*/
public Filters notIn(Object... propertyValues) {
checkPropertyNameToFilterOnIsNotNull();
List newFilteredIterable = new ArrayList();
for (E element : filteredIterable) {
Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValues.getClass()
.getComponentType(), element);
if (!isItemInArray(propertyValueOfCurrentElement, propertyValues)) {
newFilteredIterable.add(element);
}
}
this.filteredIterable = newFilteredIterable;
return this;
}
/**
* Returns true
if given item is in given array, false
otherwise.
* @param item the object to look for in arrayOfValues
* @param arrayOfValues the array of values
* @return true
if given item is in given array, false
otherwise.
*/
private static boolean isItemInArray(Object item, Object[] arrayOfValues) {
for (Object value : arrayOfValues)
if (areEqual(value, item)) return true;
return false;
}
/**
* Returns the resulting filtered Iterable<E> (even if the constructor parameter type was an array).
* @return the Iterable<E> containing the filtered elements.
*/
public Iterable get() {
return filteredIterable;
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/condition/ 0000775 0000000 0000000 00000000000 12430205632 0024432 5 ustar 00root root 0000000 0000000 fest-assert-2.0M10/src/main/java/org/fest/assertions/condition/AllOf.java 0000664 0000000 0000000 00000004611 12430205632 0026274 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 7, 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.assertions.condition;
import org.fest.assertions.core.Condition;
/**
* Returns {@code true} if all of the joined conditions is satisfied.
* @param the type of object this condition accepts.
*
* @author Yvonne Wang
* @author Mikhail Mazursky
*/
public class AllOf extends Join {
/**
* Creates a new {@link AllOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given array is {@code null}.
* @throws NullPointerException if any of the elements in the given array is {@code null}.
*/
public static Condition allOf(Condition super T>... conditions) {
return new AllOf(conditions);
}
/**
* Creates a new {@link AllOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given iterable is {@code null}.
* @throws NullPointerException if any of the elements in the given iterable is {@code null}.
*/
public static Condition allOf(Iterable extends Condition super T>> conditions) {
return new AllOf(conditions);
}
private AllOf(Condition super T>... conditions) {
super(conditions);
}
private AllOf(Iterable extends Condition super T>> conditions) {
super(conditions);
}
/** {@inheritDoc} */
@Override
public boolean matches(T value) {
for (Condition super T> condition : conditions)
if (!condition.matches(value)) return false;
return true;
}
@Override
public String toString() {
return String.format("all of:<%s>", conditions);
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/condition/AnyOf.java 0000664 0000000 0000000 00000004610 12430205632 0026312 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 5, 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.assertions.condition;
import org.fest.assertions.core.Condition;
/**
* Returns {@code true} if any of the joined conditions is satisfied.
* @param the type of object this condition accepts.
*
* @author Yvonne Wang
* @author Mikhail Mazursky
*/
public class AnyOf extends Join {
/**
* Creates a new {@link AnyOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given array is {@code null}.
* @throws NullPointerException if any of the elements in the given array is {@code null}.
*/
public static Condition anyOf(Condition super T>... conditions) {
return new AnyOf(conditions);
}
/**
* Creates a new {@link AnyOf}
* @param the type of object the given condition accept.
* @param conditions the conditions to evaluate.
* @return the created {@code AnyOf}.
* @throws NullPointerException if the given iterable is {@code null}.
* @throws NullPointerException if any of the elements in the given iterable is {@code null}.
*/
public static Condition anyOf(Iterable extends Condition super T>> conditions) {
return new AnyOf(conditions);
}
private AnyOf(Condition super T>... conditions) {
super(conditions);
}
private AnyOf(Iterable extends Condition super T>> conditions) {
super(conditions);
}
/** {@inheritDoc} */
@Override
public boolean matches(T value) {
for (Condition super T> condition : conditions)
if (condition.matches(value)) return true;
return false;
}
@Override
public String toString() {
return String.format("any of:<%s>", conditions);
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/condition/DoesNotHave.java 0000664 0000000 0000000 00000002656 12430205632 0027465 0 ustar 00root root 0000000 0000000 /*
* Created on Mar 22, 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.assertions.condition;
import org.fest.assertions.core.Condition;
/**
* Returns {@code true} if the condition is not satisfied.
*
* @author Nicolas François
* @author Joel Costigliola
* @author Mikhail Mazursky
*/
public class DoesNotHave extends Negative {
/**
* Creates a new {@link DoesNotHave}.
*
* @param condition the condition to inverse.
* @return The Not condition created.
*/
public static DoesNotHave doesNotHave(Condition super T> condition) {
return new DoesNotHave(condition);
}
private DoesNotHave(Condition super T> condition) {
super(condition);
}
@Override
public String toString() {
return String.format("does not have :<%s>", condition);
}
}
fest-assert-2.0M10/src/main/java/org/fest/assertions/condition/Join.java 0000664 0000000 0000000 00000005400 12430205632 0026173 0 ustar 00root root 0000000 0000000 /*
* Created on Feb 6, 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.assertions.condition;
import static java.util.Collections.unmodifiableCollection;
import java.util.*;
import org.fest.assertions.core.Condition;
import org.fest.util.VisibleForTesting;
/**
* Join of two or more {@link Condition}
s.
* @param the type of object this condition accepts.
*
* @author Yvonne Wang
* @author Mikhail Mazursky
*/
public abstract class Join extends Condition {
@VisibleForTesting
final Collection> conditions;
/**
* Creates a new {@link Join}.
* @param conditions the conditions to join.
* @throws NullPointerException if the given array is {@code null}.
* @throws NullPointerException if any of the elements in the given array is {@code null}.
*/
protected Join(Condition super T>... conditions) {
if (conditions == null) throw conditionsIsNull();
this.conditions = new ArrayList>();
for (Condition super T> condition : conditions)
this.conditions.add(notNull(condition));
}
/**
* Creates a new {@link Join}.
* @param conditions the conditions to join.
* @throws NullPointerException if the given iterable is {@code null}.
* @throws NullPointerException if any of the elements in the given iterable is {@code null}.
*/
protected Join(Iterable extends Condition super T>> conditions) {
if (conditions == null) throw conditionsIsNull();
this.conditions = new ArrayList>();
for (Condition super T> condition : conditions)
this.conditions.add(notNull(condition));
}
private static NullPointerException conditionsIsNull() {
return new NullPointerException("The given conditions should not be null");
}
private static Condition