From 04d24d161a8609bb8e4fe4024d2f14c3584449aa Mon Sep 17 00:00:00 2001 From: Ashley <73482956+ascopes@users.noreply.github.com> Date: Sun, 23 Oct 2022 12:47:19 +0100 Subject: [PATCH] Closes #112 - remove MaybeAssert --- .../ascopes/jct/assertions/MaybeAssert.java | 87 ------------------- 1 file changed, 87 deletions(-) delete mode 100644 java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/MaybeAssert.java diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/MaybeAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/MaybeAssert.java deleted file mode 100644 index 04ae5aee4..000000000 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/MaybeAssert.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2022 - 2022 Ashley Scopes - * - * 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. - */ -package io.github.ascopes.jct.assertions; - -import io.github.ascopes.jct.annotations.Nullable; -import java.util.Optional; -import java.util.function.Supplier; -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.AssertFactory; - - -/** - * An assertion on an optionally present value. - * - *

Unlike {@link org.assertj.core.api.OptionalAssert}, this implementation has stronger - * semantics and is designed to be used as the proxy to an optionally present result rather than the - * target value to perform assertions on. - * - * @param the inner assertion type to use. - * @param the inner value to assert on. - * @author Ashley Scopes - * @since 0.0.1 - */ -@API(since = "0.0.1", status = Status.EXPERIMENTAL) -public final class MaybeAssert, A> - extends AbstractAssert, Optional> { - - private final AssertFactory assertFactory; - private final Supplier existsAssertionErrorSupplier; - private final Supplier doesNotExistAssertionErrorSupplier; - - /** - * Initialize these assertions. - * - * @param actual the actual nullable value to assert on. - * @param assertFactory the assertion factory to use on the value. - * @param existsAssertionErrorSupplier supplier of error messages when the value unexpectedly - * exists. - */ - public MaybeAssert( - @Nullable A actual, - AssertFactory assertFactory, - Supplier existsAssertionErrorSupplier, - Supplier doesNotExistAssertionErrorSupplier - ) { - super(Optional.ofNullable(actual), MaybeAssert.class); - this.assertFactory = assertFactory; - this.existsAssertionErrorSupplier = existsAssertionErrorSupplier; - this.doesNotExistAssertionErrorSupplier = doesNotExistAssertionErrorSupplier; - } - - /** - * Get the assertions for the value, asserting that it is present first. - * - * @return the assertions on the value. - */ - public I exists() { - if (actual.isEmpty()) { - throw failure("Expected a value to be present but it was not"); - } - return assertFactory.createAssert(actual.get()); - } - - /** - * Assert that a value is not present. - */ - public void doesNotExist() { - if (actual.isPresent()) { - throw failure("Expected no value to be present but got %s", actual); - } - } -}