Merge branch 'master' into BAEL-3758_AOP_Annotations_jcabi-aspects
This commit is contained in:
@@ -31,10 +31,10 @@ public class UserServerUnitTest extends JUnitRouteTest {
|
|||||||
.assertStatusCode(404);
|
.assertStatusCode(404);
|
||||||
|
|
||||||
appRoute.run(HttpRequest.DELETE("/users/1"))
|
appRoute.run(HttpRequest.DELETE("/users/1"))
|
||||||
.assertStatusCode(200);
|
.assertStatusCode(405);
|
||||||
|
|
||||||
appRoute.run(HttpRequest.DELETE("/users/42"))
|
appRoute.run(HttpRequest.DELETE("/users/42"))
|
||||||
.assertStatusCode(200);
|
.assertStatusCode(405);
|
||||||
|
|
||||||
appRoute.run(HttpRequest.POST("/users")
|
appRoute.run(HttpRequest.POST("/users")
|
||||||
.withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, zaphod())))
|
.withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, zaphod())))
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
|
|||||||
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
|
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
|
||||||
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
|
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
|
||||||
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||||
|
- [Implementing A* Pathfinding in Java](https://www.baeldung.com/java-a-star-pathfinding)
|
||||||
- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)
|
- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ public class SlopeOne {
|
|||||||
for (Item j : InputData.items) {
|
for (Item j : InputData.items) {
|
||||||
if (e.getValue().containsKey(j)) {
|
if (e.getValue().containsKey(j)) {
|
||||||
clean.put(j, e.getValue().get(j));
|
clean.put(j, e.getValue().get(j));
|
||||||
} else {
|
} else if (!clean.containsKey(j)) {
|
||||||
clean.put(j, -1.0);
|
clean.put(j, -1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,8 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
|
|||||||
- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
|
- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
|
||||||
- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher)
|
- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher)
|
||||||
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
|
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
|
||||||
|
- [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm)
|
||||||
|
- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray)
|
||||||
|
- [How to Merge Two Sorted Arrays](https://www.baeldung.com/java-merge-sorted-arrays)
|
||||||
|
- [Median of Stream of Integers using Heap](https://www.baeldung.com/java-stream-integers-median-using-heap)
|
||||||
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4)
|
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4)
|
||||||
|
|||||||
+141
@@ -0,0 +1,141 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbinarytree;
|
||||||
|
|
||||||
|
public class AVLTree {
|
||||||
|
|
||||||
|
public class Node {
|
||||||
|
int key;
|
||||||
|
int height;
|
||||||
|
Node left;
|
||||||
|
Node right;
|
||||||
|
|
||||||
|
Node(int key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node root;
|
||||||
|
|
||||||
|
public Node find(int key) {
|
||||||
|
Node current = root;
|
||||||
|
while (current != null) {
|
||||||
|
if (current.key == key) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = current.key < key ? current.right : current.left;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(int key) {
|
||||||
|
root = insert(root, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(int key) {
|
||||||
|
root = delete(root, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int height() {
|
||||||
|
return root == null ? -1 : root.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node insert(Node node, int key) {
|
||||||
|
if (node == null) {
|
||||||
|
return new Node(key);
|
||||||
|
} else if (node.key > key) {
|
||||||
|
node.left = insert(node.left, key);
|
||||||
|
} else if (node.key < key) {
|
||||||
|
node.right = insert(node.right, key);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("duplicate Key!");
|
||||||
|
}
|
||||||
|
return rebalance(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node delete(Node node, int key) {
|
||||||
|
if (node == null) {
|
||||||
|
return node;
|
||||||
|
} else if (node.key > key) {
|
||||||
|
node.left = delete(node.left, key);
|
||||||
|
} else if (node.key < key) {
|
||||||
|
node.right = delete(node.right, key);
|
||||||
|
} else {
|
||||||
|
if (node.left == null || node.right == null) {
|
||||||
|
node = (node.left == null) ? node.right : node.left;
|
||||||
|
} else {
|
||||||
|
Node mostLeftChild = mostLeftChild(node.right);
|
||||||
|
node.key = mostLeftChild.key;
|
||||||
|
node.right = delete(node.right, node.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node != null) {
|
||||||
|
node = rebalance(node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node mostLeftChild(Node node) {
|
||||||
|
Node current = node;
|
||||||
|
/* loop down to find the leftmost leaf */
|
||||||
|
while (current.left != null) {
|
||||||
|
current = current.left;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node rebalance(Node z) {
|
||||||
|
updateHeight(z);
|
||||||
|
int balance = getBalance(z);
|
||||||
|
if (balance > 1) {
|
||||||
|
if (height(z.right.right) > height(z.right.left)) {
|
||||||
|
z = rotateLeft(z);
|
||||||
|
} else {
|
||||||
|
z.right = rotateRight(z.right);
|
||||||
|
z = rotateLeft(z);
|
||||||
|
}
|
||||||
|
} else if (balance < -1) {
|
||||||
|
if (height(z.left.left) > height(z.left.right)) {
|
||||||
|
z = rotateRight(z);
|
||||||
|
} else {
|
||||||
|
z.left = rotateLeft(z.left);
|
||||||
|
z = rotateRight(z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node rotateRight(Node y) {
|
||||||
|
Node x = y.left;
|
||||||
|
Node z = x.right;
|
||||||
|
x.right = y;
|
||||||
|
y.left = z;
|
||||||
|
updateHeight(y);
|
||||||
|
updateHeight(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node rotateLeft(Node y) {
|
||||||
|
Node x = y.right;
|
||||||
|
Node z = x.left;
|
||||||
|
x.left = y;
|
||||||
|
y.right = z;
|
||||||
|
updateHeight(y);
|
||||||
|
updateHeight(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateHeight(Node n) {
|
||||||
|
n.height = 1 + Math.max(height(n.left), height(n.right));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int height(Node n) {
|
||||||
|
return n == null ? -1 : n.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBalance(Node n) {
|
||||||
|
return (n == null) ? 0 : height(n.right) - height(n.left);
|
||||||
|
}
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbrackets;
|
||||||
|
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class BalancedBracketsUsingDeque {
|
||||||
|
|
||||||
|
public boolean isBalanced(String str) {
|
||||||
|
if (null == str || ((str.length() % 2) != 0)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
char[] ch = str.toCharArray();
|
||||||
|
for (char c : ch) {
|
||||||
|
if (!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Deque<Character> deque = new LinkedList<>();
|
||||||
|
for (char ch : str.toCharArray()) {
|
||||||
|
if (ch == '{' || ch == '[' || ch == '(') {
|
||||||
|
deque.addFirst(ch);
|
||||||
|
} else {
|
||||||
|
if (!deque.isEmpty() && ((deque.peekFirst() == '{' && ch == '}') || (deque.peekFirst() == '[' && ch == ']') || (deque.peekFirst() == '(' && ch == ')'))) {
|
||||||
|
deque.removeFirst();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbrackets;
|
||||||
|
|
||||||
|
public class BalancedBracketsUsingString {
|
||||||
|
|
||||||
|
public boolean isBalanced(String str) {
|
||||||
|
if (null == str || ((str.length() % 2) != 0)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
char[] ch = str.toCharArray();
|
||||||
|
for (char c : ch) {
|
||||||
|
if (!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (str.contains("()") || str.contains("[]") || str.contains("{}")) {
|
||||||
|
str = str.replaceAll("\\(\\)", "")
|
||||||
|
.replaceAll("\\[\\]", "")
|
||||||
|
.replaceAll("\\{\\}", "");
|
||||||
|
}
|
||||||
|
return (str.length() == 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbinarytree;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AVLTreeUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyTree_whenHeightCalled_shouldReturnMinus1() {
|
||||||
|
AVLTree tree = new AVLTree();
|
||||||
|
Assert.assertEquals(-1, tree.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyTree_whenInsertCalled_heightShouldBeZero() {
|
||||||
|
AVLTree tree = new AVLTree();
|
||||||
|
tree.insert(1);
|
||||||
|
Assert.assertEquals(0, tree.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyTree_whenInsertCalled_treeShouldBeAvl() {
|
||||||
|
AVLTree tree = new AVLTree();
|
||||||
|
tree.insert(1);
|
||||||
|
Assert.assertTrue(isAVL(tree));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSampleTree_whenInsertCalled_treeShouldBeAvl() {
|
||||||
|
AVLTree tree = getSampleAVLTree();
|
||||||
|
int newKey = 11;
|
||||||
|
tree.insert(newKey);
|
||||||
|
Assert.assertTrue(isAVL(tree));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSampleTree_whenFindExistingKeyCalled_shouldReturnMatchedNode() {
|
||||||
|
AVLTree tree = getSampleAVLTree();
|
||||||
|
int existingKey = 2;
|
||||||
|
AVLTree.Node result = tree.find(existingKey);
|
||||||
|
Assert.assertEquals(result.key, existingKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSampleTree_whenFindNotExistingKeyCalled_shouldReturnNull() {
|
||||||
|
AVLTree tree = getSampleAVLTree();
|
||||||
|
int notExistingKey = 11;
|
||||||
|
AVLTree.Node result = tree.find(notExistingKey);
|
||||||
|
Assert.assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyTree_whenDeleteCalled_treeShouldBeAvl() {
|
||||||
|
AVLTree tree = new AVLTree();
|
||||||
|
tree.delete(1);
|
||||||
|
Assert.assertTrue(isAVL(tree));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSampleTree_whenDeleteCalled_treeShouldBeAvl() {
|
||||||
|
AVLTree tree = getSampleAVLTree();
|
||||||
|
tree.delete(1);
|
||||||
|
Assert.assertTrue(isAVL(tree, tree.getRoot()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAVL(AVLTree tree) {
|
||||||
|
return isAVL(tree, tree.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAVL(AVLTree tree, AVLTree.Node node) {
|
||||||
|
if ( node == null )
|
||||||
|
return true;
|
||||||
|
int balance = tree.getBalance(node);
|
||||||
|
return (balance <= 1 && balance >= -1) && isAVL(tree, node.left) && isAVL(tree, node.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AVLTree getSampleAVLTree() {
|
||||||
|
AVLTree avlTree = new AVLTree();
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
avlTree.insert(i);
|
||||||
|
return avlTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbrackets;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class BalancedBracketsUsingDequeUnitTest {
|
||||||
|
private BalancedBracketsUsingDeque balancedBracketsUsingDeque;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
balancedBracketsUsingDeque = new BalancedBracketsUsingDeque();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced(null);
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidCharacterString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("abc[](){}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOddLengthString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{[]()}}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{[]()}}}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthUnbalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{[(])}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{[()]}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{[[(())]]}}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{([])}}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{)[](}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package com.baeldung.algorithms.balancedbrackets;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class BalancedBracketsUsingStringUnitTest {
|
||||||
|
private BalancedBracketsUsingString balancedBracketsUsingString;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
balancedBracketsUsingString = new BalancedBracketsUsingString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced(null);
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmptyString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidCharacterString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("abc[](){}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOddLengthString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{{[]()}}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{{[]()}}}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthUnbalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{[(])}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{[()]}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{{[[(())]]}}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{{([])}}");
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
|
boolean result = balancedBracketsUsingString.isBalanced("{{)[](}}");
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.baeldung.poi.excel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ExcelCellMergerUnitTest {
|
||||||
|
private static final String FILE_NAME = "ExcelCellFormatterTest.xlsx";
|
||||||
|
private String fileLocation;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws IOException, URISyntaxException {
|
||||||
|
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenCellIndex_whenAddMergeRegion_thenMergeRegionCreated() throws IOException {
|
||||||
|
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
assertEquals(0, sheet.getNumMergedRegions());
|
||||||
|
int firstRow = 0;
|
||||||
|
int lastRow = 0;
|
||||||
|
int firstCol = 0;
|
||||||
|
int lastCol = 2;
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
|
||||||
|
assertEquals(1, sheet.getNumMergedRegions());
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenCellRefString_whenAddMergeRegion_thenMergeRegionCreated() throws IOException {
|
||||||
|
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
assertEquals(0, sheet.getNumMergedRegions());
|
||||||
|
sheet.addMergedRegion(CellRangeAddress.valueOf("A1:C1"));
|
||||||
|
assertEquals(1, sheet.getNumMergedRegions());
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,4 +7,4 @@ This module contains articles about Apache Spark
|
|||||||
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
||||||
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
||||||
- [Machine Learning with Spark MLlib](https://www.baeldung.com/spark-mlib-machine-learning)
|
- [Machine Learning with Spark MLlib](https://www.baeldung.com/spark-mlib-machine-learning)
|
||||||
|
- [Introduction to Spark Graph Processing with GraphFrames](https://www.baeldung.com/spark-graph-graphframes)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles
|
||||||
|
|
||||||
|
- [Intro to Apache Tapestry](https://www.baeldung.com/apache-tapestry)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [AWS S3 with Java – Reactive Support](https://www.baeldung.com/java-aws-s3-reactive)
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||||
<version>3.3.0-01</version>
|
<version>${groovy.compiler.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
|||||||
@@ -28,17 +28,16 @@ class CategoryUnitTest extends GroovyTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://team.baeldung.com/browse/BAEL-20687
|
void test_whenUsingTimeCategory_thenOperationOnNumber() {
|
||||||
// void test_whenUsingTimeCategory_thenOperationOnNumber() {
|
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
|
||||||
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
|
use (TimeCategory) {
|
||||||
// use (TimeCategory) {
|
assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
|
||||||
// assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
|
|
||||||
//
|
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
|
||||||
// sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
|
assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
|
||||||
// assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
|
assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
|
||||||
// assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
void test_whenUsingDOMCategory_thenOperationOnXML() {
|
void test_whenUsingDOMCategory_thenOperationOnXML() {
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ class WebserviceManualTest extends GroovyTestCase {
|
|||||||
assert stories.size() == 5
|
assert stories.size() == 5
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see BAEL-3753
|
|
||||||
void test_whenConsumingSoap_thenReceiveResponse() {
|
void test_whenConsumingSoap_thenReceiveResponse() {
|
||||||
def url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso"
|
def url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso"
|
||||||
def soapClient = new SOAPClient(url)
|
def soapClient = new SOAPClient(url)
|
||||||
@@ -90,7 +89,6 @@ class WebserviceManualTest extends GroovyTestCase {
|
|||||||
def words = response.NumberToWordsResponse
|
def words = response.NumberToWordsResponse
|
||||||
assert words == "one thousand two hundred and thirty four "
|
assert words == "one thousand two hundred and thirty four "
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void test_whenConsumingRestGet_thenReceiveResponse() {
|
void test_whenConsumingRestGet_thenReceiveResponse() {
|
||||||
def path = "/get"
|
def path = "/get"
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class ReadFileUnitTest extends Specification {
|
|||||||
assert lines.size(), 3
|
assert lines.size(), 3
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
def 'Should return file content in string using ReadFile.readFileString given filePath' () {
|
def 'Should return file content in string using ReadFile.readFileString given filePath' () {
|
||||||
given:
|
given:
|
||||||
def filePath = "src/main/resources/fileContent.txt"
|
def filePath = "src/main/resources/fileContent.txt"
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ This module contains articles about Java 11 core features
|
|||||||
- [Guide to jlink](https://www.baeldung.com/jlink)
|
- [Guide to jlink](https://www.baeldung.com/jlink)
|
||||||
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
|
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
|
||||||
- [Benchmark JDK Collections vs Eclipse Collections](https://www.baeldung.com/jdk-collections-vs-eclipse-collections)
|
- [Benchmark JDK Collections vs Eclipse Collections](https://www.baeldung.com/jdk-collections-vs-eclipse-collections)
|
||||||
|
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>${shade.plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -109,6 +109,7 @@
|
|||||||
<uberjar.name>benchmarks</uberjar.name>
|
<uberjar.name>benchmarks</uberjar.name>
|
||||||
<jmh.version>1.22</jmh.version>
|
<jmh.version>1.22</jmh.version>
|
||||||
<eclipse.collections.version>10.0.0</eclipse.collections.version>
|
<eclipse.collections.version>10.0.0</eclipse.collections.version>
|
||||||
|
<shade.plugin.version>10.0.0</shade.plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
### Relevant articles:
|
||||||
|
|
||||||
|
- [Java Switch Statement](https://www.baeldung.com/java-switch)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
--enable-preview
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
## Core Java 14
|
||||||
|
|
||||||
|
This module contains articles about Java 14.
|
||||||
|
|
||||||
|
### Relevant articles
|
||||||
|
|
||||||
|
- [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation)
|
||||||
@@ -1,53 +1,66 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<artifactId>core-java-14</artifactId>
|
||||||
<artifactId>core-java-14</artifactId>
|
<name>core-java-14</name>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<packaging>jar</packaging>
|
||||||
<name>core-java-14</name>
|
<url>http://maven.apache.org</url>
|
||||||
<packaging>jar</packaging>
|
|
||||||
<url>http://maven.apache.org</url>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>../../</relativePath>
|
<relativePath>../../</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit-jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit-jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<release>${maven.compiler.release}</release>
|
||||||
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${surefire.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>--enable-preview</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<build>
|
<properties>
|
||||||
<plugins>
|
<maven.compiler.release>14</maven.compiler.release>
|
||||||
<plugin>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source.version}</source>
|
|
||||||
<target>${maven.compiler.target.version}</target>
|
|
||||||
<compilerArgs>
|
|
||||||
<compilerArg>
|
|
||||||
--enable-preview
|
|
||||||
</compilerArg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${surefire.plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<argLine>--enable-preview</argLine>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source.version>14</maven.compiler.source.version>
|
|
||||||
<maven.compiler.target.version>14</maven.compiler.target.version>
|
|
||||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package com.baeldung.java14.textblocks;
|
||||||
|
|
||||||
|
public class TextBlocks13 {
|
||||||
|
public String getBlockOfHtml() {
|
||||||
|
return """
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<span>example text</span>
|
||||||
|
</body>
|
||||||
|
</html>""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNonStandardIndent() {
|
||||||
|
return """
|
||||||
|
Indent
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuery() {
|
||||||
|
return """
|
||||||
|
select "id", "user"
|
||||||
|
from "table"
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTextWithCarriageReturns() {
|
||||||
|
return """
|
||||||
|
separated with\r
|
||||||
|
carriage returns""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTextWithEscapes() {
|
||||||
|
return """
|
||||||
|
fun with\n
|
||||||
|
whitespace\t\r
|
||||||
|
and other escapes \"""
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedText(String parameter) {
|
||||||
|
return """
|
||||||
|
Some parameter: %s
|
||||||
|
""".formatted(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.java14.textblocks;
|
||||||
|
|
||||||
|
public class TextBlocks14 {
|
||||||
|
public String getIgnoredNewLines() {
|
||||||
|
return """
|
||||||
|
This is a long test which looks to \
|
||||||
|
have a newline but actually does not""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEscapedSpaces() {
|
||||||
|
return """
|
||||||
|
line 1
|
||||||
|
line 2 \s
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-26
@@ -15,36 +15,36 @@ import java.io.Serializable;
|
|||||||
*/
|
*/
|
||||||
public class MySerialClass implements Serializable {
|
public class MySerialClass implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final ObjectStreamField[] serialPersistentFields = null;
|
private static final ObjectStreamField[] serialPersistentFields = null;
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private void readObjectNoData() throws ObjectStreamException {
|
private void readObjectNoData() throws ObjectStreamException {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private Object writeReplace() throws ObjectStreamException {
|
private Object writeReplace() throws ObjectStreamException {
|
||||||
// ...
|
// ...
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private Object readResolve() throws ObjectStreamException {
|
private Object readResolve() throws ObjectStreamException {
|
||||||
// ...
|
// ...
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package com.baeldung.java14.textblocks;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class TextBlocks13UnitTest {
|
||||||
|
private TextBlocks13 subject = new TextBlocks13();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAnOldStyleMultilineString_whenComparing_thenEqualsTextBlock() {
|
||||||
|
String expected = "<html>\n"
|
||||||
|
+ "\n"
|
||||||
|
+ " <body>\n"
|
||||||
|
+ " <span>example text</span>\n"
|
||||||
|
+ " </body>\n"
|
||||||
|
+ "</html>";
|
||||||
|
assertThat(subject.getBlockOfHtml()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAnOldStyleString_whenComparing_thenEqualsTextBlock() {
|
||||||
|
String expected = "<html>\n\n <body>\n <span>example text</span>\n </body>\n</html>";
|
||||||
|
assertThat(subject.getBlockOfHtml()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAnIndentedString_thenMatchesIndentedOldStyle() {
|
||||||
|
assertThat(subject.getNonStandardIndent()).isEqualTo(" Indent\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAMultilineQuery_thenItCanContainUnescapedQuotes() {
|
||||||
|
assertThat(subject.getQuery()).contains("select \"id\", \"user\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAMultilineQuery_thenItEndWithANewline() {
|
||||||
|
assertThat(subject.getQuery()).endsWith("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenATextWithCarriageReturns_thenItContainsBoth() {
|
||||||
|
assertThat(subject.getTextWithCarriageReturns()).isEqualTo("separated with\r\ncarriage returns");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAStringWithEscapedWhitespace_thenItAppearsInTheResultingString() {
|
||||||
|
assertThat(subject.getTextWithEscapes()).contains("fun with\n\n")
|
||||||
|
.contains("whitespace\t\r\n")
|
||||||
|
.contains("and other escapes \"\"\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAFormattedString_thenTheParameterIsReplaced() {
|
||||||
|
assertThat(subject.getFormattedText("parameter")).contains("Some parameter: parameter");
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.java14.textblocks;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class TextBlocks14UnitTest {
|
||||||
|
private TextBlocks14 subject = new TextBlocks14();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAStringWithEscapedNewLines_thenTheResultHasNoNewLines() {
|
||||||
|
String expected = "This is a long test which looks to have a newline but actually does not";
|
||||||
|
assertThat(subject.getIgnoredNewLines()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenAStringWithEscapesSpaces_thenTheResultHasLinesEndingWithSpaces() {
|
||||||
|
String expected = "line 1\nline 2 \n";
|
||||||
|
assertThat(subject.getEscapedSpaces()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>spring-boot</classifier>
|
<classifier>spring-boot</classifier>
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user