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 Maps (as suggested in assertj/ass…
- Loading branch information
1 parent
89cfb4f
commit 608ede7
Showing
6 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/org/assertj/core/api/AbstractMapSizeAssert.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,25 @@ | ||
/** | ||
* 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.Map; | ||
|
||
public abstract class AbstractMapSizeAssert<S extends AbstractMapAssert<S, A, K, V>, A extends Map<K, V>, K, V> | ||
extends AbstractIntegerAssert<AbstractMapSizeAssert<S, A, K, V>> { | ||
|
||
protected AbstractMapSizeAssert(Integer actual, Class<?> selfType) { | ||
super(actual, selfType); | ||
} | ||
|
||
public abstract AbstractMapAssert<S, A, K, V> returnToMap(); | ||
} |
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.Map; | ||
|
||
public class MapSizeAssert<K, V> extends AbstractMapSizeAssert<MapAssert<K, V>, Map<K, V>, K, V> { | ||
|
||
private AbstractMapAssert<MapAssert<K, V>, Map<K, V>, K, V> source; | ||
|
||
public MapSizeAssert(AbstractMapAssert<MapAssert<K, V>, Map<K, V>, K, V> source, Integer i) { | ||
super(i, MapSizeAssert.class); | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
public AbstractMapAssert<MapAssert<K, V>, Map<K, V>, K, V> returnToMap() { | ||
return source; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/test/java/org/assertj/core/api/map/MapAssert_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,48 @@ | ||
/** | ||
* 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.map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.data.MapEntry.entry; | ||
import static org.assertj.core.test.ExpectedException.none; | ||
import static org.assertj.core.test.Maps.mapOf; | ||
|
||
import java.util.Map; | ||
|
||
import org.assertj.core.test.ExpectedException; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class MapAssert_size_Test { | ||
|
||
@Rule | ||
public ExpectedException thrown = none(); | ||
|
||
@Test | ||
@SuppressWarnings("unchecked") | ||
public void should_be_able_to_use_integer_assertions_on_size_the_map_size() { | ||
Map<String, String> stringToString = mapOf(entry("a", "1"), entry("b", "2")); | ||
// @format:off | ||
assertThat(stringToString).size().isGreaterThan(0) | ||
.isLessThanOrEqualTo(3) | ||
.returnToMap().contains(entry("a", "1")); | ||
// @format:on | ||
} | ||
|
||
@Test | ||
public void should_have_an_helpful_error_message_when_size_is_used_on_a_null_map() { | ||
Map<String, String> nullMap = null; | ||
thrown.expectNullPointerException("Can not perform assertions on the size of a null map."); | ||
assertThat(nullMap).size().isGreaterThan(1); | ||
} | ||
} |