From d0ba47e75dede5fa71c22bc0ab0e831ec41edf1d Mon Sep 17 00:00:00 2001 From: ACHRAF TAITAI <43656331+achraftt@users.noreply.github.com> Date: Sat, 30 Jul 2022 14:22:59 +0200 Subject: [PATCH] BAEL-5643 : Replace at Specific Index in Java ArrayList (#12539) --- .../ReplaceUsingIndexInArrayListUnitTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/replace/ReplaceUsingIndexInArrayListUnitTest.java diff --git a/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/replace/ReplaceUsingIndexInArrayListUnitTest.java b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/replace/ReplaceUsingIndexInArrayListUnitTest.java new file mode 100644 index 0000000000..ad6d0fee43 --- /dev/null +++ b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/replace/ReplaceUsingIndexInArrayListUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.list.replace; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class ReplaceUsingIndexInArrayListUnitTest { + + private static final List EXPECTED = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); + + @Test void givenArrayList_updateUsingSet() { + List aList = new ArrayList<>(Arrays.asList(1, 2, 7, 4, 5)); + aList.set(2, 3); + assertThat(aList).isEqualTo(EXPECTED); + } +} \ No newline at end of file