Finding the Minimum Value in an ArrayList along with the Index Number… (#13498)

* Finding the Minimum Value in an ArrayList along with the Index Number in Java

* BAEL-6147: rename test unit method

* adapt test method name
This commit is contained in:
ACHRAF TAITAI 2023-03-28 14:09:47 +02:00 committed by GitHub
parent f5fa90c236
commit e8fe289f85
1 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.baeldung.java_8_features.Person;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -71,4 +72,17 @@ public class Java8MaxMinUnitTest {
assertEquals(bugatti, maxBySpeed); assertEquals(bugatti, maxBySpeed);
} }
@Test
public void givenIntegerList_whenGetMinAndIndex_thenSuccess() {
final List<Integer> listOfIntegers = Arrays.asList(11, 13, 9, 20, 7, 3, 30);
final Integer expectedMinValue = 3;
final Integer expectedMinIndex = 5;
Integer minValue = Collections.min(listOfIntegers);
Integer minIndex = listOfIntegers.indexOf(minValue);
assertEquals(minValue, expectedMinValue);
assertEquals(minIndex, expectedMinIndex);
}
} }