Skip to content

Commit

Permalink
Move assertThat(CompletionStage<RESULT> actual) from AssertionsForCla…
Browse files Browse the repository at this point in the history
…ssTypes to AssertionsForInterfaceTypes.

Fixes #839.
  • Loading branch information
joel-costigliola committed Jan 10, 2018
1 parent 8e71b4e commit 43c3c6b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/assertj/core/api/Assertions.java
Expand Up @@ -212,7 +212,7 @@ public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletableFut
*/
@CheckReturnValue
public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletionStage<RESULT> actual) {
return AssertionsForClassTypes.assertThat(actual);
return AssertionsForInterfaceTypes.assertThat(actual);
}

/**
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/assertj/core/api/AssertionsForClassTypes.java
Expand Up @@ -36,7 +36,6 @@
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.exception.RuntimeIOException;
Expand Down Expand Up @@ -85,21 +84,6 @@ public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletableFut
return new CompletableFutureAssert<>(actual);
}

/**
* Create assertion for {@link java.util.concurrent.CompletionStage} by converting it to a {@link CompletableFuture} and returning a {@link CompletableFutureAssert}.
* <p>
* If the given {@link java.util.concurrent.CompletionStage} is null, the {@link CompletableFuture} in the returned {@link CompletableFutureAssert} will also be null.
*
* @param actual the actual value.
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.CompletionStage}.
*
* @return the created assertion object.
*/
@CheckReturnValue
public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletionStage<RESULT> actual) {
return new CompletableFutureAssert<>(actual);
}

/**
* Create assertion for {@link java.util.Optional}.
*
Expand Down
Expand Up @@ -16,6 +16,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.DoublePredicate;
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
Expand Down Expand Up @@ -378,5 +380,20 @@ public static DoublePredicateAssert assertThat(DoublePredicate actual) {
return new DoublePredicateAssert(actual);
}

/**
* Create assertion for {@link java.util.concurrent.CompletionStage} by converting it to a {@link CompletableFuture} and returning a {@link CompletableFutureAssert}.
* <p>
* If the given {@link java.util.concurrent.CompletionStage} is null, the {@link CompletableFuture} in the returned {@link CompletableFutureAssert} will also be null.
*
* @param actual the actual value.
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.CompletionStage}.
*
* @return the created assertion object.
*/
@CheckReturnValue
public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletionStage<RESULT> actual) {
return new CompletableFutureAssert<>(actual);
}


}
@@ -0,0 +1,34 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2018 the original author or authors.
*/
package org.assertj.core.api;

import org.junit.Test;

import java.util.Date;

public class Assertions_avoid_ambiguous_reference_compilation_error_Test {

@Test
public void should_not_report_ambiguous_reference_compilation_error() {
// does not compile, explanation: https://stackoverflow.com/questions/29499847/ambiguous-method-in-java-8-why
// Assertions.assertThat(getDate()).isEqualTo(getDate());

// compiles since AssertionsForClassTypes does not provide assertThat for interfaces
AssertionsForClassTypes.assertThat(getDate()).isEqualTo(getDate());
}

protected static <T extends Date> T getDate() {
return (T) new Date(123);
}

}

0 comments on commit 43c3c6b

Please sign in to comment.