├── src ├── test │ ├── resources │ │ └── junit-platform.properties │ └── java │ │ └── org │ │ └── assertj │ │ └── guava │ │ ├── api │ │ ├── TableAssertBaseTest.java │ │ ├── RangeMapAssertBaseTest.java │ │ ├── MultimapAssertBaseTest.java │ │ ├── Assertions_assertThat_with_Optional_Test.java │ │ ├── Assertions_assertThat_with_Multimap_Test.java │ │ ├── RangeMapAssert_isNotEmpty_Test.java │ │ ├── MultimapAssert_isNotEmpty_Test.java │ │ ├── RangeMapAssert_isEmpty_Test.java │ │ ├── RangeSetAssert_isNullOrEmpty_Test.java │ │ ├── TableAssert_isEmpty_Test.java │ │ ├── RangeSetAssert_isEmpty_Test.java │ │ ├── RangeSetAssert_isNotEmpty_Test.java │ │ ├── RangeAssert_isEmpty_Test.java │ │ ├── ByteSourceAssert_isEmpty_Test.java │ │ ├── RangeAssert_isNotEmpty_Test.java │ │ ├── OptionalAssert_extractingValue_Test.java │ │ ├── OptionalAssert_isAbsent_Test.java │ │ ├── OptionalAssert_isPresent_Test.java │ │ ├── MultimapAssert_isEmpty_Test.java │ │ ├── MultimapAssert_hasSize_Test.java │ │ ├── RangeAssert_hasClosedLowerBound_Test.java │ │ ├── ByteSourceAssert_hasSize_Test.java │ │ ├── RangeAssert_hasClosedUpperBound_Test.java │ │ ├── RangeAssert_hasOpenedLowerBound_Test.java │ │ ├── RangeAssert_hasOpenedUpperBound_Test.java │ │ ├── ByteSourceAssert_hasSameContentAs_Test.java │ │ ├── TableAssert_hasSize_Test.java │ │ ├── RangeAssert_doesNotContain_Test.java │ │ ├── RangeAssert_hasUpperEndpointEqualTo_Test.java │ │ ├── TableAssert_hasRowCount_Test.java │ │ ├── RangeAssert_hasLowerEndpointEqualTo_Test.java │ │ ├── TableAssert_hasColumnCount_Test.java │ │ ├── OptionalAssert_extractingCharSequence_Test.java │ │ ├── RangeSetAssert_hasSize_Test.java │ │ ├── MultimapAssert_contains_Test.java │ │ ├── TableAssert_containsRows_Test.java │ │ ├── RangeMapAssert_contains_Test.java │ │ ├── TableAssert_containsColumns_Test.java │ │ ├── OptionalAssert_contains_Test.java │ │ ├── TableAssert_containsValues_Test.java │ │ ├── RangeSetAssert_doesNotContain_Test.java │ │ ├── MultisetAssert_containsAtMost_Test.java │ │ ├── MultisetAssert_containsAtLeast_Test.java │ │ ├── RangeSetAssert_doesNotContainAll_Test.java │ │ ├── RangeSetAssert_doesNotEnclose_Test.java │ │ ├── RangeSetAssert_doesNotIntersect_Test.java │ │ ├── RangeSetAssert_containsAnyOf_Test.java │ │ ├── TableAssert_containsCells_Test.java │ │ └── RangeSetAssert_doesNotEncloseAnyRangesOf_with_Iterable_Test.java │ │ ├── testkit │ │ ├── AssertionErrors.java │ │ └── junit │ │ │ └── jupiter │ │ │ ├── DefaultDisplayNameGenerator.java │ │ │ └── DefaultDisplayNameGeneratorTest.java │ │ └── error │ │ ├── ShouldHaveSameContentTest_create_Test.java │ │ ├── RangeSetShouldEncloseAnyOf_create_Test.java │ │ ├── RangeSetShouldIntersectAnyOf_create_Test.java │ │ ├── RangeSetShouldEnclose_create_Test.java │ │ ├── RangeSetShouldNotEnclose_create_Test.java │ │ ├── RangeSetShouldIntersect_create_Test.java │ │ └── RangeSetShouldNotIntersect_create_Test.java └── main │ └── java │ └── org │ └── assertj │ └── guava │ ├── error │ ├── ShouldHaveSameContent.java │ ├── OptionalShouldBeAbsent.java │ ├── OptionalShouldBePresent.java │ ├── RangeSetShouldNotEnclose.java │ ├── TableShouldContainRows.java │ ├── RangeSetShouldEncloseAnyOf.java │ ├── RangeShouldBeClosedInTheLowerBound.java │ ├── RangeShouldBeClosedInTheUpperBound.java │ ├── RangeShouldBeOpenedInTheLowerBound.java │ ├── RangeShouldBeOpenedInTheUpperBound.java │ ├── TableShouldContainColumns.java │ ├── RangeSetShouldIntersectAnyOf.java │ ├── ShouldContainValues.java │ ├── RangeSetShouldEnclose.java │ ├── RangeSetShouldNotIntersect.java │ ├── RangeSetShouldIntersect.java │ ├── TableShouldHaveRowCount.java │ ├── MultisetShouldContainTimes.java │ ├── OptionalShouldBePresentWithValue.java │ ├── TableShouldHaveColumnCount.java │ ├── MultisetShouldContainAtMostTimes.java │ ├── ShouldHaveSize.java │ ├── MultisetShouldContainAtLeastTimes.java │ ├── ShouldContainKeys.java │ ├── RangeShouldHaveLowerEndpointEqual.java │ ├── RangeShouldHaveUpperEndpointEqual.java │ └── TableShouldContainCell.java │ ├── util │ └── ExceptionUtils.java │ └── data │ └── MapEntry.java ├── .gitignore ├── .github ├── dependabot.yml └── workflows │ ├── release.yml │ ├── main.yml │ └── codeql-analysis.yml ├── .editorconfig ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── README.md ├── CONTRIBUTING.md └── verify.bndrun /src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.displayname.generator.default=org.assertj.guava.testkit.junit.jupiter.DefaultDisplayNameGenerator 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | /target 8 | /.classpath 9 | /.project 10 | .idea 11 | *.iml 12 | *.iws 13 | *.ipr 14 | .settings 15 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: https://editorconfig.org/ 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | 12 | # 2 space indentation for java, xml and yml files 13 | [*.{java,xml,yml,sh}] 14 | indent_style = space 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | release: 8 | 9 | name: Release to Maven Central 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Set up Maven Central 15 | uses: actions/setup-java@v3 16 | with: 17 | distribution: 'zulu' 18 | java-version: 17 19 | server-id: ossrh 20 | server-username: OSSRH_USERNAME 21 | server-password: OSSRH_TOKEN 22 | gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} 23 | 24 | - name: Publish to Maven Central 25 | run: | 26 | git config user.name '${{ github.actor }}' 27 | git config user.email '${{ github.actor }}@users.noreply.github.com' 28 | ./mvnw -B release:prepare release:perform -Dpassword=${{ secrets.GITHUB_TOKEN }} 29 | env: 30 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 31 | OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} 32 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 33 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 19 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssertBaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import org.junit.jupiter.api.BeforeEach; 16 | 17 | import com.google.common.collect.Table; 18 | import com.google.common.collect.TreeBasedTable; 19 | 20 | /** 21 | * @author Jan Gorman 22 | */ 23 | public class TableAssertBaseTest { 24 | 25 | protected Table actual; 26 | 27 | @BeforeEach 28 | public void setUp() { 29 | actual = TreeBasedTable.create(); 30 | actual.put(1, 3, "Millard Fillmore"); 31 | actual.put(1, 4, "Franklin Pierce"); 32 | actual.put(2, 5, "Grover Cleveland"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/ShouldHaveSameContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.io.ByteSource; 19 | 20 | public class ShouldHaveSameContent extends BasicErrorMessageFactory { 21 | 22 | public static ErrorMessageFactory shouldHaveSameContent(ByteSource actual, ByteSource expected) { 23 | return new ShouldHaveSameContent(actual, expected); 24 | } 25 | 26 | private ShouldHaveSameContent(ByteSource actual, ByteSource expected) { 27 | super("%nexpected: %s%n but was: %s", expected, actual); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/testkit/AssertionErrors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.testkit; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowableOfType; 17 | 18 | import org.assertj.core.api.ThrowableAssert.ThrowingCallable; 19 | 20 | public class AssertionErrors { 21 | 22 | public static AssertionError expectAssertionError(ThrowingCallable shouldRaiseAssertionError) { 23 | AssertionError error = catchThrowableOfType(shouldRaiseAssertionError, AssertionError.class); 24 | assertThat(error).as("The code under test should have raised an AssertionError").isNotNull(); 25 | return error; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AssertJ Assertions for Guava [![Maven Central](https://img.shields.io/maven-central/v/org.assertj/assertj-guava.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.assertj%22%20AND%20a:%22assertj-guava%22) [![Javadocs](http://www.javadoc.io/badge/org.assertj/assertj-guava.svg)](http://www.javadoc.io/doc/org.assertj/assertj-guava) 2 | ============================ 3 | 4 | [![Github CI status](https://github.com/assertj/assertj-guava/workflows/CI/badge.svg)](https://github.com/assertj/assertj-guava/actions?query=workflow%3ACI) 5 | [![Binary Compatibility](https://github.com/assertj/assertj-guava/actions/workflows/binary-compatibility.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-guava/actions/workflows/binary-compatibility.yml?query=branch%3Amain) 6 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=joel-costigliola_assertj-guava&metric=alert_status)](https://sonarcloud.io/dashboard?id=joel-costigliola_assertj-guava) 7 | 8 | AssertJ assertions for [**Guava**](https://github.com/google/guava) provides assertions for Guava types like `Multimap`, `Table`, `ByteSource` or `Optional`. 9 | 10 | Please have a look at the complete documentation in the [**AssertJ Guava section**](https://assertj.github.io/doc/#assertj-guava), including a [**quickstart guide**](https://assertj.github.io/doc/#assertj-guava-quick-start). 11 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/testkit/junit/jupiter/DefaultDisplayNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.testkit.junit.jupiter; 14 | 15 | import org.junit.jupiter.api.DisplayNameGenerator; 16 | 17 | public class DefaultDisplayNameGenerator extends DisplayNameGenerator.ReplaceUnderscores { 18 | 19 | private static final String TEST_SUFFIX = " Test"; 20 | 21 | @Override 22 | public String generateDisplayNameForClass(Class testClass) { 23 | return removeTestSuffixIfExists(super.generateDisplayNameForClass(testClass)); 24 | } 25 | 26 | private static String removeTestSuffixIfExists(String displayName) { 27 | return displayName.endsWith(TEST_SUFFIX) 28 | ? displayName.substring(0, displayName.lastIndexOf(TEST_SUFFIX)) 29 | : displayName; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeMapAssertBaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import org.junit.jupiter.api.BeforeEach; 16 | 17 | import com.google.common.collect.Range; 18 | import com.google.common.collect.TreeRangeMap; 19 | 20 | public class RangeMapAssertBaseTest { 21 | 22 | protected TreeRangeMap actual; 23 | 24 | @BeforeEach 25 | public void setUp() { 26 | actual = TreeRangeMap.create(); 27 | actual.put(Range.closedOpen(380, 450), "violet"); 28 | actual.put(Range.closedOpen(450, 495), "blue"); 29 | actual.put(Range.closedOpen(495, 570), "green"); 30 | actual.put(Range.closedOpen(570, 590), "yellow"); 31 | actual.put(Range.closedOpen(590, 620), "orange"); 32 | actual.put(Range.closedOpen(620, 750), "red"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | 7 | test_os: 8 | name: OS ${{ matrix.os }} 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | os: [ubuntu-latest, macOS-latest, windows-latest] 13 | runs-on: ${{ matrix.os }} 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Setup Java 17 | uses: actions/setup-java@v3 18 | with: 19 | distribution: 'zulu' 20 | java-version: 17 21 | cache: 'maven' 22 | - name: Test 23 | run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc 24 | 25 | sonar: 26 | name: Sonar code analysis 27 | runs-on: ubuntu-latest 28 | if: github.repository == 'assertj/assertj-guava' && github.event_name == 'push' 29 | steps: 30 | - uses: actions/checkout@v3 31 | - name: Setup Java 32 | uses: actions/setup-java@v3 33 | with: 34 | distribution: 'zulu' 35 | java-version: 17 36 | cache: 'maven' 37 | - name: Build with Maven 38 | run: > 39 | ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc 40 | org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar 41 | -Dsonar.host.url=https://sonarcloud.io 42 | -Dsonar.organization=assertj 43 | -Dsonar.projectKey=joel-costigliola_assertj-guava 44 | env: 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 47 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultimapAssertBaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Lists.newArrayList; 16 | 17 | import org.junit.jupiter.api.BeforeEach; 18 | 19 | import com.google.common.collect.LinkedListMultimap; 20 | import com.google.common.collect.Multimap; 21 | 22 | public class MultimapAssertBaseTest { 23 | 24 | protected Multimap actual; 25 | 26 | public MultimapAssertBaseTest() { 27 | super(); 28 | } 29 | 30 | @BeforeEach 31 | public void setUp() { 32 | actual = LinkedListMultimap.create(); 33 | actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar")); 34 | actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose")); 35 | actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili")); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/OptionalShouldBeAbsent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.base.Optional; 19 | 20 | /** 21 | * Creates an error message indicating that an Optional which should be absent is actually present 22 | * 23 | * @author Kornel Kiełczewski 24 | * @author Joel Costigliola 25 | */ 26 | public final class OptionalShouldBeAbsent extends BasicErrorMessageFactory { 27 | 28 | public static ErrorMessageFactory shouldBeAbsent(final Optional actual) { 29 | return new OptionalShouldBeAbsent("Expecting Optional to contain nothing (absent Optional) but contained %s", 30 | actual.get()); 31 | } 32 | 33 | private OptionalShouldBeAbsent(final String format, final Object... arguments) { 34 | super(format, arguments); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/Assertions_assertThat_with_Optional_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | import static org.assertj.guava.api.Assertions.assertThat; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import com.google.common.base.Optional; 21 | 22 | /** 23 | * @author Joel Costigliola 24 | */ 25 | @SuppressWarnings("Guava") 26 | class Assertions_assertThat_with_Optional_Test { 27 | 28 | @Test 29 | void should_create_Assert() { 30 | // GIVEN 31 | Optional actual = Optional.of("value"); 32 | // WHEN 33 | OptionalAssert assertion = assertThat(actual); 34 | // THEN 35 | then(assertion).isNotNull(); 36 | } 37 | 38 | @Test 39 | void should_pass_actual() { 40 | // GIVEN 41 | Optional actual = Optional.of("value"); 42 | // WHEN 43 | Optional result = assertThat(actual).getActual(); 44 | // THEN 45 | then(result).isSameAs(actual); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/OptionalShouldBePresent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.base.Optional; 19 | 20 | /** 21 | * 22 | * Creates an error message indicating that an Optional which should be present is absent 23 | * 24 | * @author Kornel Kiełczewski 25 | * @author Joel Costigliola 26 | */ 27 | public final class OptionalShouldBePresent extends BasicErrorMessageFactory { 28 | 29 | public static ErrorMessageFactory shouldBePresent(final Optional actual) { 30 | return new OptionalShouldBePresent( 31 | "Expecting Optional to contain a non-null instance but contained nothing (absent Optional)", 32 | actual); 33 | } 34 | 35 | private OptionalShouldBePresent(final String format, final Object... arguments) { 36 | super(format, arguments); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldNotEnclose.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | /** 19 | * @author Ilya Koshaleu 20 | */ 21 | public class RangeSetShouldNotEnclose extends BasicErrorMessageFactory { 22 | 23 | public static ErrorMessageFactory shouldNotEnclose(Object actual, Object expected, Iterable enclosed) { 24 | return new RangeSetShouldNotEnclose(actual, expected, enclosed); 25 | } 26 | 27 | /** 28 | * Creates a new {@link BasicErrorMessageFactory}. 29 | * 30 | * @param actual actual {@code RangeSet}. 31 | * @param expected expected value. 32 | * @param enclosed list of values that haven't to be enclosed, but they have. 33 | */ 34 | private RangeSetShouldNotEnclose(Object actual, Object expected, Object enclosed) { 35 | super("%nExpecting:%n %s%nnot to enclose%n %s%nbut it encloses%n %s%n", actual, expected, enclosed); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/TableShouldContainRows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import java.util.Set; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * @author Jan Gorman 22 | */ 23 | public class TableShouldContainRows extends BasicErrorMessageFactory { 24 | 25 | public static ErrorMessageFactory tableShouldContainRows(Object actual, Object[] rows, Set rowsNotFound) { 26 | return rows.length == 1 ? new TableShouldContainRows(actual, rows[0]) 27 | : new TableShouldContainRows(actual, rows, 28 | rowsNotFound); 29 | 30 | } 31 | 32 | private TableShouldContainRows(Object actual, Object row) { 33 | super("%nExpecting:%n %s%nto contain row:%n %s", actual, row); 34 | } 35 | 36 | public TableShouldContainRows(Object actual, Object[] rows, Set rowsNotFound) { 37 | super("%nExpecting:%n %s%nto contain rows:%n %s%nbut could not find:%n %s", actual, rows, rowsNotFound); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldEncloseAnyOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | /** 19 | * Creates an error message indicating that the given {@link com.google.common.collect.RangeSet} does not enclose 20 | * at lease one element of expected objects. 21 | * 22 | * @author Ilya Koshaleu 23 | */ 24 | public class RangeSetShouldEncloseAnyOf extends BasicErrorMessageFactory { 25 | 26 | public static ErrorMessageFactory shouldEncloseAnyOf(Object actual, Object expected) { 27 | return new RangeSetShouldEncloseAnyOf(actual, expected); 28 | } 29 | 30 | /** 31 | * Creates a new {@link BasicErrorMessageFactory}. 32 | * 33 | * @param actual actual {@code RangeSet}. 34 | * @param expected expected range to check for enclosing 35 | */ 36 | private RangeSetShouldEncloseAnyOf(Object actual, Object expected) { 37 | super("%nExpecting:%n %s%nto enclose any of%n %s%n", actual, expected); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/Assertions_assertThat_with_Multimap_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | import static org.assertj.guava.api.Assertions.assertThat; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import com.google.common.collect.HashMultimap; 21 | import com.google.common.collect.Multimap; 22 | 23 | /** 24 | * @author Joel Costigliola 25 | */ 26 | class Assertions_assertThat_with_Multimap_Test { 27 | 28 | @Test 29 | void should_create_Assert() { 30 | // GIVEN 31 | Multimap actual = HashMultimap.create(); 32 | // WHEN 33 | MultimapAssert assertion = assertThat(actual); 34 | // THEN 35 | then(assertion).isNotNull(); 36 | } 37 | 38 | @Test 39 | void should_pass_actual() { 40 | // GIVEN 41 | Multimap actual = HashMultimap.create(); 42 | // WHEN 43 | Multimap result = assertThat(actual).getActual(); 44 | // THEN 45 | then(result).isSameAs(actual); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldBeClosedInTheLowerBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldBeClosedInTheLowerBound extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveClosedLowerBound(final Range actual) { 23 | return new RangeShouldBeClosedInTheLowerBound( 24 | "%nExpecting:%n %s%nto be closed in the lower bound but was opened", actual); 25 | } 26 | 27 | /** 28 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 29 | * 30 | * @param format the format string. 31 | * @param arguments arguments referenced by the format specifiers in the format string. 32 | */ 33 | public RangeShouldBeClosedInTheLowerBound(final String format, final Object... arguments) { 34 | super(format, arguments); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldBeClosedInTheUpperBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldBeClosedInTheUpperBound extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveClosedUpperBound(final Range actual) { 23 | return new RangeShouldBeClosedInTheUpperBound( 24 | "%nExpecting:%n %s%nto be closed in the upper bound but was opened", actual); 25 | } 26 | 27 | /** 28 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 29 | * 30 | * @param format the format string. 31 | * @param arguments arguments referenced by the format specifiers in the format string. 32 | */ 33 | public RangeShouldBeClosedInTheUpperBound(final String format, final Object... arguments) { 34 | super(format, arguments); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldBeOpenedInTheLowerBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldBeOpenedInTheLowerBound extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveOpenedLowerBound(final Range actual) { 23 | return new RangeShouldBeOpenedInTheLowerBound( 24 | "%nExpecting:%n %s%nto be opened in the lower bound but was closed", actual); 25 | } 26 | 27 | /** 28 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 29 | * 30 | * @param format the format string. 31 | * @param arguments arguments referenced by the format specifiers in the format string. 32 | */ 33 | public RangeShouldBeOpenedInTheLowerBound(final String format, final Object... arguments) { 34 | super(format, arguments); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldBeOpenedInTheUpperBound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldBeOpenedInTheUpperBound extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveOpenedUpperBound(final Range actual) { 23 | return new RangeShouldBeOpenedInTheUpperBound( 24 | "%nExpecting:%n %s%nto be opened in the upper bound but was closed", actual); 25 | } 26 | 27 | /** 28 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 29 | * 30 | * @param format the format string. 31 | * @param arguments arguments referenced by the format specifiers in the format string. 32 | */ 33 | public RangeShouldBeOpenedInTheUpperBound(final String format, final Object... arguments) { 34 | super(format, arguments); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | Thank you for your interest in contributing to AssertJ assertions! 5 | We appreciate your effort and to make sure that your pull request is easy to review, we ask you to make note of the following guidelines: 6 | 7 | * Use **[AssertJ code Eclipse formatting preferences](https://github.com/joel-costigliola/assertj-core/blob/master/src/ide-support/assertj-eclipse-formatter.xml)** (for Idea users, it is possible to import it) 8 | * Write complete Javadocs on each assertion methods including a code example. 9 | * Write one JUnit test class for each assertion method with the following naming convention : `__Test`. 10 | * Unit tests method naming convention is underscore based (like python) and not camel case, we find it is much readable for long test names! 11 | * Use JUnit 5 `@DisplayName` on the test class - see `OptionalAssert_contains_Test` as an example. 12 | * Successful assertion unit test method name must start with : `should_pass_...`. 13 | * Failing assertion unit test method name must start with : `should_fail_...`. 14 | * If possible, add a (fun) code example in [assertj-examples](https://github.com/joel-costigliola/assertj-examples) and use it in the javadoc. 15 | 16 | Example: 17 | 18 | As `OptionalAssert` has three assertions: `isPresent`, `isAbsent`, `contains`, we have three test classes : 19 | * `OptionalAssert_isPresent_Test` 20 | * `OptionalAssert_isAbsent_Test` 21 | * `OptionalAssert_contains_Test` 22 | 23 | Let's look at `OptionalAssert_contains_Test` tests names : 24 | * `should_pass_when_actual_contains_expected_value` 25 | * `should_fail_if_actual_is_null` 26 | * `should_fail_when_option_does_not_contain_expected_value` 27 | * `should_fail_when_optional_contains_nothing` 28 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/TableShouldContainColumns.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import java.util.Set; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * @author Jan Gorman 22 | */ 23 | public class TableShouldContainColumns extends BasicErrorMessageFactory { 24 | 25 | public static ErrorMessageFactory tableShouldContainColumns(Object actual, Object[] columns, Set columnsNotFound) { 26 | return columns.length == 1 ? new TableShouldContainColumns(actual, columns[0]) 27 | : new TableShouldContainColumns(actual, columns, 28 | columnsNotFound); 29 | } 30 | 31 | private TableShouldContainColumns(Object actual, Object row) { 32 | super("%nExpecting:%n %s%nto contain column:%n %s", actual, row); 33 | } 34 | 35 | public TableShouldContainColumns(Object actual, Object[] rows, Set columnsNotFound) { 36 | super("%nExpecting:%n %s%nto contain columns:%n %s%nbut could not find:%n %s", actual, rows, columnsNotFound); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/ShouldHaveSameContentTest_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.BDDAssertions.then; 17 | import static org.assertj.guava.error.ShouldHaveSameContent.shouldHaveSameContent; 18 | 19 | import org.assertj.core.description.TextDescription; 20 | import org.assertj.core.error.ErrorMessageFactory; 21 | import org.assertj.core.presentation.StandardRepresentation; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import com.google.common.io.ByteSource; 25 | 26 | class ShouldHaveSameContentTest_create_Test { 27 | 28 | @Test 29 | void should_create_error_message() { 30 | // GIVEN 31 | ErrorMessageFactory factory = shouldHaveSameContent(ByteSource.wrap(new byte[1]), ByteSource.wrap(new byte[] { (byte) 1 })); 32 | // WHEN 33 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 34 | // THEN 35 | then(message).isEqualTo(format("[Test] %nexpected: ByteSource.wrap(01)%n but was: ByteSource.wrap(00)")); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /verify.bndrun: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 2 | # the License. You may obtain a copy of the License at 3 | # 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 7 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 8 | # specific language governing permissions and limitations under the License. 9 | # 10 | # Copyright 2020 the original author or authors. 11 | 12 | -tester: biz.aQute.tester.junit-platform 13 | 14 | -runfw: org.eclipse.osgi 15 | -resolve.effective: active 16 | -runproperties: \ 17 | org.osgi.framework.bootdelegation=sun.reflect,\ 18 | osgi.console= 19 | 20 | -runrequires: \ 21 | bnd.identity;id='${project.artifactId}',\ 22 | bnd.identity;id='junit-jupiter-engine',\ 23 | bnd.identity;id='junit-platform-launcher' 24 | 25 | # This will help us keep -runbundles sorted 26 | -runstartlevel: \ 27 | order=sortbynameversion,\ 28 | begin=-1 29 | 30 | # The version ranges will change as the version of 31 | # AssertJ and/or its dependencies change. 32 | -runbundles: \ 33 | assertj-core;version='[3.23.1,3.23.2)',\ 34 | assertj-guava;version='[3.4.1,3.4.2)',\ 35 | com.google.guava;version='[31.1.0,31.1.1)',\ 36 | com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ 37 | junit-jupiter-api;version='[5.8.2,5.8.3)',\ 38 | junit-jupiter-engine;version='[5.8.2,5.8.3)',\ 39 | junit-platform-commons;version='[1.8.2,1.8.3)',\ 40 | junit-platform-engine;version='[1.8.2,1.8.3)',\ 41 | junit-platform-launcher;version='[1.8.2,1.8.3)',\ 42 | net.bytebuddy.byte-buddy;version='[1.12.10,1.12.11)',\ 43 | org.opentest4j;version='[1.2.0,1.2.1)' 44 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldIntersectAnyOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.RangeSet; 19 | 20 | /** 21 | * Creates an error message indicating that the given {@link com.google.common.collect.RangeSet} does not intersect 22 | * at lease one element of expected objects. 23 | * 24 | * @author Ilya Koshaleu 25 | */ 26 | public class RangeSetShouldIntersectAnyOf extends BasicErrorMessageFactory { 27 | 28 | public static ErrorMessageFactory shouldIntersectAnyOf(RangeSet actual, Object expected) { 29 | return new RangeSetShouldIntersectAnyOf(actual, expected); 30 | } 31 | 32 | /** 33 | * Creates a new {@link BasicErrorMessageFactory}. 34 | * 35 | * @param actual actual {@link com.google.common.collect.RangeSet}. 36 | * @param expected expected range to intersect. 37 | */ 38 | private RangeSetShouldIntersectAnyOf(Object actual, Object expected) { 39 | super("%nExpecting:%n %s%nto intersect at least one range of the given:%n %s%n", actual, expected); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/testkit/junit/jupiter/DefaultDisplayNameGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.testkit.junit.jupiter; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | 17 | import org.junit.jupiter.params.ParameterizedTest; 18 | import org.junit.jupiter.params.provider.CsvSource; 19 | 20 | class DefaultDisplayNameGeneratorTest { 21 | 22 | private final DefaultDisplayNameGenerator underTest = new DefaultDisplayNameGenerator(); 23 | 24 | @ParameterizedTest 25 | @CsvSource({ 26 | "org.assertj.guava.testkit.junit.jupiter.SomeAssert_someMethod_Test, SomeAssert someMethod", 27 | "org.assertj.guava.testkit.junit.jupiter.SomeAssert_someMethod_with_SomeType_Test, SomeAssert someMethod with SomeType" 28 | }) 29 | void generateDisplayNameForClass_should_remove_test_suffix(Class testClass, String expected) { 30 | // WHEN 31 | String displayName = underTest.generateDisplayNameForClass(testClass); 32 | // THEN 33 | then(displayName).isEqualTo(expected); 34 | } 35 | 36 | } 37 | 38 | @SuppressWarnings("unused") 39 | class SomeAssert_someMethod_Test { 40 | } 41 | 42 | @SuppressWarnings("unused") 43 | class SomeAssert_someMethod_with_SomeType_Test { 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/util/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.util; 14 | 15 | import static java.lang.String.format; 16 | 17 | public class ExceptionUtils { 18 | 19 | /** 20 | * Throws a {@link IllegalArgumentException} if given condition is true with message formatted with given arguments 21 | * using {@link String#format(String, Object...)}. 22 | * 23 | * @param condition condition that will trigger the {@link IllegalArgumentException} if true 24 | * @param exceptionMessage message set in thrown IllegalArgumentException 25 | * @param exceptionMessageArgs arguments to be used to format exceptionMessage 26 | * @throws IllegalArgumentException if condition is true 27 | */ 28 | public static void throwIllegalArgumentExceptionIfTrue(boolean condition, String exceptionMessage, 29 | Object... exceptionMessageArgs) { 30 | if (condition) { 31 | throw new IllegalArgumentException(format(exceptionMessage, exceptionMessageArgs)); 32 | } 33 | } 34 | 35 | /** 36 | * protected to avoid direct instanciation but allowing subclassing. 37 | */ 38 | protected ExceptionUtils() { 39 | // empty 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/ShouldContainValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import java.util.Set; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | import org.assertj.core.error.ShouldContainValue; 20 | 21 | /** 22 | * Creates an error message indicating that an assertion that verifies a map contains some values failed. TODO : move to 23 | * assertj-core to replace {@link ShouldContainValue} 24 | * 25 | * @author Joel Costigliola 26 | */ 27 | public class ShouldContainValues extends BasicErrorMessageFactory { 28 | 29 | public static ErrorMessageFactory shouldContainValues(Object actual, Object[] values, Set valuesNotFound) { 30 | return values.length == 1 ? new ShouldContainValues(actual, values[0]) 31 | : new ShouldContainValues(actual, values, 32 | valuesNotFound); 33 | } 34 | 35 | private ShouldContainValues(Object actual, Object value) { 36 | super("%nExpecting:%n %s%nto contain value:%n %s", actual, value); 37 | } 38 | 39 | private ShouldContainValues(Object actual, Object[] values, Set valuesNotFound) { 40 | super("%nExpecting:%n %s%nto contain values:%n %s%nbut could not find:%n %s", actual, values, valuesNotFound); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldEnclose.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | /** 19 | * Creates an error message indicating that the given {@link com.google.common.collect.RangeSet} does not enclose 20 | * neither another one {@link com.google.common.collect.RangeSet} nor some set of 21 | * {@link com.google.common.collect.Range}. 22 | * 23 | * @author Ilya Koshaleu 24 | */ 25 | public class RangeSetShouldEnclose extends BasicErrorMessageFactory { 26 | 27 | public static ErrorMessageFactory shouldEnclose(Object actual, Object expected, Iterable notEnclosed) { 28 | return new RangeSetShouldEnclose(actual, expected, notEnclosed); 29 | } 30 | 31 | /** 32 | * Creates a new {@link BasicErrorMessageFactory}. 33 | * 34 | * @param actual actual {@code RangeSet}. 35 | * @param expected expected range to check for enclosing. 36 | * @param notEnclosed list of objects that have to be enclosed, but they haven't. 37 | */ 38 | private RangeSetShouldEnclose(Object actual, Object expected, Object notEnclosed) { 39 | super("%nExpecting:%n %s%nto enclose%n %s%nbut it does not enclose%n %s%n", actual, expected, notEnclosed); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldNotIntersect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | /** 19 | * @author Ilya Koshaleu 20 | */ 21 | public class RangeSetShouldNotIntersect extends BasicErrorMessageFactory { 22 | 23 | public static ErrorMessageFactory shouldNotIntersect(Object actual, Object unexpected, Iterable intersected) { 24 | return new RangeSetShouldNotIntersect(actual, unexpected, intersected); 25 | } 26 | 27 | @Deprecated 28 | public static ErrorMessageFactory shouldNotIntersects(Object actual, Object unexpected, Iterable intersected) { 29 | return new RangeSetShouldNotIntersect(actual, unexpected, intersected); 30 | } 31 | 32 | /** 33 | * Creates a new {@link BasicErrorMessageFactory}. 34 | * 35 | * @param actual actual {@code RangeSet}. 36 | * @param unexpected ranges that should not be intersected. 37 | * @param intersected list of ranges that haven't be intersected, but they have. 38 | */ 39 | private RangeSetShouldNotIntersect(Object actual, Object unexpected, Object intersected) { 40 | super("%nExpecting:%n %s%nnot to intersect%n %s%nbut it intersects%n %s%n", 41 | actual, unexpected, intersected); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeSetShouldIntersect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | import com.google.common.collect.RangeSet; 20 | 21 | /** 22 | * Creates an error message indicating that the given {@link RangeSet} does not intersect 23 | * either another one {@link RangeSet} or some set of {@link Range}. 24 | * 25 | * @author Ilya Koshaleu 26 | */ 27 | public class RangeSetShouldIntersect extends BasicErrorMessageFactory { 28 | 29 | public static ErrorMessageFactory shouldIntersect(RangeSet actual, Object expected, Iterable notIntersected) { 30 | return new RangeSetShouldIntersect(actual, expected, notIntersected); 31 | } 32 | 33 | /** 34 | * Creates a new {@link BasicErrorMessageFactory}. 35 | * 36 | * @param actual actual {@link RangeSet}. 37 | * @param expected expected {@link RangeSet} that have to be intersected. 38 | * @param notIntersected not intersected ranges. 39 | */ 40 | private RangeSetShouldIntersect(Object actual, Object expected, Object notIntersected) { 41 | super("%nExpecting:%n %s%nto intersect%n %s%nbut it does not intersect%n %s%n", 42 | actual, expected, notIntersected); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/TableShouldHaveRowCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static java.lang.String.format; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * @author David Harris 22 | */ 23 | public class TableShouldHaveRowCount extends BasicErrorMessageFactory { 24 | 25 | /** 26 | * Creates a new {@link TableShouldHaveRowCount}. 27 | * @param actual the actual value in the failed assertion. 28 | * @param actualSize the number of row keys in {@code actual}. 29 | * @param expectedSize the expected number of row keys. 30 | * @return the created {@code ErrorMessageFactory}. 31 | */ 32 | public static ErrorMessageFactory tableShouldHaveRowCount(Object actual, int actualSize, int expectedSize) { 33 | return new TableShouldHaveRowCount(actual, actualSize, expectedSize); 34 | } 35 | 36 | private TableShouldHaveRowCount(Object actual, int actualSize, int expectedSize) { 37 | // format the sizes in a standard way, otherwise if we use (for ex) an Hexadecimal representation 38 | // it will format sizes in hexadecimal while we only want actual to be formatted in hexadecimal 39 | super(format("%nExpected row count: %s but was: %s in:%n%s", expectedSize, actualSize, "%s"), actual); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/MultisetShouldContainTimes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Multiset; 19 | 20 | /** 21 | * Creates an error message stating that a given value appears in a {@link Multiset} a different number of to the expected value 22 | * 23 | * @author Max Daniline 24 | */ 25 | public class MultisetShouldContainTimes extends BasicErrorMessageFactory { 26 | 27 | public static ErrorMessageFactory shouldContainTimes(final Multiset actual, final Object expected, 28 | final int expectedTimes, final int actualTimes) { 29 | return new MultisetShouldContainTimes("%n" + 30 | "Expecting:%n" + 31 | " %s%n" + 32 | "to contain:%n" + 33 | " %s%n" + 34 | "exactly %s times but was found %s times.", 35 | actual, expected, expectedTimes, actualTimes); 36 | } 37 | 38 | private MultisetShouldContainTimes(String format, Object... arguments) { 39 | super(format, arguments); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/OptionalShouldBePresentWithValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.base.Optional; 19 | 20 | /** 21 | * 22 | * Creates an error message indicating that an Optional should contain an expected value 23 | * 24 | * @author Kornel Kiełczewski 25 | * @author Joel Costigliola 26 | */ 27 | public final class OptionalShouldBePresentWithValue extends BasicErrorMessageFactory { 28 | 29 | public static ErrorMessageFactory shouldBePresentWithValue(final Optional actual, final Object value) { 30 | return new OptionalShouldBePresentWithValue("%nExpecting Optional to contain value %n %s%n but contained %n %s", 31 | value, actual.get()); 32 | } 33 | 34 | public static ErrorMessageFactory shouldBePresentWithValue(final Object value) { 35 | return new OptionalShouldBePresentWithValue( 36 | "Expecting Optional to contain %s but contained nothing (absent Optional)", 37 | value); 38 | } 39 | 40 | private OptionalShouldBePresentWithValue(final String format, final Object... arguments) { 41 | super(format, arguments); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/TableShouldHaveColumnCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static java.lang.String.format; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * @author David Harris 22 | */ 23 | public class TableShouldHaveColumnCount extends BasicErrorMessageFactory { 24 | 25 | /** 26 | * Creates a new {@link TableShouldHaveColumnCount}. 27 | * @param actual the actual value in the failed assertion. 28 | * @param actualSize the number of column keys in {@code actual}. 29 | * @param expectedSize the expected number of column keys. 30 | * @return the created {@code ErrorMessageFactory}. 31 | */ 32 | public static ErrorMessageFactory tableShouldHaveColumnCount(Object actual, int actualSize, int expectedSize) { 33 | return new TableShouldHaveColumnCount(actual, actualSize, expectedSize); 34 | } 35 | 36 | private TableShouldHaveColumnCount(Object actual, int actualSize, int expectedSize) { 37 | // format the sizes in a standard way, otherwise if we use (for ex) an Hexadecimal representation 38 | // it will format sizes in hexadecimal while we only want actual to be formatted in hexadecimal 39 | super(format("%nExpected column count: %s but was: %s in:%n%s", expectedSize, actualSize, "%s"), actual); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeMapAssert_isNotEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | public class RangeMapAssert_isNotEmpty_Test extends RangeMapAssertBaseTest { 24 | 25 | @Test 26 | public void should_pass_if_actual_is_not_empty() { 27 | assertThat(actual).isNotEmpty(); 28 | } 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_if_actual_is_empty() { 43 | // GIVEN 44 | actual.clear(); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting actual not to be empty")); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultimapAssert_isNotEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | public class MultimapAssert_isNotEmpty_Test extends MultimapAssertBaseTest { 24 | 25 | @Test 26 | public void should_pass_if_actual_is_not_empty() { 27 | assertThat(actual).isNotEmpty(); 28 | } 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_if_actual_is_empty() { 43 | // GIVEN 44 | actual.clear(); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting actual not to be empty")); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/MultisetShouldContainAtMostTimes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Multiset; 19 | 20 | /** 21 | * Creates an error message stating that a given value appears in a {@link Multiset} more times than expected 22 | * 23 | * @author Max Daniline 24 | */ 25 | public class MultisetShouldContainAtMostTimes extends BasicErrorMessageFactory { 26 | 27 | public static ErrorMessageFactory shouldContainAtMostTimes(final Multiset actual, final Object expected, 28 | final int expectedTimes, final int actualTimes) { 29 | return new MultisetShouldContainAtMostTimes("%n" + 30 | "Expecting:%n" + 31 | " %s%n" + 32 | "to contain:%n" + 33 | " %s%n" + 34 | "at most %s times but was found %s times.", 35 | actual, expected, expectedTimes, actualTimes); 36 | } 37 | 38 | private MultisetShouldContainAtMostTimes(String format, Object... arguments) { 39 | super(format, arguments); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/ShouldHaveSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static java.lang.String.format; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * Creates an error message indicating that an assertion that verifies that a value have certain size failed. 22 | * 23 | * @author Joel Costigliola 24 | */ 25 | public class ShouldHaveSize extends BasicErrorMessageFactory { 26 | 27 | /** 28 | * Creates a new {@link org.assertj.guava.error.ShouldHaveSize}. 29 | * @param actual the actual value in the failed assertion. 30 | * @param actualSize the size of {@code actual}. 31 | * @param expectedSize the expected size. 32 | * @return the created {@code ErrorMessageFactory}. 33 | */ 34 | public static ErrorMessageFactory shouldHaveSize(Object actual, long actualSize, long expectedSize) { 35 | return new ShouldHaveSize(actual, actualSize, expectedSize); 36 | } 37 | 38 | private ShouldHaveSize(Object actual, long actualSize, long expectedSize) { 39 | // format the sizes in a standard way, otherwise if we use (for ex) an Hexadecimal representation 40 | // it will format sizes in hexadecimal while we only want actual to be formatted in hexadecimal 41 | super(format("%nExpected size: %s but was: %s in:%n%s", expectedSize, actualSize, "%s"), actual); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/MultisetShouldContainAtLeastTimes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Multiset; 19 | 20 | /** 21 | * Creates an error message stating that a given value appears in a {@link Multiset} fewer times than expected 22 | * 23 | * @author Max Daniline 24 | */ 25 | public class MultisetShouldContainAtLeastTimes extends BasicErrorMessageFactory { 26 | 27 | public static ErrorMessageFactory shouldContainAtLeastTimes(final Multiset actual, final Object expected, 28 | final int expectedTimes, final int actualTimes) { 29 | return new MultisetShouldContainAtLeastTimes("%n" + 30 | "Expecting:%n" + 31 | " %s%n" + 32 | "to contain:%n" + 33 | " %s%n" + 34 | "at least %s times but was found %s times.", 35 | actual, expected, expectedTimes, actualTimes); 36 | } 37 | 38 | private MultisetShouldContainAtLeastTimes(String format, Object... arguments) { 39 | super(format, arguments); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeMapAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | public class RangeMapAssert_isEmpty_Test extends RangeMapAssertBaseTest { 24 | 25 | @Test 26 | public void should_pass_if_actual_is_empty() { 27 | actual.clear(); 28 | assertThat(actual).isEmpty(); 29 | } 30 | 31 | @Test 32 | public void should_fail_if_actual_is_null() { 33 | // GIVEN 34 | actual = null; 35 | // WHEN 36 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 37 | // THEN 38 | assertThat(throwable).isInstanceOf(AssertionError.class) 39 | .hasMessage(actualIsNull()); 40 | } 41 | 42 | @Test 43 | public void should_fail_if_actual_is_not_empty() { 44 | // WHEN 45 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 46 | // THEN 47 | assertThat(throwable).isInstanceOf(AssertionError.class) 48 | .hasMessage(format("%nExpecting empty but was: [[380..450)=violet, [450..495)=blue, [495..570)=green, [570..590)=yellow, [590..620)=orange, [620..750)=red]")); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/ShouldContainKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import java.util.Set; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | /** 21 | * Creates an error message indicating that an assertion that verifies a map contains some keys failed. TODO : move to 22 | * assertj-core to replace {@link org.assertj.core.error.ShouldContainKeys}. 23 | * 24 | * @author Joel Costigliola 25 | */ 26 | public class ShouldContainKeys extends BasicErrorMessageFactory { 27 | 28 | private ShouldContainKeys(Object actual, Object key) { 29 | super("%nExpecting:%n %s%nto contain key:%n %s", actual, key); 30 | } 31 | 32 | private ShouldContainKeys(Object actual, Object[] keys, Set keysNotFound) { 33 | super("%nExpecting:%n %s%nto contain keys:%n %s%nbut could not find:%n %s", actual, keys, keysNotFound); 34 | } 35 | 36 | /** 37 | * Creates a new {@link ShouldContainKeys}. 38 | * 39 | * @param actual the actual value in the failed assertion. 40 | * @param keys the expected keys. 41 | * @param keysNotFound the missing keys. 42 | * @return the created {@code ErrorMessageFactory}. 43 | */ 44 | public static ErrorMessageFactory shouldContainKeys(Object actual, Object[] keys, Set keysNotFound) { 45 | return keys.length == 1 ? new ShouldContainKeys(actual, keys[0]) : new ShouldContainKeys(actual, keys, keysNotFound); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_isNullOrEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static org.assertj.core.api.BDDAssertions.then; 17 | import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.ImmutableRangeSet; 24 | import com.google.common.collect.RangeSet; 25 | 26 | /** 27 | * @author Ilya Koshaleu 28 | */ 29 | class RangeSetAssert_isNullOrEmpty_Test { 30 | 31 | @Test 32 | void should_pass_if_actual_is_null() { 33 | // GIVEN 34 | RangeSet actual = null; 35 | // WHEN/THEN 36 | assertThat(actual).isNullOrEmpty(); 37 | } 38 | 39 | @Test 40 | void should_pass_if_actual_is_empty() { 41 | // GIVEN 42 | RangeSet actual = ImmutableRangeSet.of(); 43 | // THEN 44 | assertThat(actual).isNullOrEmpty(); 45 | } 46 | 47 | @Test 48 | void should_fail_if_actual_is_not_null_and_not_empty() { 49 | // GIVEN 50 | RangeSet actual = ImmutableRangeSet.of(closed(1, 10)); 51 | // WHEN 52 | AssertionError error = expectAssertionError(() -> assertThat(actual).isNullOrEmpty()); 53 | // WHEN/THEN 54 | then(error).hasMessage(shouldBeNullOrEmpty(actual).create()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author Jan Gorman 25 | */ 26 | public class TableAssert_isEmpty_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_pass_if_actual_is_empty() { 30 | actual.clear(); 31 | assertThat(actual).isEmpty(); 32 | } 33 | 34 | @Test 35 | public void should_fail_if_actual_is_null() { 36 | // GIVEN 37 | actual = null; 38 | // WHEN 39 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsValues("Manu Ginobili")); 40 | // THEN 41 | assertThat(throwable).isInstanceOf(AssertionError.class) 42 | .hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | public void should_fail_if_actual_is_not_empty() { 47 | // WHEN 48 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 49 | // THEN 50 | assertThat(throwable).isInstanceOf(AssertionError.class) 51 | .hasMessage(format("%nExpecting empty but was: {1={3=Millard Fillmore, 4=Franklin Pierce}, 2={5=Grover Cleveland}}")); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldHaveLowerEndpointEqual.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldHaveLowerEndpointEqual extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveEqualLowerEndpoint(final Range actual, 23 | final Object value) { 24 | return new RangeShouldHaveLowerEndpointEqual("%n" + 25 | "Expecting:%n" + 26 | " %s%n" + 27 | "to have lower endpoint equal to:%n" + 28 | " %s%n" + 29 | "but was:%n" + 30 | " %s", 31 | actual, value, actual.lowerEndpoint()); 32 | } 33 | 34 | /** 35 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 36 | * 37 | * @param format the format string. 38 | * @param arguments arguments referenced by the format specifiers in the format string. 39 | */ 40 | private RangeShouldHaveLowerEndpointEqual(final String format, final Object... arguments) { 41 | super(format, arguments); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/RangeShouldHaveUpperEndpointEqual.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import org.assertj.core.error.BasicErrorMessageFactory; 16 | import org.assertj.core.error.ErrorMessageFactory; 17 | 18 | import com.google.common.collect.Range; 19 | 20 | public class RangeShouldHaveUpperEndpointEqual extends BasicErrorMessageFactory { 21 | 22 | public static > ErrorMessageFactory shouldHaveEqualUpperEndpoint(final Range actual, 23 | final Object value) { 24 | return new RangeShouldHaveUpperEndpointEqual("%n" + 25 | "Expecting:%n" + 26 | " %s%n" + 27 | "to have upper endpoint equal to:%n" + 28 | " %s%n" + 29 | "but was:%n" + 30 | " %s", 31 | actual, value, actual.upperEndpoint()); 32 | } 33 | 34 | /** 35 | * Creates a new {@link org.assertj.core.error.BasicErrorMessageFactory}. 36 | * 37 | * @param format the format string. 38 | * @param arguments arguments referenced by the format specifiers in the format string. 39 | */ 40 | private RangeShouldHaveUpperEndpointEqual(final String format, final Object... arguments) { 41 | super(format, arguments); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.ImmutableRangeSet; 24 | import com.google.common.collect.Range; 25 | import com.google.common.collect.RangeSet; 26 | 27 | /** 28 | * @author Ilya Koshaleu 29 | */ 30 | class RangeSetAssert_isEmpty_Test { 31 | 32 | @Test 33 | void should_fail_if_actual_is_null() { 34 | // GIVEN 35 | RangeSet actual = null; 36 | // WHEN 37 | AssertionError error = expectAssertionError(() -> assertThat(actual).isEmpty()); 38 | // THEN 39 | then(error).hasMessage(actualIsNull()); 40 | } 41 | 42 | @Test 43 | void should_fail_if_actual_is_not_empty() { 44 | // GIVEN 45 | RangeSet actual = ImmutableRangeSet.of(Range.closed(1, 10)); 46 | // WHEN 47 | AssertionError error = expectAssertionError(() -> assertThat(actual).isEmpty()); 48 | // THEN 49 | then(error).hasMessage(shouldBeEmpty(actual).create()); 50 | } 51 | 52 | @Test 53 | void should_pass_if_actual_is_empty() { 54 | // GIVEN 55 | RangeSet actual = ImmutableRangeSet.of(); 56 | // WHEN/THEN 57 | assertThat(actual).isEmpty(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_isNotEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.ImmutableRangeSet; 24 | import com.google.common.collect.Range; 25 | import com.google.common.collect.RangeSet; 26 | 27 | /** 28 | * @author Ilya Koshaleu 29 | */ 30 | class RangeSetAssert_isNotEmpty_Test { 31 | 32 | @Test 33 | void should_fail_if_actual_is_null() { 34 | // GIVEN 35 | RangeSet actual = null; 36 | // WHEN 37 | AssertionError error = expectAssertionError(() -> assertThat(actual).isNotEmpty()); 38 | // THEN 39 | then(error).hasMessage(actualIsNull()); 40 | } 41 | 42 | @Test 43 | void should_fail_if_actual_is_empty() { 44 | // GIVEN 45 | RangeSet actual = ImmutableRangeSet.of(); 46 | // WHEN 47 | AssertionError error = expectAssertionError(() -> assertThat(actual).isNotEmpty()); 48 | // THEN 49 | then(error).hasMessage(shouldNotBeEmpty().create()); 50 | } 51 | 52 | @Test 53 | void should_pass_if_actual_is_not_empty() { 54 | // GIVEN 55 | RangeSet actual = ImmutableRangeSet.of(Range.closed(1, 10)); 56 | // WHEN/THEN 57 | assertThat(actual).isNotEmpty(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_isEmpty_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_is_not_empty() { 43 | // GIVEN 44 | final Range actual = Range.openClosed(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting empty but was: (1..10]")); 50 | } 51 | 52 | @Test 53 | public void should_pass_if_range_is_empty() throws Exception { 54 | // GIVEN 55 | final Range actual = Range.openClosed(1, 1); 56 | // THEN 57 | assertThat(actual).isEmpty(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/ByteSourceAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import java.io.IOException; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | import com.google.common.io.ByteSource; 26 | 27 | /** 28 | * Tests for {@link ByteSource#isEmpty()}. 29 | * 30 | * @author Andrew Gaul 31 | */ 32 | public class ByteSourceAssert_isEmpty_Test { 33 | 34 | @Test 35 | public void should_pass_if_actual_is_empty() throws IOException { 36 | ByteSource actual = ByteSource.empty(); 37 | assertThat(actual).isEmpty(); 38 | } 39 | 40 | @Test 41 | public void should_fail_if_actual_is_null() { 42 | // GIVEN 43 | ByteSource actual = null; 44 | // WHEN 45 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 46 | // THEN 47 | assertThat(throwable).isInstanceOf(AssertionError.class) 48 | .hasMessage(actualIsNull()); 49 | } 50 | 51 | @Test 52 | public void should_fail_if_actual_is_not_empty() { 53 | // GIVEN 54 | ByteSource actual = ByteSource.wrap(new byte[1]); 55 | // WHEN 56 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 57 | // THEN 58 | assertThat(throwable).hasMessage(format("%nExpecting empty but was: ByteSource.wrap(00)")); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_isNotEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_isNotEmpty_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_is_empty() { 43 | // GIVEN 44 | final Range actual = Range.openClosed(1, 1); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isNotEmpty()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting actual not to be empty")); 50 | } 51 | 52 | @Test 53 | public void should_pass_if_range_is_not_empty() throws Exception { 54 | // GIVEN 55 | final Range actual = Range.closed(1, 10); 56 | // THEN 57 | assertThat(actual).isNotEmpty(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/OptionalAssert_extractingValue_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | import com.google.common.base.Optional; 23 | 24 | public class OptionalAssert_extractingValue_Test { 25 | 26 | @Test 27 | public void should_fail_if_actual_is_null() { 28 | // GIVEN 29 | Optional actual = null; 30 | // WHEN 31 | Throwable throwable = catchThrowable(() -> assertThat(actual).extractingValue()); 32 | // THEN 33 | assertThat(throwable).isInstanceOf(AssertionError.class) 34 | .hasMessage(actualIsNull()); 35 | } 36 | 37 | @Test 38 | public void should_fail_when_optional_contains_nothing() { 39 | // GIVEN 40 | final Optional actual = Optional.absent(); 41 | // WHEN 42 | Throwable throwable = catchThrowable(() -> assertThat(actual).extractingValue()); 43 | // THEN 44 | assertThat(throwable).isInstanceOf(AssertionError.class) 45 | .hasMessage("Expecting Optional to contain a non-null instance but contained nothing (absent Optional)"); 46 | } 47 | 48 | @Test 49 | public void should_pass_when_actual_contains_a_value() { 50 | // GIVEN 51 | final Optional testedOptional = Optional.of("Test"); 52 | // THEN 53 | assertThat(testedOptional).extractingValue().isEqualTo("Test"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/OptionalAssert_isAbsent_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | import com.google.common.base.Optional; 23 | 24 | /** 25 | * @author Kornel 26 | * @author Joel Costigliola 27 | */ 28 | public class OptionalAssert_isAbsent_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Optional actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isAbsent()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_expected_present_optional_is_absent() { 43 | // GIVEN 44 | final Optional actual = Optional.of("X"); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isAbsent()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage("Expecting Optional to contain nothing (absent Optional) but contained \"X\""); 50 | } 51 | 52 | @Test 53 | public void should_pass_when_optional_is_absent() { 54 | // GIVEN 55 | final Optional testedOptional = Optional.absent(); 56 | // THEN 57 | assertThat(testedOptional).isAbsent(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/OptionalAssert_isPresent_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | import com.google.common.base.Optional; 23 | 24 | /** 25 | * @author Kornel 26 | * @author Joel Costigliola 27 | */ 28 | public class OptionalAssert_isPresent_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Optional actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).isPresent()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_expecting_absent_optional_to_be_present() { 43 | // GIVEN 44 | final Optional actual = Optional.absent(); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).isPresent()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage("Expecting Optional to contain a non-null instance but contained nothing (absent Optional)"); 50 | } 51 | 52 | @Test 53 | public void should_pass_when_optional_is_present() { 54 | // GIVEN 55 | final Optional testedOptional = Optional.of(new Object()); 56 | // THEN 57 | assertThat(testedOptional).isPresent(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultimapAssert_isEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | import static org.junit.jupiter.api.Assertions.fail; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | class MultimapAssert_isEmpty_Test extends MultimapAssertBaseTest { 25 | 26 | @Test 27 | void should_pass_if_actual_is_empty() { 28 | actual.clear(); 29 | assertThat(actual).isEmpty(); 30 | } 31 | 32 | @Test 33 | void should_fail_if_actual_is_null() { 34 | // GIVEN 35 | actual = null; 36 | // WHEN 37 | Throwable throwable = catchThrowable(() -> assertThat(actual).isEmpty()); 38 | // THEN 39 | assertThat(throwable).isInstanceOf(AssertionError.class) 40 | .hasMessage(actualIsNull()); 41 | } 42 | 43 | @Test 44 | void should_fail_if_actual_is_not_empty() { 45 | try { 46 | assertThat(actual).isEmpty(); 47 | } catch (AssertionError e) { 48 | // @format:off 49 | assertThat(e).hasMessage(format("%n" + 50 | "Expecting empty but was: {Lakers=[Kobe Bryant, Magic Johnson, Kareem Abdul Jabbar], " + 51 | "Bulls=[Michael Jordan, Scottie Pippen, Derrick Rose], Spurs=[Tony Parker, Tim Duncan," + 52 | " Manu Ginobili]}")); 53 | // @format:on 54 | return; 55 | } 56 | fail("Assertion error expected"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultimapAssert_hasSize_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.api.BDDAssertions.then; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author Joel Costigliola 25 | */ 26 | class MultimapAssert_hasSize_Test extends MultimapAssertBaseTest { 27 | 28 | @Test 29 | void should_pass_if_size_of_actual_is_equal_to_expected_size() { 30 | // WHEN/THEN 31 | assertThat(actual).hasSize(9); 32 | } 33 | 34 | @Test 35 | void should_fail_if_actual_is_null() { 36 | // GIVEN 37 | actual = null; 38 | // WHEN 39 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(2)); 40 | // THEN 41 | then(throwable).isInstanceOf(AssertionError.class) 42 | .hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | void should_fail_if_size_of_actual_is_not_equal_to_expected_size() { 47 | // WHEN 48 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(3)); 49 | // THEN 50 | then(throwable).isInstanceOf(AssertionError.class) 51 | .hasMessage(format("%n" + 52 | "Expected size: 3 but was: 9 in:%n" + 53 | "{Lakers=[Kobe Bryant, Magic Johnson, Kareem Abdul Jabbar], Bulls=[Michael Jordan, " + 54 | "Scottie Pippen, Derrick Rose], Spurs=[Tony Parker, Tim Duncan, Manu Ginobili]}")); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldEncloseAnyOf_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.guava.error.RangeSetShouldEncloseAnyOf.shouldEncloseAnyOf; 22 | 23 | import org.assertj.core.description.TextDescription; 24 | import org.assertj.core.error.ErrorMessageFactory; 25 | import org.assertj.core.presentation.StandardRepresentation; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests for 30 | * {@link RangeSetShouldEncloseAnyOf#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 31 | * 32 | * @author Ilya_Koshaleu 33 | */ 34 | public class RangeSetShouldEncloseAnyOf_create_Test { 35 | 36 | @Test 37 | void should_create_error_message() { 38 | // GIVEN 39 | ErrorMessageFactory factory = shouldEncloseAnyOf(of(closed(0, 10)), 40 | array(closed(2, 15), open(-5, 5))); 41 | // WHEN 42 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 43 | // THEN 44 | assertThat(message).isEqualTo(format("[Test] %n" + 45 | "Expecting:%n" + 46 | " [[0..10]]%n" + 47 | "to enclose any of%n" + 48 | " [[2..15], (-5..5)]%n")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldIntersectAnyOf_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.guava.error.RangeSetShouldIntersectAnyOf.shouldIntersectAnyOf; 22 | 23 | import org.assertj.core.description.TextDescription; 24 | import org.assertj.core.error.ErrorMessageFactory; 25 | import org.assertj.core.presentation.StandardRepresentation; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests for 30 | * {@link RangeSetShouldIntersectAnyOf#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 31 | * 32 | * @author Ilya_Koshaleu 33 | */ 34 | public class RangeSetShouldIntersectAnyOf_create_Test { 35 | 36 | @Test 37 | void should_create_error_message() { 38 | // GIVEN 39 | ErrorMessageFactory factory = shouldIntersectAnyOf(of(closed(0, 10)), 40 | array(closed(10, 15), open(-5, 0))); 41 | // WHEN 42 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 43 | // THEN 44 | assertThat(message).isEqualTo(format("[Test] %n" + 45 | "Expecting:%n" + 46 | " [[0..10]]%n" + 47 | "to intersect at least one range of the given:%n" + 48 | " [[10..15], (-5..0)]%n")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/error/TableShouldContainCell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static java.lang.String.format; 16 | 17 | import org.assertj.core.error.BasicErrorMessageFactory; 18 | import org.assertj.core.error.ErrorMessageFactory; 19 | 20 | import com.google.common.collect.Table; 21 | 22 | /** 23 | * @author David Harris 24 | */ 25 | public class TableShouldContainCell extends BasicErrorMessageFactory { 26 | 27 | /** 28 | * Creates a new {@link TableShouldContainCell}. 29 | * @param actual the actual value in the failed assertion. 30 | * @param row the row where actualValue was read. 31 | * @param column the column where actualValue was read. 32 | * @param expectedValue the expected value of the cell. 33 | * @param actualValue the expected actual value of the cell. 34 | * 35 | * @param the type of the table row keys 36 | * @param the type of the table column keys 37 | * @param the type of the mapped values 38 | * @return the created {@code ErrorMessageFactory}. 39 | */ 40 | public static ErrorMessageFactory tableShouldContainCell(Table actual, R row, C column, V expectedValue, 41 | V actualValue) { 42 | return new TableShouldContainCell(actual, row, column, expectedValue, actualValue); 43 | } 44 | 45 | private TableShouldContainCell(Table actual, R row, C column, V expectedValue, V actualValue) { 46 | // Except for actual, format values using the standard representation instead of a specific one like Hexadecimal 47 | super(format("%nExpecting row: %s and column: %s to have value:%n %s%nbut was:%n %s%nin:%n %s", row, column, 48 | expectedValue, actualValue, "%s"), 49 | actual); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasClosedLowerBound_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_hasClosedLowerBound_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasClosedLowerBound()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_has_opened_lower_bound() { 43 | // GIVEN 44 | final Range actual = Range.openClosed(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasClosedLowerBound()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting:%n" + 50 | " (1..10]%n" + 51 | "to be closed in the lower bound but was opened")); 52 | } 53 | 54 | @Test 55 | public void should_pass_if_range_has_closed_lower_bound() throws Exception { 56 | // GIVEN 57 | final Range actual = Range.closed(1, 10); 58 | // THEN 59 | assertThat(actual).hasClosedLowerBound(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/ByteSourceAssert_hasSize_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import java.io.IOException; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | import com.google.common.io.ByteSource; 26 | 27 | /** 28 | * Tests for {@link org.assertj.guava.api.ByteSourceAssert#hasSize(long)}. 29 | * 30 | * @author Andrew Gaul 31 | */ 32 | public class ByteSourceAssert_hasSize_Test { 33 | 34 | @Test 35 | public void should_pass_if_size_of_actual_is_equal_to_expected_size() throws IOException { 36 | ByteSource actual = ByteSource.wrap(new byte[9]); 37 | assertThat(actual).hasSize(9); 38 | } 39 | 40 | @Test 41 | public void should_fail_if_actual_is_null() { 42 | // GIVEN 43 | ByteSource actual = null; 44 | // WHEN 45 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(2)); 46 | // THEN 47 | assertThat(throwable).isInstanceOf(AssertionError.class) 48 | .hasMessage(actualIsNull()); 49 | } 50 | 51 | @Test 52 | public void should_fail_if_size_of_actual_is_not_equal_to_expected_size() { 53 | // GIVEN 54 | ByteSource actual = ByteSource.wrap(new byte[9]); 55 | // WHEN 56 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(3)); 57 | // THEN 58 | assertThat(throwable).hasMessage(format("%n" + 59 | "Expected size: 3 but was: 9 in:%n" + 60 | "ByteSource.wrap(000000000000000000)")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasClosedUpperBound_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_hasClosedUpperBound_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasClosedUpperBound()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_has_opened_upper_bound() { 43 | // GIVEN 44 | final Range actual = Range.closedOpen(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasClosedUpperBound()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%n" + 50 | "Expecting:%n" + 51 | " [1..10)%n" + 52 | "to be closed in the upper bound but was opened")); 53 | } 54 | 55 | @Test 56 | public void should_pass_if_range_has_closed_upper_bound() throws Exception { 57 | // GIVEN 58 | final Range actual = Range.closed(1, 10); 59 | // THEN 60 | assertThat(actual).hasClosedUpperBound(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasOpenedLowerBound_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_hasOpenedLowerBound_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasOpenedLowerBound()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_has_closed_lower_bound() { 43 | // GIVEN 44 | final Range actual = Range.closedOpen(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasOpenedLowerBound()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%n" + 50 | "Expecting:%n" + 51 | " [1..10)%n" + 52 | "to be opened in the lower bound but was closed")); 53 | } 54 | 55 | @Test 56 | public void should_pass_if_range_has_opened_lower_bound() throws Exception { 57 | // GIVEN 58 | final Range actual = Range.openClosed(1, 10); 59 | // THEN 60 | assertThat(actual).hasOpenedLowerBound(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasOpenedUpperBound_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_hasOpenedUpperBound_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasOpenedUpperBound()); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_has_closed_upper_bound() { 43 | // GIVEN 44 | final Range actual = Range.openClosed(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasOpenedUpperBound()); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%n" + 50 | "Expecting:%n" + 51 | " (1..10]%n" + 52 | "to be opened in the upper bound but was closed")); 53 | } 54 | 55 | @Test 56 | public void should_pass_if_range_has_opened_upper_bound() throws Exception { 57 | // GIVEN 58 | final Range actual = Range.closedOpen(1, 10); 59 | // THEN 60 | assertThat(actual).hasOpenedUpperBound(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/ByteSourceAssert_hasSameContentAs_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.BDDAssertions.then; 16 | import static org.assertj.core.util.FailureMessages.actualIsNull; 17 | import static org.assertj.guava.api.Assertions.assertThat; 18 | import static org.assertj.guava.error.ShouldHaveSameContent.shouldHaveSameContent; 19 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 20 | 21 | import java.io.IOException; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | import com.google.common.io.ByteSource; 26 | 27 | /** 28 | * @author Andrew Gaul 29 | */ 30 | class ByteSourceAssert_hasSameContentAs_Test { 31 | 32 | @Test 33 | void should_pass_if_size_of_actual_is_equal_to_expected_size() throws IOException { 34 | // GIVEN 35 | ByteSource actual = ByteSource.wrap(new byte[1]); 36 | ByteSource other = ByteSource.wrap(new byte[1]); 37 | // WHEN/THEN 38 | assertThat(actual).hasSameContentAs(other); 39 | } 40 | 41 | @Test 42 | void should_fail_if_actual_is_null() { 43 | // GIVEN 44 | ByteSource actual = null; 45 | ByteSource other = ByteSource.wrap(new byte[1]); 46 | // WHEN 47 | AssertionError error = expectAssertionError(() -> assertThat(actual).hasSameContentAs(other)); 48 | // THEN 49 | then(error).isInstanceOf(AssertionError.class) 50 | .hasMessage(actualIsNull()); 51 | } 52 | 53 | @Test 54 | void should_fail_if_content_of_actual_is_not_equal_to_expected_content() { 55 | // GIVEN 56 | ByteSource actual = ByteSource.wrap(new byte[1]); 57 | ByteSource other = ByteSource.wrap(new byte[] { (byte) 1 }); 58 | // WHEN 59 | AssertionError error = expectAssertionError(() -> assertThat(actual).hasSameContentAs(other)); 60 | // THEN 61 | then(error).hasMessage(shouldHaveSameContent(actual, other).create()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '34 18 * * 1' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v2 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v2 71 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_hasSize_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author David Harris 25 | */ 26 | public class TableAssert_hasSize_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_pass_if_actual_has_0_cells() { 30 | actual.clear(); 31 | assertThat(actual).hasSize(0); 32 | } 33 | 34 | @Test 35 | public void should_pass_if_actual_has_4_cells() { 36 | assertThat(actual).hasSize(3); 37 | } 38 | 39 | @Test 40 | public void should_fail_if_actual_is_null() { 41 | // GIVEN 42 | actual = null; 43 | // WHEN 44 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(3)); 45 | // THEN 46 | assertThat(throwable).isInstanceOf(AssertionError.class) 47 | .hasMessage(actualIsNull()); 48 | } 49 | 50 | @Test 51 | public void should_fail_if_expected_is_negative() { 52 | // WHEN 53 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(-1)); 54 | // THEN 55 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 56 | .hasMessage("The expected size should not be negative."); 57 | } 58 | 59 | @Test 60 | public void should_fail_if_actual_does_not_have_3_cells() { 61 | // GIVEN 62 | actual.clear(); 63 | // WHEN 64 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasSize(3)); 65 | // THEN 66 | assertThat(throwable).isInstanceOf(AssertionError.class) 67 | .hasMessage(shouldHaveSize(actual, actual.size(), 3).create()); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_doesNotContain_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_doesNotContain_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).doesNotContain(1)); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_contains_unexpected_value() { 43 | // GIVEN 44 | final Range actual = Range.closed(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).doesNotContain(9, 10, 11)); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%nExpecting%n" + 50 | " [1..10]%n" + 51 | "not to contain%n" + 52 | " [9, 10, 11]%n" + 53 | "but found%n" + 54 | " [9, 10]%n")); 55 | } 56 | 57 | @Test 58 | public void should_pass_if_range_does_not_contain_values() throws Exception { 59 | // GIVEN 60 | final Range actual = Range.closedOpen(1, 10); 61 | // THEN 62 | assertThat(actual).doesNotContain(10); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldEnclose_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.IterableUtil.iterable; 22 | import static org.assertj.guava.error.RangeSetShouldEnclose.shouldEnclose; 23 | 24 | import org.assertj.core.description.TextDescription; 25 | import org.assertj.core.error.ErrorMessageFactory; 26 | import org.assertj.core.presentation.StandardRepresentation; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests for 31 | * {@link RangeSetShouldEnclose#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 32 | * 33 | * @author Ilya_Koshaleu 34 | */ 35 | public class RangeSetShouldEnclose_create_Test { 36 | 37 | @Test 38 | void should_create_error_message() { 39 | // GIVEN 40 | ErrorMessageFactory factory = shouldEnclose(of(closed(0, 10)), 41 | array(closed(2, 5), open(-5, 5)), 42 | iterable(open(-5, 5))); 43 | // WHEN 44 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 45 | // THEN 46 | assertThat(message).isEqualTo(format("[Test] %n" + 47 | "Expecting:%n" + 48 | " [[0..10]]%n" + 49 | "to enclose%n" + 50 | " [[2..5], (-5..5)]%n" + 51 | "but it does not enclose%n" + 52 | " [(-5..5)]%n")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldNotEnclose_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.IterableUtil.iterable; 22 | import static org.assertj.guava.error.RangeSetShouldNotEnclose.shouldNotEnclose; 23 | 24 | import org.assertj.core.description.TextDescription; 25 | import org.assertj.core.error.ErrorMessageFactory; 26 | import org.assertj.core.presentation.StandardRepresentation; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests for 31 | * {@link RangeSetShouldNotEnclose#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 32 | * 33 | * @author Ilya_Koshaleu 34 | */ 35 | public class RangeSetShouldNotEnclose_create_Test { 36 | 37 | @Test 38 | void should_create_error_message() { 39 | // GIVEN 40 | ErrorMessageFactory factory = shouldNotEnclose(of(closed(0, 10)), 41 | array(closed(2, 5), open(-5, 5)), 42 | iterable(closed(2, 5))); 43 | // WHEN 44 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 45 | // THEN 46 | assertThat(message).isEqualTo(format("[Test] %n" + 47 | "Expecting:%n" + 48 | " [[0..10]]%n" + 49 | "not to enclose%n" + 50 | " [[2..5], (-5..5)]%n" + 51 | "but it encloses%n" + 52 | " [[2..5]]%n")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldIntersect_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.IterableUtil.iterable; 22 | import static org.assertj.guava.error.RangeSetShouldIntersect.shouldIntersect; 23 | 24 | import org.assertj.core.description.TextDescription; 25 | import org.assertj.core.error.ErrorMessageFactory; 26 | import org.assertj.core.presentation.StandardRepresentation; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests for 31 | * {@link RangeSetShouldIntersect#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 32 | * 33 | * @author Ilya_Koshaleu 34 | */ 35 | public class RangeSetShouldIntersect_create_Test { 36 | 37 | @Test 38 | void should_create_error_message() { 39 | // GIVEN 40 | ErrorMessageFactory factory = shouldIntersect(of(closed(0, 10)), 41 | array(closed(2, 15), open(-5, 0)), 42 | iterable(open(-5, 0))); 43 | // WHEN 44 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 45 | // THEN 46 | assertThat(message).isEqualTo(format("[Test] %n" + 47 | "Expecting:%n" + 48 | " [[0..10]]%n" + 49 | "to intersect%n" + 50 | " [[2..15], (-5..0)]%n" + 51 | "but it does not intersect%n" + 52 | " [(-5..0)]%n")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/assertj/guava/data/MapEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.data; 14 | 15 | import static org.assertj.core.util.Objects.HASH_CODE_PRIME; 16 | import static org.assertj.core.util.Objects.areEqual; 17 | import static org.assertj.core.util.Objects.hashCodeFor; 18 | import static org.assertj.core.util.Strings.quote; 19 | 20 | /** 21 | * This is generic version of {@link org.assertj.core.data.MapEntry} 22 | * 23 | * @param key type 24 | * @param value type 25 | * 26 | * @deprecated use {@link org.assertj.core.data.MapEntry org.assertj.core.data.MapEntry} instead. 27 | */ 28 | @Deprecated 29 | public final class MapEntry { 30 | public final K key; 31 | 32 | public final V value; 33 | 34 | /** 35 | * Creates a new {@link MapEntry}. 36 | * 37 | * @param key type 38 | * @param value type 39 | * @param key the key of the entry to create. 40 | * @param value the value of the entry to create. 41 | * @return the created {@code MapEntry}. 42 | */ 43 | public static MapEntry entry(K key, V value) { 44 | return new MapEntry<>(key, value); 45 | } 46 | 47 | private MapEntry(K key, V value) { 48 | this.key = key; 49 | this.value = value; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object obj) { 54 | if (this == obj) { 55 | return true; 56 | } 57 | if (obj == null) { 58 | return false; 59 | } 60 | if (getClass() != obj.getClass()) { 61 | return false; 62 | } 63 | MapEntry other = (MapEntry) obj; 64 | return areEqual(key, other.key) && areEqual(value, other.value); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | int result = 1; 70 | result = HASH_CODE_PRIME * result + hashCodeFor(key); 71 | result = HASH_CODE_PRIME * result + hashCodeFor(value); 72 | return result; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return String.format("%s[key=%s, value=%s]", getClass().getSimpleName(), quote(key), quote(value)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/error/RangeSetShouldNotIntersect_create_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.error; 14 | 15 | import static com.google.common.collect.ImmutableRangeSet.of; 16 | import static com.google.common.collect.Range.closed; 17 | import static com.google.common.collect.Range.open; 18 | import static java.lang.String.format; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.IterableUtil.iterable; 22 | import static org.assertj.guava.error.RangeSetShouldNotIntersect.shouldNotIntersect; 23 | 24 | import org.assertj.core.description.TextDescription; 25 | import org.assertj.core.error.ErrorMessageFactory; 26 | import org.assertj.core.presentation.StandardRepresentation; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests for 31 | * {@link RangeSetShouldNotIntersect#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} 32 | * 33 | * @author Ilya_Koshaleu 34 | */ 35 | public class RangeSetShouldNotIntersect_create_Test { 36 | 37 | @Test 38 | void should_create_error_message() { 39 | // GIVEN 40 | ErrorMessageFactory factory = shouldNotIntersect(of(closed(0, 10)), 41 | array(closed(2, 15), open(-5, 0)), 42 | iterable(closed(2, 15))); 43 | // WHEN 44 | String message = factory.create(new TextDescription("Test"), StandardRepresentation.STANDARD_REPRESENTATION); 45 | // THEN 46 | assertThat(message).isEqualTo(format("[Test] %n" + 47 | "Expecting:%n" + 48 | " [[0..10]]%n" + 49 | "not to intersect%n" + 50 | " [[2..15], (-5..0)]%n" + 51 | "but it intersects%n" + 52 | " [[2..15]]%n")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasUpperEndpointEqualTo_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | public class RangeAssert_hasUpperEndpointEqualTo_Test { 26 | 27 | @Test 28 | public void should_fail_if_actual_is_null() { 29 | // GIVEN 30 | Range actual = null; 31 | // WHEN 32 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasUpperEndpointEqualTo(1)); 33 | // THEN 34 | assertThat(throwable).isInstanceOf(AssertionError.class) 35 | .hasMessage(actualIsNull()); 36 | } 37 | 38 | @Test 39 | public void should_fail_when_range_has_not_the_expected_upper_endpoint() { 40 | // GIVEN 41 | final Range actual = Range.closed(1, 10); 42 | // WHEN 43 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasUpperEndpointEqualTo(2)); 44 | // THEN 45 | assertThat(throwable).isInstanceOf(AssertionError.class) 46 | .hasMessage(format("%n" + 47 | "Expecting:%n" + 48 | " [1..10]%n" + 49 | "to have upper endpoint equal to:%n" + 50 | " 2%n" + 51 | "but was:%n" + 52 | " 10")); 53 | } 54 | 55 | @Test 56 | public void should_pass_if_range_has_expected_upper_endpoint() throws Exception { 57 | // GIVEN 58 | final Range actual = Range.closedOpen(1, 10); 59 | // THEN 60 | assertThat(actual).hasUpperEndpointEqualTo(10); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_hasRowCount_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.error.TableShouldHaveRowCount.tableShouldHaveRowCount; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author David Harris 25 | */ 26 | public class TableAssert_hasRowCount_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_pass_if_actual_has_0_rows() { 30 | actual.clear(); 31 | assertThat(actual).hasRowCount(0); 32 | } 33 | 34 | @Test 35 | public void should_pass_if_actual_has_2_rows() { 36 | assertThat(actual).hasRowCount(2); 37 | } 38 | 39 | @Test 40 | public void should_fail_if_actual_is_null() { 41 | // GIVEN 42 | actual = null; 43 | // WHEN 44 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasRowCount(3)); 45 | // THEN 46 | assertThat(throwable).isInstanceOf(AssertionError.class) 47 | .hasMessage(actualIsNull()); 48 | } 49 | 50 | @Test 51 | public void should_fail_if_expected_is_negative() { 52 | // WHEN 53 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasRowCount(-1)); 54 | // THEN 55 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 56 | .hasMessage("The expected size should not be negative."); 57 | } 58 | 59 | @Test 60 | public void should_fail_if_actual_does_not_have_2_rows() { 61 | // GIVEN 62 | actual.clear(); 63 | // WHEN 64 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasRowCount(2)); 65 | // THEN 66 | assertThat(throwable).isInstanceOf(AssertionError.class) 67 | .hasMessage(tableShouldHaveRowCount(actual, actual.rowKeySet().size(), 2).create()); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeAssert_hasLowerEndpointEqualTo_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.Range; 24 | 25 | /** 26 | * @author Marcin Kwaczyński 27 | */ 28 | public class RangeAssert_hasLowerEndpointEqualTo_Test { 29 | 30 | @Test 31 | public void should_fail_if_actual_is_null() { 32 | // GIVEN 33 | Range actual = null; 34 | // WHEN 35 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasLowerEndpointEqualTo(1)); 36 | // THEN 37 | assertThat(throwable).isInstanceOf(AssertionError.class) 38 | .hasMessage(actualIsNull()); 39 | } 40 | 41 | @Test 42 | public void should_fail_when_range_has_lower_endpoint_not_equal_to() { 43 | // GIVEN 44 | final Range actual = Range.closed(1, 10); 45 | // WHEN 46 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasLowerEndpointEqualTo(2)); 47 | // THEN 48 | assertThat(throwable).isInstanceOf(AssertionError.class) 49 | .hasMessage(format("%n" + 50 | "Expecting:%n" + 51 | " [1..10]%n" + 52 | "to have lower endpoint equal to:%n" + 53 | " 2%n" + 54 | "but was:%n" + 55 | " 1")); 56 | } 57 | 58 | @Test 59 | public void should_pass_if_range_has_lower_endpoint_equal_to() throws Exception { 60 | // GIVEN 61 | final Range actual = Range.closedOpen(1, 10); 62 | // THEN 63 | assertThat(actual).hasLowerEndpointEqualTo(1); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_hasColumnCount_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.error.TableShouldHaveColumnCount.tableShouldHaveColumnCount; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author David Harris 25 | */ 26 | public class TableAssert_hasColumnCount_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_pass_if_actual_has_0_columns() { 30 | actual.clear(); 31 | assertThat(actual).hasColumnCount(0); 32 | } 33 | 34 | @Test 35 | public void should_pass_if_actual_has_3_columns() { 36 | assertThat(actual).hasColumnCount(3); 37 | } 38 | 39 | @Test 40 | public void should_fail_if_actual_is_null() { 41 | // GIVEN 42 | actual = null; 43 | // WHEN 44 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasColumnCount(3)); 45 | // THEN 46 | assertThat(throwable).isInstanceOf(AssertionError.class) 47 | .hasMessage(actualIsNull()); 48 | } 49 | 50 | @Test 51 | public void should_fail_if_expected_is_negative() { 52 | // WHEN 53 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasColumnCount(-1)); 54 | // THEN 55 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 56 | .hasMessage("The expected size should not be negative."); 57 | } 58 | 59 | @Test 60 | public void should_fail_if_actual_does_not_have_3_columns() { 61 | // GIVEN 62 | actual.clear(); 63 | // WHEN 64 | Throwable throwable = catchThrowable(() -> assertThat(actual).hasColumnCount(3)); 65 | // THEN 66 | assertThat(throwable).isInstanceOf(AssertionError.class) 67 | .hasMessage(tableShouldHaveColumnCount(actual, actual.columnKeySet().size(), 3).create()); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/OptionalAssert_extractingCharSequence_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.error.ShouldBeInstance.shouldBeInstance; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.base.Optional; 24 | 25 | public class OptionalAssert_extractingCharSequence_Test { 26 | 27 | @Test 28 | public void should_fail_if_actual_is_null() { 29 | // GIVEN 30 | Optional actual = null; 31 | // WHEN 32 | Throwable throwable = catchThrowable(() -> assertThat(actual).extractingCharSequence()); 33 | // THEN 34 | assertThat(throwable).isInstanceOf(AssertionError.class) 35 | .hasMessage(actualIsNull()); 36 | } 37 | 38 | @Test 39 | public void should_fail_when_optional_contains_nothing() { 40 | // GIVEN 41 | final Optional actual = Optional.absent(); 42 | // WHEN 43 | Throwable throwable = catchThrowable(() -> assertThat(actual).extractingCharSequence()); 44 | // THEN 45 | assertThat(throwable).isInstanceOf(AssertionError.class) 46 | .hasMessage("Expecting Optional to contain a non-null instance but contained nothing (absent Optional)"); 47 | } 48 | 49 | @Test 50 | public void should_pass_when_actual_contains_a_value() { 51 | // GIVEN 52 | final Optional actual = Optional.of("Test"); 53 | // THEN 54 | assertThat(actual).extractingCharSequence().isEqualTo("Test"); 55 | } 56 | 57 | @Test 58 | public void should_not_pass_when_actual_contains_other_than_charSequence() { 59 | // GIVEN 60 | final Optional actual = Optional.of(12L); 61 | // WHEN 62 | Throwable throwable = catchThrowable(() -> assertThat(actual).extractingCharSequence()); 63 | // THEN 64 | assertThat(throwable).isInstanceOf(AssertionError.class) 65 | .hasMessage(shouldBeInstance(12L, CharSequence.class).create()); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_hasSize_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static org.assertj.core.api.BDDAssertions.then; 17 | import static org.assertj.core.util.FailureMessages.actualIsNull; 18 | import static org.assertj.guava.api.Assertions.assertThat; 19 | import static org.assertj.guava.error.ShouldHaveSize.shouldHaveSize; 20 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import com.google.common.collect.ImmutableRangeSet; 25 | import com.google.common.collect.RangeSet; 26 | 27 | class RangeSetAssert_hasSize_Test { 28 | 29 | @Test 30 | void should_fail_if_actual_is_null() { 31 | // GIVEN 32 | RangeSet actual = null; 33 | // WHEN 34 | AssertionError error = expectAssertionError(() -> assertThat(actual).hasSize(5)); 35 | // THEN 36 | then(error).hasMessage(actualIsNull()); 37 | } 38 | 39 | @Test 40 | void should_fail_if_actual_size_does_not_match_expected() { 41 | // GIVEN 42 | RangeSet actual = ImmutableRangeSet. builder() 43 | .add(closed(1, 10)) 44 | .add(closed(20, 35)) 45 | .add(closed(40, 45)) 46 | .build(); 47 | // WHEN 48 | AssertionError error = expectAssertionError(() -> assertThat(actual).hasSize(5)); 49 | // THEN 50 | then(error).isInstanceOf(AssertionError.class) 51 | .hasMessage(shouldHaveSize(actual, actual.asRanges().size(), 5).create()); 52 | } 53 | 54 | @Test 55 | void should_pass_if_actual_size_matches_expected() { 56 | // GIVEN 57 | RangeSet actual = ImmutableRangeSet. builder() 58 | .add(closed(1, 10)) 59 | .add(closed(20, 35)) 60 | .add(closed(40, 45)) 61 | .build(); 62 | // WHEN/THEN 63 | assertThat(actual).hasSize(actual.asRanges().size()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultimapAssert_contains_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.util.Collections.singleton; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.api.Assertions.entry; 18 | import static org.assertj.core.api.BDDAssertions.then; 19 | import static org.assertj.core.error.ShouldContain.shouldContain; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.FailureMessages.actualIsNull; 22 | import static org.assertj.guava.api.Assertions.assertThat; 23 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 24 | 25 | import org.assertj.core.data.MapEntry; 26 | import org.junit.jupiter.api.Test; 27 | 28 | class MultimapAssert_contains_Test extends MultimapAssertBaseTest { 29 | 30 | @Test 31 | void should_pass_if_actual_contains_given_entries() { 32 | assertThat(actual).contains(entry("Bulls", "Derrick Rose")); 33 | assertThat(actual).contains(entry("Lakers", "Kobe Bryant"), entry("Spurs", "Tim Duncan")); 34 | } 35 | 36 | @Test 37 | void should_fail_if_actual_is_null() { 38 | // GIVEN 39 | actual = null; 40 | // WHEN 41 | AssertionError error = expectAssertionError(() -> assertThat(actual).contains(entry("Lakers", "Kobe Bryant"))); 42 | // THEN 43 | then(error).hasMessage(actualIsNull()); 44 | } 45 | 46 | @Test 47 | void should_fail_if_entries_to_look_for_are_null() { 48 | // GIVEN 49 | MapEntry[] entries = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).contains(entries)); 52 | // THEN 53 | then(thrown).isInstanceOf(IllegalArgumentException.class) 54 | .hasMessage("The entries to look for should not be null"); 55 | } 56 | 57 | @Test 58 | void should_fail_if_entries_to_look_for_are_empty() { 59 | // WHEN 60 | Throwable thrown = catchThrowable(() -> assertThat(actual).contains()); 61 | // THEN 62 | then(thrown).isInstanceOf(IllegalArgumentException.class) 63 | .hasMessage("The entries to look for should not be empty"); 64 | } 65 | 66 | @Test 67 | void should_fail_if_actual_does_not_contain_all_given_entries() { 68 | // GIVEN 69 | MapEntry[] entries = array(entry("Lakers", "Kobe Bryant"), entry("Spurs", "Derrick Rose")); 70 | // WHEN 71 | AssertionError error = expectAssertionError(() -> assertThat(actual).contains(entries)); 72 | // THEN 73 | then(error).hasMessage(shouldContain(actual, entries, singleton(entry("Spurs", "Derrick Rose"))).create()); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_containsRows_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.api.Assertions.fail; 19 | import static org.assertj.core.util.FailureMessages.actualIsNull; 20 | import static org.assertj.guava.api.Assertions.assertThat; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * @author Jan Gorman 26 | */ 27 | public class TableAssert_containsRows_Test extends TableAssertBaseTest { 28 | 29 | @Test 30 | public void should_pass_if_actual_contains_rows() { 31 | assertThat(actual).containsRows(1, 2); 32 | } 33 | 34 | @Test 35 | public void should_fail_if_actual_is_null() { 36 | // GIVEN 37 | actual = null; 38 | // WHEN 39 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsRows(1, 2)); 40 | // THEN 41 | assertThat(throwable).isInstanceOf(AssertionError.class) 42 | .hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | public void should_fail_if_rows_to_look_for_are_null() { 47 | // GIVEN 48 | Integer[] rows = null; 49 | // WHEN 50 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsRows(rows)); 51 | // THEN 52 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 53 | .hasMessage("The rows to look for should not be null."); 54 | } 55 | 56 | @Test 57 | public void should_fail_if_rows_to_look_for_are_empty() { 58 | // WHEN 59 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsRows()); 60 | // THEN 61 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 62 | .hasMessage("The rows to look for should not be empty."); 63 | } 64 | 65 | @Test 66 | public void should_fail_if_actual_does_not_contain_rows() { 67 | try { 68 | assertThat(actual).containsRows(3, 4); 69 | } catch (AssertionError e) { 70 | assertThat(e).hasMessage(format("%n" + 71 | "Expecting:%n" + 72 | " {1={3=Millard Fillmore, 4=Franklin Pierce}, 2={5=Grover Cleveland}}%n" + 73 | "to contain rows:%n" + 74 | " [3, 4]%n" + 75 | "but could not find:%n" + 76 | " [3, 4]")); 77 | return; 78 | } 79 | fail("Assertion error expected."); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeMapAssert_contains_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.util.Arrays.asList; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.api.BDDAssertions.then; 18 | import static org.assertj.core.data.MapEntry.entry; 19 | import static org.assertj.core.error.ShouldContain.shouldContain; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.FailureMessages.actualIsNull; 22 | import static org.assertj.guava.api.Assertions.assertThat; 23 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 24 | 25 | import org.assertj.core.data.MapEntry; 26 | import org.junit.jupiter.api.Test; 27 | 28 | class RangeMapAssert_contains_Test extends RangeMapAssertBaseTest { 29 | 30 | @Test 31 | void should_pass_if_actual_contains_given_entries() { 32 | assertThat(actual).contains(entry(400, "violet")); 33 | assertThat(actual).contains(entry(420, "violet"), entry(595, "orange")); 34 | } 35 | 36 | @Test 37 | void should_fail_if_actual_is_null() { 38 | // GIVEN 39 | actual = null; 40 | // WHEN 41 | AssertionError error = expectAssertionError(() -> assertThat(actual).contains(entry(400, "violet"))); 42 | // THEN 43 | then(error).hasMessage(actualIsNull()); 44 | } 45 | 46 | @Test 47 | void should_fail_if_entries_to_look_for_are_null() { 48 | // GIVEN 49 | MapEntry[] entries = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).contains(entries)); 52 | // THEN 53 | then(thrown).isInstanceOf(IllegalArgumentException.class) 54 | .hasMessage("The entries to look for should not be null"); 55 | } 56 | 57 | @Test 58 | void should_fail_if_entries_to_look_for_are_empty() { 59 | // WHEN 60 | MapEntry[] entries = array(); 61 | // WHEN 62 | Throwable thrown = catchThrowable(() -> assertThat(actual).contains(entries)); 63 | // THEN 64 | then(thrown).isInstanceOf(IllegalArgumentException.class) 65 | .hasMessage("The entries to look for should not be empty"); 66 | } 67 | 68 | @Test 69 | void should_fail_if_actual_does_not_contain_all_given_entries() { 70 | // GIVEN 71 | MapEntry[] entries = array(entry(400, "violet"), entry(100, "violet"), entry(500, "pink")); 72 | // WHEN 73 | AssertionError error = expectAssertionError(() -> assertThat(actual).contains(entries)); 74 | // THEN 75 | then(error).hasMessage(shouldContain(actual, entries, asList(entry(100, "violet"), entry(500, "pink"))).create()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_containsColumns_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author Jan Gorman 25 | */ 26 | public class TableAssert_containsColumns_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_fail_if_actual_is_null() { 30 | // GIVEN 31 | actual = null; 32 | // WHEN 33 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsColumns(1, 2)); 34 | // THEN 35 | assertThat(throwable).isInstanceOf(AssertionError.class) 36 | .hasMessage(actualIsNull()); 37 | } 38 | 39 | @Test 40 | public void should_pass_if_actual_contains_columns() { 41 | assertThat(actual).containsColumns(3, 4); 42 | } 43 | 44 | @Test 45 | public void should_fail_if_columns_to_look_for_are_null() { 46 | // GIVEN 47 | Integer[] columns = null; 48 | // WHEN 49 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsColumns(columns)); 50 | // THEN 51 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 52 | .hasMessage("The columns to look for should not be null."); 53 | } 54 | 55 | @Test 56 | public void should_fail_if_columns_to_look_for_are_empty() { 57 | // WHEN 58 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsColumns()); 59 | // THEN 60 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 61 | .hasMessage("The columns to look for should not be empty."); 62 | } 63 | 64 | @Test 65 | public void should_fail_if_actual_does_not_contain_columns() { 66 | // WHEN 67 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsColumns(9, 6)); 68 | // THEN 69 | assertThat(throwable).isInstanceOf(AssertionError.class) 70 | .hasMessage(format("%n" + 71 | "Expecting:%n" + 72 | " {1={3=Millard Fillmore, 4=Franklin Pierce}, 2={5=Grover Cleveland}}%n" + 73 | "to contain columns:%n" + 74 | " [9, 6]%n" + 75 | "but could not find:%n" + 76 | " [6, 9]")); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/OptionalAssert_contains_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.base.Optional; 24 | 25 | /** 26 | * @author Kornel 27 | * @author Joel Costigliola 28 | */ 29 | public class OptionalAssert_contains_Test { 30 | 31 | @Test 32 | public void should_fail_if_actual_is_null() { 33 | // GIVEN 34 | Optional actual = null; 35 | // WHEN 36 | Throwable throwable = catchThrowable(() -> assertThat(actual).contains("Test 2")); 37 | // THEN 38 | assertThat(throwable).isInstanceOf(AssertionError.class) 39 | .hasMessage(actualIsNull()); 40 | } 41 | 42 | @Test 43 | public void should_fail_when_option_does_not_contain_expected_value() { 44 | // GIVEN 45 | final Optional actual = Optional.of("Test"); 46 | // WHEN 47 | Throwable throwable = catchThrowable(() -> assertThat(actual).contains("Test 2")); 48 | // THEN 49 | assertThat(throwable).isInstanceOf(AssertionError.class) 50 | .hasMessage(format("%n" + 51 | "Expecting Optional to contain value %n" + 52 | " \"Test 2\"%n" + 53 | " but contained %n" + 54 | " \"Test\"")); 55 | } 56 | 57 | @Test 58 | public void should_fail_when_optional_contains_nothing() { 59 | // GIVEN 60 | final Optional actual = Optional.absent(); 61 | // WHEN 62 | Throwable throwable = catchThrowable(() -> assertThat(actual).contains("Test")); 63 | // THEN 64 | assertThat(throwable).isInstanceOf(AssertionError.class) 65 | .hasMessage("Expecting Optional to contain \"Test\" but contained nothing (absent Optional)"); 66 | } 67 | 68 | @Test 69 | public void should_pass_when_actual_contains_expected_value() { 70 | // GIVEN 71 | final Optional actual = Optional.of("Test"); 72 | // THEN 73 | assertThat(actual).contains("Test"); 74 | } 75 | 76 | @Test 77 | public void should_pass_when_actual_contains_expected_value_for_arrays() { 78 | // GIVEN 79 | final Optional actual = Optional.of(new byte[] { 1, 2, 3 }); 80 | // THEN 81 | assertThat(actual).contains(new byte[] { 1, 2, 3 }); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_containsValues_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.api.Assertions.fail; 19 | import static org.assertj.core.util.FailureMessages.actualIsNull; 20 | import static org.assertj.guava.api.Assertions.assertThat; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * @author Jan Gorman 26 | */ 27 | public class TableAssert_containsValues_Test extends TableAssertBaseTest { 28 | 29 | @Test 30 | public void should_fail_if_actual_is_null() { 31 | // GIVEN 32 | actual = null; 33 | // WHEN 34 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsValues("a", "b", "c")); 35 | // THEN 36 | assertThat(throwable).isInstanceOf(AssertionError.class) 37 | .hasMessage(actualIsNull()); 38 | } 39 | 40 | @Test 41 | public void should_pass_if_actual_contains_values() { 42 | assertThat(actual).containsValues("Franklin Pierce", "Millard Fillmore"); 43 | } 44 | 45 | @Test 46 | public void should_fail_if_values_to_look_for_are_null() { 47 | // GIVEN 48 | String[] values = null; 49 | // WHEN 50 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsValues(values)); 51 | // THEN 52 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 53 | .hasMessage("The values to look for should not be null."); 54 | } 55 | 56 | @Test 57 | public void should_fail_if_values_to_look_for_are_empty() { 58 | // WHEN 59 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsValues()); 60 | // THEN 61 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 62 | .hasMessage("The values to look for should not be empty."); 63 | } 64 | 65 | @Test 66 | public void should_fail_if_actual_does_not_contain_values() { 67 | try { 68 | assertThat(actual).containsValues("James A. Garfield", "Andrew Johnson"); 69 | } catch (AssertionError e) { 70 | assertThat(e).hasMessage(format("%n" + 71 | "Expecting:%n" + 72 | " {1={3=Millard Fillmore, 4=Franklin Pierce}, 2={5=Grover Cleveland}}%n" + 73 | "to contain values:%n" + 74 | " [\"James A. Garfield\", \"Andrew Johnson\"]%n" + 75 | "but could not find:%n" + 76 | " [\"Andrew Johnson\", \"James A. Garfield\"]")); 77 | return; 78 | } 79 | fail("Assertion error expected."); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_doesNotContain_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.api.BDDAssertions.then; 18 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 19 | import static org.assertj.core.error.ShouldNotContain.shouldNotContain; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.FailureMessages.actualIsNull; 22 | import static org.assertj.guava.api.Assertions.assertThat; 23 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | import com.google.common.collect.ImmutableRangeSet; 28 | import com.google.common.collect.RangeSet; 29 | 30 | /** 31 | * @author Ilya Koshaleu 32 | */ 33 | class RangeSetAssert_doesNotContain_Test { 34 | 35 | @Test 36 | void should_fail_if_actual_is_null() { 37 | // GIVEN 38 | RangeSet actual = null; 39 | // WHEN 40 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotContain(1)); 41 | // THEN 42 | then(error).hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | void should_fail_if_values_is_null() { 47 | // GIVEN 48 | RangeSet actual = ImmutableRangeSet.of(); 49 | Integer[] values = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotContain(values)); 52 | // THEN 53 | then(thrown).isInstanceOf(NullPointerException.class) 54 | .hasMessage(shouldNotBeNull("values").create()); 55 | } 56 | 57 | @Test 58 | void should_fail_if_values_is_empty() { 59 | // GIVEN 60 | RangeSet actual = ImmutableRangeSet.of(closed(0, 1)); 61 | Integer[] values = {}; 62 | // WHEN 63 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotContain(values)); 64 | // THEN 65 | then(thrown).isInstanceOf(IllegalArgumentException.class) 66 | .hasMessage("Expecting values not to be empty"); 67 | } 68 | 69 | @Test 70 | void should_fail_if_actual_contains_values() { 71 | // GIVEN 72 | RangeSet actual = ImmutableRangeSet.of(closed(1, 10)); 73 | Integer[] values = array(0, 2, 3, 4); 74 | // WHEN 75 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotContain(values)); 76 | // THEN 77 | then(error).hasMessage(shouldNotContain(actual, values, array(2, 3, 4)).create()); 78 | } 79 | 80 | @Test 81 | void should_pass_if_actual_does_not_contain_values() { 82 | // GIVEN 83 | RangeSet actual = ImmutableRangeSet.of(closed(0, 3)); 84 | // WHEN/THEN 85 | assertThat(actual).doesNotContain(4, 5); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultisetAssert_containsAtMost_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.HashMultiset; 24 | import com.google.common.collect.Multiset; 25 | 26 | public class MultisetAssert_containsAtMost_Test { 27 | 28 | @Test 29 | public void should_fail_if_actual_is_null() { 30 | // GIVEN 31 | Multiset actual = null; 32 | // WHEN 33 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtMost(1, "test")); 34 | // THEN 35 | assertThat(throwable).isInstanceOf(AssertionError.class) 36 | .hasMessage(actualIsNull()); 37 | } 38 | 39 | @Test 40 | public void should_fail_if_expected_is_negative() { 41 | // GIVEN 42 | Multiset actual = HashMultiset.create(); 43 | // WHEN 44 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtMost(-1, "test")); 45 | // THEN 46 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 47 | .hasMessage("The maximum count should not be negative."); 48 | } 49 | 50 | @Test 51 | public void should_pass_if_actual_contains_value_fewer_times_than_expected() { 52 | // GIVEN 53 | Multiset actual = HashMultiset.create(); 54 | actual.add("test", 2); 55 | // when 56 | assertThat(actual).containsAtMost(3, "test"); 57 | // THEN pass 58 | } 59 | 60 | @Test 61 | public void should_pass_if_actual_contains_value_number_of_times_expected() { 62 | // GIVEN 63 | Multiset actual = HashMultiset.create(); 64 | actual.add("test", 2); 65 | // when 66 | assertThat(actual).containsAtMost(2, "test"); 67 | // THEN pass 68 | } 69 | 70 | @Test 71 | public void should_fail_if_actual_contains_value_more_times_than_expected() { 72 | // GIVEN 73 | Multiset actual = HashMultiset.create(); 74 | actual.add("test", 2); 75 | // WHEN 76 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtMost(1, "test")); 77 | // THEN 78 | assertThat(throwable).isInstanceOf(AssertionError.class) 79 | .hasMessage(format("%nExpecting:%n" + 80 | " [\"test\", \"test\"]%n" + 81 | "to contain:%n" + 82 | " \"test\"%n" + 83 | "at most 1 times but was found 2 times.")); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/MultisetAssert_containsAtLeast_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.google.common.collect.HashMultiset; 24 | import com.google.common.collect.Multiset; 25 | 26 | /** 27 | * @author Max Daniline 28 | */ 29 | public class MultisetAssert_containsAtLeast_Test { 30 | 31 | @Test 32 | public void should_fail_if_actual_is_null() { 33 | // GIVEN 34 | Multiset actual = null; 35 | // WHEN 36 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtLeast(1, "test")); 37 | // THEN 38 | assertThat(throwable).isInstanceOf(AssertionError.class) 39 | .hasMessage(actualIsNull()); 40 | } 41 | 42 | @Test 43 | public void should_fail_if_expected_is_negative() { 44 | // GIVEN 45 | Multiset actual = HashMultiset.create(); 46 | // WHEN 47 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtLeast(-1, "test")); 48 | // THEN 49 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 50 | .hasMessage("The minimum count should not be negative."); 51 | } 52 | 53 | @Test 54 | public void should_fail_if_actual_contains_value_fewer_times_than_expected() { 55 | // GIVEN 56 | Multiset actual = HashMultiset.create(); 57 | actual.add("test", 2); 58 | // WHEN 59 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsAtLeast(3, "test")); 60 | // THEN 61 | assertThat(throwable).isInstanceOf(AssertionError.class) 62 | .hasMessage(format("%nExpecting:%n" + 63 | " [\"test\", \"test\"]%n" + 64 | "to contain:%n" + 65 | " \"test\"%n" + 66 | "at least 3 times but was found 2 times.")); 67 | } 68 | 69 | @Test 70 | public void should_pass_if_actual_contains_value_number_of_times_expected() { 71 | // GIVEN 72 | Multiset actual = HashMultiset.create(); 73 | actual.add("test", 2); 74 | // THEN 75 | assertThat(actual).containsAtLeast(2, "test"); 76 | } 77 | 78 | @Test 79 | public void should_pass_if_actual_contains_value_more_times_than_expected() { 80 | // GIVEN 81 | Multiset actual = HashMultiset.create(); 82 | actual.add("test", 2); 83 | // THEN 84 | assertThat(actual).containsAtLeast(1, "test"); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_doesNotContainAll_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static java.util.Arrays.asList; 17 | import static java.util.Collections.emptySet; 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.assertj.core.api.Assertions.catchThrowable; 20 | import static org.assertj.core.api.BDDAssertions.then; 21 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 22 | import static org.assertj.core.error.ShouldNotContain.shouldNotContain; 23 | import static org.assertj.core.util.FailureMessages.actualIsNull; 24 | import static org.assertj.core.util.Lists.list; 25 | import static org.assertj.guava.api.Assertions.assertThat; 26 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 27 | 28 | import org.junit.jupiter.api.Test; 29 | 30 | import com.google.common.collect.ImmutableRangeSet; 31 | import com.google.common.collect.RangeSet; 32 | 33 | /** 34 | * @author Ilya Koshaleu 35 | */ 36 | class RangeSetAssert_doesNotContainAll_Test { 37 | 38 | @Test 39 | void should_fail_if_actual_is_null() { 40 | // GIVEN 41 | RangeSet actual = null; 42 | // WHEN 43 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotContainAll(asList(1, 2))); 44 | // THEN 45 | then(error).hasMessage(actualIsNull()); 46 | } 47 | 48 | @Test 49 | void should_fail_if_values_is_null() { 50 | // GIVEN 51 | RangeSet actual = ImmutableRangeSet.of(); 52 | Iterable values = null; 53 | // WHEN 54 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotContainAll(values)); 55 | // THEN 56 | then(thrown).isInstanceOf(NullPointerException.class) 57 | .hasMessage(shouldNotBeNull("values").create()); 58 | } 59 | 60 | @Test 61 | void should_fail_if_values_is_empty() { 62 | // GIVEN 63 | RangeSet actual = ImmutableRangeSet.of(); 64 | Iterable values = emptySet(); 65 | // WHEN 66 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotContainAll(values)); 67 | // THEN 68 | assertThat(thrown).isInstanceOf(IllegalArgumentException.class) 69 | .hasMessage("Expecting values not to be empty"); 70 | } 71 | 72 | @Test 73 | void should_fail_if_actual_contains_values() { 74 | // GIVEN 75 | RangeSet actual = ImmutableRangeSet.of(closed(1, 10)); 76 | Iterable values = list(0, 2, 3, 4); 77 | // WHEN 78 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotContainAll(values)); 79 | // THEN 80 | then(error).hasMessage(shouldNotContain(actual, values, list(2, 3, 4)).create()); 81 | } 82 | 83 | @Test 84 | void should_pass_if_actual_does_not_contain_values() { 85 | // GIVEN 86 | RangeSet actual = ImmutableRangeSet.of(closed(0, 3)); 87 | // WHEN/THEN 88 | assertThat(actual).doesNotContainAll(list(4, 5)); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_doesNotEnclose_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static com.google.common.collect.Range.open; 17 | import static java.util.Collections.singleton; 18 | import static org.assertj.core.api.Assertions.catchThrowable; 19 | import static org.assertj.core.api.BDDAssertions.then; 20 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 21 | import static org.assertj.core.util.Arrays.array; 22 | import static org.assertj.core.util.FailureMessages.actualIsNull; 23 | import static org.assertj.guava.api.Assertions.assertThat; 24 | import static org.assertj.guava.error.RangeSetShouldNotEnclose.shouldNotEnclose; 25 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | import com.google.common.collect.ImmutableRangeSet; 30 | import com.google.common.collect.Range; 31 | import com.google.common.collect.RangeSet; 32 | 33 | class RangeSetAssert_doesNotEnclose_Test { 34 | 35 | @Test 36 | void should_fail_if_actual_is_null() { 37 | // GIVEN 38 | RangeSet actual = null; 39 | // WHEN 40 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotEnclose(closed(0, 1))); 41 | // THEN 42 | then(error).hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | void should_fail_if_ranges_is_null() { 47 | // GIVEN 48 | RangeSet actual = ImmutableRangeSet.of(); 49 | Range[] ranges = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotEnclose(ranges)); 52 | // THEN 53 | then(thrown).isInstanceOf(NullPointerException.class) 54 | .hasMessage(shouldNotBeNull("ranges").create()); 55 | } 56 | 57 | @Test 58 | void should_fail_if_ranges_is_empty() { 59 | // GIVEN 60 | RangeSet actual = ImmutableRangeSet.of(closed(0, 1)); 61 | Range[] ranges = array(); 62 | // WHEN 63 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotEnclose(ranges)); 64 | // THEN 65 | then(thrown).isInstanceOf(IllegalArgumentException.class) 66 | .hasMessage("Expecting ranges not to be empty"); 67 | } 68 | 69 | @Test 70 | void should_fail_if_actual_encloses_ranges() { 71 | // GIVEN 72 | RangeSet actual = ImmutableRangeSet.of(closed(0, 100)); 73 | Range[] ranges = array(open(10, 50), open(50, 110)); 74 | // WHEN 75 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotEnclose(ranges)); 76 | // THEN 77 | then(error).hasMessage(shouldNotEnclose(actual, ranges, singleton(open(10, 50))).create()); 78 | } 79 | 80 | @Test 81 | void should_pass_if_actual_does_not_enclose_ranges() { 82 | // GIVEN 83 | RangeSet actual = ImmutableRangeSet.of(closed(0, 100)); 84 | Range[] ranges = array(open(-10, 50), open(50, 110)); 85 | // WHEN/THEN 86 | assertThat(actual).doesNotEnclose(ranges); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_doesNotIntersect_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static com.google.common.collect.Range.open; 17 | import static java.util.Arrays.asList; 18 | import static org.assertj.core.api.Assertions.catchThrowable; 19 | import static org.assertj.core.api.BDDAssertions.then; 20 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 21 | import static org.assertj.core.util.Arrays.array; 22 | import static org.assertj.core.util.FailureMessages.actualIsNull; 23 | import static org.assertj.guava.api.Assertions.assertThat; 24 | import static org.assertj.guava.error.RangeSetShouldNotIntersect.shouldNotIntersect; 25 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | import com.google.common.collect.ImmutableRangeSet; 30 | import com.google.common.collect.Range; 31 | import com.google.common.collect.RangeSet; 32 | 33 | class RangeSetAssert_doesNotIntersect_Test { 34 | 35 | @Test 36 | void should_fail_if_actual_is_null() { 37 | // GIVEN 38 | RangeSet actual = null; 39 | // WHEN 40 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotIntersect(closed(0, 1))); 41 | // THEN 42 | then(error).hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | void should_fail_if_ranges_is_null() { 47 | // GIVEN 48 | RangeSet actual = ImmutableRangeSet.of(); 49 | Range[] ranges = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotIntersect(ranges)); 52 | // THEN 53 | then(thrown).isInstanceOf(NullPointerException.class) 54 | .hasMessage(shouldNotBeNull("ranges").create()); 55 | } 56 | 57 | @Test 58 | void should_fail_if_ranges_is_empty() { 59 | // GIVEN 60 | RangeSet actual = ImmutableRangeSet.of(closed(0, 1)); 61 | Range[] ranges = array(); 62 | // WHEN 63 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotIntersect(ranges)); 64 | // THEN 65 | then(thrown).isInstanceOf(IllegalArgumentException.class) 66 | .hasMessage("Expecting ranges not to be empty"); 67 | } 68 | 69 | @Test 70 | void should_fail_if_actual_intersects_ranges() { 71 | // GIVEN 72 | RangeSet actual = ImmutableRangeSet.of(closed(0, 100)); 73 | Range[] ranges = array(open(-100, 0), open(90, 170)); 74 | // WHEN 75 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotIntersect(ranges)); 76 | // THEN 77 | then(error).hasMessage(shouldNotIntersect(actual, ranges, asList(open(90, 170))).create()); 78 | } 79 | 80 | @Test 81 | void should_pass_if_actual_does_not_intersect_ranges() { 82 | // GIVEN 83 | RangeSet actual = ImmutableRangeSet.of(closed(0, 100)); 84 | Range[] ranges = array(open(-100, 0), open(100, 170)); 85 | // WHEN/THEN 86 | assertThat(actual).doesNotIntersect(ranges); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_containsAnyOf_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static org.assertj.core.api.Assertions.catchThrowable; 17 | import static org.assertj.core.api.BDDAssertions.then; 18 | import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; 19 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 20 | import static org.assertj.core.util.Arrays.array; 21 | import static org.assertj.core.util.FailureMessages.actualIsNull; 22 | import static org.assertj.guava.api.Assertions.assertThat; 23 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | import com.google.common.collect.ImmutableRangeSet; 28 | import com.google.common.collect.RangeSet; 29 | 30 | /** 31 | * @author Ilya Koshaleu 32 | */ 33 | class RangeSetAssert_containsAnyOf_Test { 34 | 35 | @Test 36 | void should_fail_if_actual_is_null() { 37 | // GIVEN 38 | RangeSet actual = null; 39 | // WHEN 40 | AssertionError error = expectAssertionError(() -> assertThat(actual).containsAnyOf(1)); 41 | // THEN 42 | then(error).hasMessage(actualIsNull()); 43 | } 44 | 45 | @Test 46 | void should_fail_if_values_is_null() { 47 | // GIVEN 48 | RangeSet actual = ImmutableRangeSet.of(); 49 | Integer[] values = null; 50 | // WHEN 51 | Throwable thrown = catchThrowable(() -> assertThat(actual).containsAnyOf(values)); 52 | // THEN 53 | then(thrown).isInstanceOf(NullPointerException.class) 54 | .hasMessage(shouldNotBeNull("values").create()); 55 | } 56 | 57 | @Test 58 | void should_fail_if_values_is_empty() { 59 | // GIVEN 60 | RangeSet actual = ImmutableRangeSet.of(closed(0, 1)); 61 | Integer[] values = {}; 62 | // WHEN 63 | Throwable thrown = catchThrowable(() -> assertThat(actual).containsAnyOf(values)); 64 | // THEN 65 | then(thrown).isInstanceOf(IllegalArgumentException.class) 66 | .hasMessage("Expecting values not to be empty"); 67 | } 68 | 69 | @Test 70 | void should_fail_if_actual_does_not_contain_values() { 71 | // GIVEN 72 | RangeSet actual = ImmutableRangeSet.of(closed(0, 3)); 73 | Integer[] values = array(4, 5); 74 | // WHEN 75 | AssertionError error = expectAssertionError(() -> assertThat(actual).containsAnyOf(values)); 76 | // THEN 77 | then(error).hasMessage(shouldContainAnyOf(actual, values).create()); 78 | } 79 | 80 | @Test 81 | void should_pass_if_both_actual_and_values_are_empty() { 82 | // GIVEN 83 | RangeSet actual = ImmutableRangeSet.of(); 84 | Integer[] values = {}; 85 | // WHEN/THEN 86 | assertThat(actual).containsAnyOf(values); 87 | } 88 | 89 | @Test 90 | void should_pass_if_actual_contains_any_values() { 91 | // GIVEN 92 | RangeSet actual = ImmutableRangeSet.of(closed(1, 10)); 93 | // WHEN/THEN 94 | assertThat(actual).containsAnyOf(0, 1, 2, 3, 11, 12, 13); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/TableAssert_containsCells_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static java.lang.String.format; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import static org.assertj.core.api.Assertions.catchThrowable; 18 | import static org.assertj.core.util.FailureMessages.actualIsNull; 19 | import static org.assertj.guava.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * @author Jan Gorman 25 | */ 26 | public class TableAssert_containsCells_Test extends TableAssertBaseTest { 27 | 28 | @Test 29 | public void should_fail_if_actual_is_null() { 30 | // GIVEN 31 | actual = null; 32 | // WHEN 33 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsCell(1, 2, "")); 34 | // THEN 35 | assertThat(throwable).isInstanceOf(AssertionError.class) 36 | .hasMessage(actualIsNull()); 37 | } 38 | 39 | @Test 40 | public void should_pass_if_actual_contains_cell() { 41 | assertThat(actual).containsCell(1, 3, "Millard Fillmore"); 42 | } 43 | 44 | @Test 45 | public void should_fail_if_actual_does_not_contain_cell() { 46 | // WHEN 47 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsCell(1, 4, "Millard Fillmore")); 48 | // THEN 49 | assertThat(throwable).isInstanceOf(AssertionError.class) 50 | .hasMessage(format("%n" + 51 | "Expecting row: 1 and column: 4 to have value:%n" + 52 | " Millard Fillmore%n" + 53 | "but was:%n" + 54 | " Franklin Pierce%n" + 55 | "in:%n" + 56 | " {1={3=Millard Fillmore, 4=Franklin Pierce}, 2={5=Grover Cleveland}}")); 57 | 58 | } 59 | 60 | @Test 61 | public void should_fail_if_row_is_null() { 62 | // GIVEN 63 | Integer row = null; 64 | // WHEN 65 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsCell(row, 1, "Millard Fillmore")); 66 | // THEN 67 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 68 | .hasMessage("The row to look for should not be null."); 69 | } 70 | 71 | @Test 72 | public void should_fail_if_column_is_null() { 73 | // GIVEN 74 | Integer column = null; 75 | // WHEN 76 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsCell(1, column, "Millard Fillmore")); 77 | // THEN 78 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 79 | .hasMessage("The column to look for should not be null."); 80 | } 81 | 82 | @Test 83 | public void should_fail_if_value_is_null() { 84 | // GIVEN 85 | String value = null; 86 | // WHEN 87 | Throwable throwable = catchThrowable(() -> assertThat(actual).containsCell(1, 2, value)); 88 | // THEN 89 | assertThat(throwable).isInstanceOf(IllegalArgumentException.class) 90 | .hasMessage("The value to look for should not be null."); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/org/assertj/guava/api/RangeSetAssert_doesNotEncloseAnyRangesOf_with_Iterable_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2022 the original author or authors. 12 | */ 13 | package org.assertj.guava.api; 14 | 15 | import static com.google.common.collect.Range.closed; 16 | import static com.google.common.collect.Range.open; 17 | import static java.util.Collections.emptySet; 18 | import static java.util.Collections.singleton; 19 | import static org.assertj.core.api.Assertions.catchThrowable; 20 | import static org.assertj.core.api.BDDAssertions.then; 21 | import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; 22 | import static org.assertj.core.util.FailureMessages.actualIsNull; 23 | import static org.assertj.core.util.Lists.list; 24 | import static org.assertj.guava.api.Assertions.assertThat; 25 | import static org.assertj.guava.error.RangeSetShouldNotEnclose.shouldNotEnclose; 26 | import static org.assertj.guava.testkit.AssertionErrors.expectAssertionError; 27 | 28 | import org.junit.jupiter.api.Test; 29 | 30 | import com.google.common.collect.ImmutableRangeSet; 31 | import com.google.common.collect.Range; 32 | import com.google.common.collect.RangeSet; 33 | 34 | class RangeSetAssert_doesNotEncloseAnyRangesOf_with_Iterable_Test { 35 | 36 | @Test 37 | void should_fail_if_actual_is_null() { 38 | // GIVEN 39 | RangeSet actual = null; 40 | Iterable> ranges = list(closed(0, 10)); 41 | // WHEN 42 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotEncloseAnyRangesOf(ranges)); 43 | // THEN 44 | then(error).hasMessage(actualIsNull()); 45 | } 46 | 47 | @Test 48 | void should_fail_if_ranges_is_null() { 49 | // GIVEN 50 | RangeSet actual = ImmutableRangeSet.of(); 51 | Iterable> ranges = null; 52 | // WHEN 53 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotEncloseAnyRangesOf(ranges)); 54 | // THEN 55 | then(thrown).isInstanceOf(NullPointerException.class) 56 | .hasMessage(shouldNotBeNull("ranges").create()); 57 | } 58 | 59 | @Test 60 | void should_fail_if_ranges_is_empty() { 61 | // GIVEN 62 | RangeSet actual = ImmutableRangeSet.of(closed(0, 1)); 63 | Iterable> ranges = emptySet(); 64 | // WHEN 65 | Throwable thrown = catchThrowable(() -> assertThat(actual).doesNotEncloseAnyRangesOf(ranges)); 66 | // THEN 67 | then(thrown).isInstanceOf(IllegalArgumentException.class) 68 | .hasMessage("Expecting ranges not to be empty"); 69 | } 70 | 71 | @Test 72 | void should_fail_if_actual_encloses_ranges() { 73 | // GIVEN 74 | RangeSet actual = ImmutableRangeSet.of(closed(0, 100)); 75 | Iterable> ranges = list(open(10, 50), open(50, 110)); 76 | // WHEN 77 | AssertionError error = expectAssertionError(() -> assertThat(actual).doesNotEncloseAnyRangesOf(ranges)); 78 | // THEN 79 | then(error).hasMessage(shouldNotEnclose(actual, ranges, singleton(open(10, 50))).create()); 80 | } 81 | 82 | @Test 83 | void should_pass_if_actual_does_not_enclose_ranges() { 84 | // GIVEN 85 | RangeSet rangeSet = ImmutableRangeSet.of(closed(0, 100)); 86 | Iterable> ranges = list(open(-10, 50), open(50, 110)); 87 | // WHEN/THEN 88 | assertThat(rangeSet).doesNotEncloseAnyRangesOf(ranges); 89 | } 90 | 91 | } 92 | --------------------------------------------------------------------------------