1+ package com .baeldung .findanelement ;
2+
3+ import static org .junit .Assert .assertNull ;
4+ import static org .junit .Assert .assertTrue ;
5+ import java .util .ArrayList ;
6+ import java .util .List ;
7+ import org .junit .Test ;
8+
9+ public class FindAnElementTest {
10+
11+ private static List <Integer > scores = new ArrayList <>();
12+ static {
13+ scores .add (0 );
14+ scores .add (1 );
15+ scores .add (2 );
16+ }
17+
18+ private static FindElementInAList <Integer > findElementInAList = new FindElementInAList <>();
19+
20+ @ Test
21+ public void givenElement_whenFoundUsingIndexOf_thenReturnElement () {
22+ Integer scoreToFind = 1 ;
23+ Integer score = findElementInAList .findUsingIndexOf (scoreToFind , scores );
24+ assertTrue (score .equals (scoreToFind ));
25+ }
26+
27+ @ Test
28+ public void givenElement_whenNotFoundUsingListIterator_thenReturnNull () {
29+ boolean found = findElementInAList .findUsingListIterator (5 , scores );
30+ assertTrue (!found );
31+ }
32+
33+ @ Test
34+ public void givenElement_whenFoundListIterator_thenReturnElement () {
35+ Integer scoreToFind = 1 ;
36+ boolean found = findElementInAList .findUsingListIterator (scoreToFind , scores );
37+ assertTrue (found );
38+ }
39+
40+ @ Test
41+ public void givenElement_whenNotFoundUsingIndexOf_thenReturnNull () {
42+ Integer score = findElementInAList .findUsingIndexOf (5 , scores );
43+ assertNull (score );
44+ }
45+
46+ @ Test
47+ public void givenElement_whenFoundUsingEnhancedForLoop_thenReturnElement () {
48+ Integer scoreToFind = 1 ;
49+ boolean found = findElementInAList .findUsingEnhancedForLoop (scoreToFind , scores );
50+ assertTrue (found );
51+ }
52+
53+ @ Test
54+ public void givenElement_whenNotFoundUsingEnhancedForLoop_thenReturnNull () {
55+ Integer scoreToFind = 5 ;
56+ boolean found = findElementInAList .findUsingEnhancedForLoop (scoreToFind , scores );
57+ assertTrue (!found );
58+ }
59+
60+ @ Test
61+ public void givenElement_whenFoundUsingStream_thenReturnElement () {
62+ Integer scoreToFind = 1 ;
63+ Integer score = findElementInAList .findUsingStream (scoreToFind , scores );
64+ assertTrue (score .equals (scoreToFind ));
65+ }
66+
67+ @ Test
68+ public void givenElement_whenNotFoundUsingStream_thenReturnNull () {
69+ Integer scoreToFind = 5 ;
70+ Integer score = findElementInAList .findUsingStream (scoreToFind , scores );
71+ assertNull (score );
72+ }
73+
74+ @ Test
75+ public void givenElement_whenFoundUsingParallelStream_thenReturnElement () {
76+ Integer scoreToFind = 1 ;
77+ Integer score = findElementInAList .findUsingParallelStream (scoreToFind , scores );
78+ assertTrue (score .equals (scoreToFind ));
79+ }
80+
81+ @ Test
82+ public void givenElement_whenNotFoundUsingParallelStream_thenReturnNull () {
83+ Integer scoreToFind = 5 ;
84+ Integer score = findElementInAList .findUsingParallelStream (scoreToFind , scores );
85+ assertNull (score );
86+ }
87+
88+ @ Test
89+ public void givenElement_whenFoundUsingGuava_thenReturnElement () {
90+ Integer scoreToFind = 1 ;
91+ Integer score = findElementInAList .findUsingGuava (scoreToFind , scores );
92+ assertTrue (score .equals (scoreToFind ));
93+ }
94+
95+ @ Test
96+ public void givenElement_whenNotFoundUsingGuava_thenReturnNull () {
97+ Integer scoreToFind = 5 ;
98+ Integer score = findElementInAList .findUsingGuava (scoreToFind , scores );
99+ assertNull (score );
100+ }
101+
102+ @ Test
103+ public void givenElement_whenFoundUsingApacheCommons_thenReturnElement () {
104+ Integer scoreToFind = 1 ;
105+ Integer score = findElementInAList .findUsingApacheCommon (scoreToFind , scores );
106+ assertTrue (score .equals (scoreToFind ));
107+ }
108+
109+ @ Test
110+ public void givenElement_whenNotFoundUsingApacheCommons_thenReturnNull () {
111+ Integer scoreToFind = 5 ;
112+ Integer score = findElementInAList .findUsingApacheCommon (scoreToFind , scores );
113+ assertNull (score );
114+ }
115+
116+ }
0 commit comments