From 16b8708d25efc7c23962d143a5ce78f091621a6c Mon Sep 17 00:00:00 2001 From: Imran Alam <75203259+Imranalam28@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:20:31 +0530 Subject: [PATCH] Update SinglePeakFinderUnitTest.java --- .../peakelements/SinglePeakFinderUnitTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/src/test/java/com/baeldung/peakelements/SinglePeakFinderUnitTest.java b/core-java-modules/core-java-collections-array-list-2/src/test/java/com/baeldung/peakelements/SinglePeakFinderUnitTest.java index a847afa504..f2448ec255 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/test/java/com/baeldung/peakelements/SinglePeakFinderUnitTest.java +++ b/core-java-modules/core-java-collections-array-list-2/src/test/java/com/baeldung/peakelements/SinglePeakFinderUnitTest.java @@ -2,12 +2,23 @@ package com.baeldung.peakelements; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.OptionalInt; public class SinglePeakFinderUnitTest { @Test void findSinglePeak_givenArrayOfIntegers_whenValidInput_thenReturnsCorrectPeak() { int[] arr = {0, 10, 2, 4, 5, 1}; - assertEquals(10, SinglePeakFinder.findSinglePeak(arr)); + OptionalInt peak = SinglePeakFinder.findSinglePeak(arr); + assertTrue(peak.isPresent()); + assertEquals(10, peak.getAsInt()); + } + + @Test + void findSinglePeak_givenEmptyArray_thenReturnsEmptyOptional() { + int[] arr = {}; + OptionalInt peak = SinglePeakFinder.findSinglePeak(arr); + assertTrue(peak.isEmpty()); } }