Skip to content

Commit 7b836d9

Browse files
bxnkolezhendrikse
authored andcommitted
Pairs functionality in Java (Core Java, Apache Commons and Vavr) (eugenp#2563)
* Unit tests for pairs functionality in Java (Core Java, Apache Commons and Vavr) * Remove default file templates * Refactor mustache * BAEL-1123 - Testing Linked List for Cycles - deep20jain@gmail.com (eugenp#2525) * Adding node and cycle detection by hashing * Adding implementation for all algorithms for cycle detection and removal * Applying formatting rules * JDeferred (eugenp#2553) * moving jmh into libraries module * refactoring jmh * Update pom.xml * manual algorightm * with BM result * fix for space issue * Fixed indentation * change as per suggestion * vavr either * adding unit test and othe rutilities * adding concurrent module * concurrent package description * concurrent package description * Update EitherUnitTest.java * introducing lambda expression * jooby project * jooby project * reducing employee bean content * bootique module * bootique * bootique * undertow module * undertow module * refactoring * using lambda * as per baeldung formatter * easy code added for simplicity * simpliflying * adding JDeferred module * moved jdeferred to librarires module * BAEL-1116 Spring swagger codegen (eugenp#2527) * Spring integration with Swagger client code genrator * Refactor * format pom.xml * BAEL-1106 Introduction to javax.measure (eugenp#2522) * BAEL-243 Spring Batch using Partitioner * BAEL-1106 Introduction to javax.measure * Unnecessary Committed * BAEL-1106 Move code to libraries from core-java * BAEL-1106 Move code to libraries from core-java * Update pom.xml * Introduced jmh benchmarking (eugenp#2549) * Bael 1043/protonpack (eugenp#2415) * BAEL-1043/ Introduction to protonpack * Added test cases for windowed() api * Resolving merge issues * Retrofit rx (eugenp#2519) * Retrofit with RxJava * Correct spelling mistake * Use spaces for indentation instead of tabs in pom.xml * Use spaces for indentation instead of tabs in pom.xml * Add Retrofit integration with RxJava to libraries module * Remove standalone project for Retrofit integration with RxJava * remove retrofit-rxjava module * Fixed error in pom.xml caused by an issue while merging * Retrofit integration with RxJava * Fix test cases * Fix merge issues * BAEL-1016 Merging master * import source BAEL-1084 (eugenp#2560) * Moved to libraries folder from core-java
1 parent 0d599ae commit 7b836d9

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.pairs;
2+
3+
import org.apache.commons.lang3.tuple.ImmutablePair;
4+
import org.apache.commons.lang3.tuple.MutablePair;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
public class ApacheCommonsPairUnitTest {
9+
10+
@Test
11+
public void givenMutablePair_whenGetValue_shouldPass() {
12+
int key = 5;
13+
String value = "Five";
14+
15+
MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
16+
Assert.assertTrue(mutablePair.getKey() == key);
17+
Assert.assertEquals(mutablePair.getValue(), value);
18+
}
19+
20+
@Test
21+
public void givenMutablePair_whenSetValue_shouldPass() {
22+
int key = 6;
23+
String value = "Six";
24+
String newValue = "New Six";
25+
26+
MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
27+
Assert.assertTrue(mutablePair.getKey() == key);
28+
Assert.assertEquals(mutablePair.getValue(), value);
29+
mutablePair.setValue(newValue);
30+
Assert.assertEquals(mutablePair.getValue(), newValue);
31+
}
32+
33+
@Test
34+
public void givenImmutablePair_whenGetValue_shouldPass() {
35+
int key = 2;
36+
String value = "Two";
37+
38+
ImmutablePair<Integer, String> immutablePair = new ImmutablePair<>(key, value);
39+
Assert.assertTrue(immutablePair.getKey() == key);
40+
Assert.assertEquals(immutablePair.getValue(), value);
41+
}
42+
43+
@Test(expected = UnsupportedOperationException.class)
44+
public void givenImmutablePair_whenSetValue_shouldFail() {
45+
ImmutablePair<Integer, String> immutablePair = new ImmutablePair<>(1, "One");
46+
immutablePair.setValue("Another One");
47+
}
48+
49+
50+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.pairs;
2+
3+
import javafx.util.Pair;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class CoreJavaPairUnitTest {
8+
@Test
9+
public void givenPair_whenGetValue_shouldSucceed() {
10+
String key = "Good Day";
11+
boolean value = true;
12+
Pair<String, Boolean> pair = new Pair<>(key, value);
13+
14+
Assert.assertEquals(key, pair.getKey());
15+
Assert.assertEquals(value, pair.getValue());
16+
}
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.pairs;
2+
3+
import io.vavr.Tuple2;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class VavrPairsUnitTest {
8+
@Test
9+
public void givenTuple_whenSetValue_shouldSucceed() {
10+
String key = "Eleven";
11+
double value = 11.0;
12+
double newValue = 11.1;
13+
14+
Tuple2<String, Double> pair = new Tuple2<>(key, value);
15+
16+
pair = pair.update2(newValue);
17+
Assert.assertTrue(newValue == pair._2());
18+
}
19+
20+
@Test
21+
public void givenPair_whenGetValue_shouldSucceed() {
22+
String key = "Twelve";
23+
double value = 12.0;
24+
25+
Tuple2<String, Double> pair = new Tuple2<>(key, value);
26+
27+
Assert.assertTrue(value == pair._2());
28+
}
29+
}

0 commit comments

Comments
 (0)