forked from assertj/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable fluent assertions on size of list assertj#301, assertj#589
- Loading branch information
1 parent
5fcd421
commit 5388605
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/assertj/core/api/AbstractSizeAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* 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-2016 the original author or authors. | ||
*/ | ||
package org.assertj.core.api; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractSizeAssert<S extends AbstractListAssert<S, A, T>, A extends List<? extends T>, T> extends AbstractIntegerAssert<SizeAssert<T, Integer>>{ | ||
|
||
protected AbstractSizeAssert(Integer actual, Class<?> selfType) { | ||
super(actual, selfType); | ||
} | ||
|
||
public abstract AbstractListAssert<S, A, T> returnToList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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-2016 the original author or authors. | ||
*/ | ||
package org.assertj.core.api; | ||
|
||
import java.util.List; | ||
|
||
public class SizeAssert<T, U> extends AbstractSizeAssert<ListAssert<T>, List<? extends T>, T>{ | ||
|
||
private AbstractListAssert<ListAssert<T>, List<? extends T>, T> source; | ||
|
||
public SizeAssert(AbstractListAssert<ListAssert<T>, List<? extends T>, T> source, Integer i) { | ||
super(i, SizeAssert.class); | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
public AbstractListAssert<ListAssert<T>, List<? extends T>, T> returnToList() { | ||
return source; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/org/assertj/core/api/list/ListAssert_size_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* 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-2016 the original author or authors. | ||
*/ | ||
package org.assertj.core.api.list; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.test.ExpectedException.none; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.assertj.core.test.ExpectedException; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
|
||
public class ListAssert_size_Test { | ||
|
||
@Rule | ||
public ExpectedException thrown = none(); | ||
|
||
@Test | ||
public void should_be_able_to_use_integer_assertions_on_size_of_list() { | ||
List<String> strings = Arrays.asList("a", "b", "c"); | ||
assertThat(strings).size().isGreaterThan(0).isLessThanOrEqualTo(3).returnToList().contains("a").doesNotContain("d"); | ||
|
||
List<Integer> integers = Arrays.asList(1, 2, 3); | ||
assertThat(integers).size().isGreaterThan(0).isLessThanOrEqualTo(3).returnToList().contains(1).doesNotContain(4); | ||
} | ||
|
||
@Test | ||
public void should_have_nice_error_message_when_size_is_used_on_list_which_is_null() { | ||
List<Integer> nullList = null; | ||
thrown.expectNullPointerException("Can not assert on size of list which is Null."); | ||
assertThat(nullList).size().isGreaterThan(1); | ||
} | ||
} |