Pairs functionality in Java (Core Java, Apache Commons and Vavr) (#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 (#2525)

* Adding node and cycle detection by hashing

* Adding implementation for all algorithms for cycle detection and removal

* Applying formatting rules

* JDeferred (#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 (#2527)

* Spring integration with Swagger client code genrator

* Refactor

* format pom.xml

* BAEL-1106 Introduction to javax.measure (#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 (#2549)

* Bael 1043/protonpack (#2415)

* BAEL-1043/ Introduction to protonpack

* Added test cases for windowed() api

* Resolving merge issues

* Retrofit rx (#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 (#2560)

* Moved to libraries folder from core-java
This commit is contained in:
bankole salako 2017-09-05 16:51:08 +01:00 committed by Zeger Hendrikse
parent 0d599aeca1
commit 7b836d9211
3 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package com.baeldung.pairs;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.MutablePair;
import org.junit.Assert;
import org.junit.Test;
public class ApacheCommonsPairUnitTest {
@Test
public void givenMutablePair_whenGetValue_shouldPass() {
int key = 5;
String value = "Five";
MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
Assert.assertTrue(mutablePair.getKey() == key);
Assert.assertEquals(mutablePair.getValue(), value);
}
@Test
public void givenMutablePair_whenSetValue_shouldPass() {
int key = 6;
String value = "Six";
String newValue = "New Six";
MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
Assert.assertTrue(mutablePair.getKey() == key);
Assert.assertEquals(mutablePair.getValue(), value);
mutablePair.setValue(newValue);
Assert.assertEquals(mutablePair.getValue(), newValue);
}
@Test
public void givenImmutablePair_whenGetValue_shouldPass() {
int key = 2;
String value = "Two";
ImmutablePair<Integer, String> immutablePair = new ImmutablePair<>(key, value);
Assert.assertTrue(immutablePair.getKey() == key);
Assert.assertEquals(immutablePair.getValue(), value);
}
@Test(expected = UnsupportedOperationException.class)
public void givenImmutablePair_whenSetValue_shouldFail() {
ImmutablePair<Integer, String> immutablePair = new ImmutablePair<>(1, "One");
immutablePair.setValue("Another One");
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.pairs;
import javafx.util.Pair;
import org.junit.Assert;
import org.junit.Test;
public class CoreJavaPairUnitTest {
@Test
public void givenPair_whenGetValue_shouldSucceed() {
String key = "Good Day";
boolean value = true;
Pair<String, Boolean> pair = new Pair<>(key, value);
Assert.assertEquals(key, pair.getKey());
Assert.assertEquals(value, pair.getValue());
}
}

View File

@ -0,0 +1,29 @@
package com.baeldung.pairs;
import io.vavr.Tuple2;
import org.junit.Assert;
import org.junit.Test;
public class VavrPairsUnitTest {
@Test
public void givenTuple_whenSetValue_shouldSucceed() {
String key = "Eleven";
double value = 11.0;
double newValue = 11.1;
Tuple2<String, Double> pair = new Tuple2<>(key, value);
pair = pair.update2(newValue);
Assert.assertTrue(newValue == pair._2());
}
@Test
public void givenPair_whenGetValue_shouldSucceed() {
String key = "Twelve";
double value = 12.0;
Tuple2<String, Double> pair = new Tuple2<>(key, value);
Assert.assertTrue(value == pair._2());
}
}