From 759c1880ad85ec57d4ebc589fd151ab02adcb05b Mon Sep 17 00:00:00 2001 From: George Date: Fri, 13 Dec 2024 20:56:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=20`SupplierTest`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/function/SupplierTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 function/src/test/java/com/sogeor/framework/function/SupplierTest.java diff --git a/function/src/test/java/com/sogeor/framework/function/SupplierTest.java b/function/src/test/java/com/sogeor/framework/function/SupplierTest.java new file mode 100644 index 0000000..e5266ca --- /dev/null +++ b/function/src/test/java/com/sogeor/framework/function/SupplierTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2024 Sogeor + * + * 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 com.sogeor.framework.function; + +import com.sogeor.framework.annotation.NonNull; +import com.sogeor.framework.throwable.fault.ImaginaryFault; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +final class SupplierTest { + + @Test + void methodDirect() { + final @NonNull var object = new Object(); + final @NonNull var supplier = Supplier.direct(object); + assertNotNull(supplier); + + assertEquals(object, supplier.get()); + } + + @Test + void methodOf() { + final @NonNull var object = new Object(); + final @NonNull var supplier = Supplier.of(() -> object); + assertNotNull(supplier); + + assertEquals(object, supplier.get()); + } + + @Test + void methodOrPassed() { + final @NonNull var object = new Object(); + final @NonNull var supplier = Supplier.of(() -> { + throw new RuntimeException(); + }).orPassed(object); + assertNotNull(supplier); + + assertEquals(object, supplier.get()); + } + + @Test + void methodOrSupplied() { + final @NonNull var object = new Object(); + final @NonNull var supplier = Supplier.of(() -> { + throw new RuntimeException(); + }).orSupplied(Supplier.direct(object)); + assertNotNull(supplier); + + assertEquals(object, supplier.get()); + } + +}