Merge branch 'master' into JAVA-12732
This commit is contained in:
commit
72a9941130
Binary file not shown.
Binary file not shown.
|
@ -4,7 +4,6 @@
|
|||
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>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>akka-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -9,4 +9,4 @@ This module contains articles about conversions among Collection types and array
|
|||
- [Converting List to Map With a Custom Supplier](https://www.baeldung.com/list-to-map-supplier)
|
||||
- [Arrays.asList vs new ArrayList(Arrays.asList())](https://www.baeldung.com/java-arrays-aslist-vs-new-arraylist)
|
||||
- [Iterate Over a Set in Java](https://www.baeldung.com/java-iterate-set)
|
||||
- More articles: [[<-- prev]](../java-collections-conversions)
|
||||
- More articles: [[<-- prev]](../core-java-collections-conversions)
|
|
@ -3,9 +3,9 @@
|
|||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-conversions-2</artifactId>
|
||||
<artifactId>core-java-collections-conversions-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-conversions-2</name>
|
||||
<name>core-java-collections-conversions-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -33,7 +33,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-collections-conversions-2</finalName>
|
||||
<finalName>core-java-collections-conversions-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
|
@ -12,4 +12,4 @@ This module contains articles about conversions among Collection types and array
|
|||
- [Java 8 Collectors toMap](https://www.baeldung.com/java-collectors-tomap)
|
||||
- [Converting Iterable to Collection in Java](https://www.baeldung.com/java-iterable-to-collection)
|
||||
- [Converting Iterator to List](https://www.baeldung.com/java-convert-iterator-to-list)
|
||||
- More articles: [[next -->]](../java-collections-conversions-2)
|
||||
- More articles: [[next -->]](../core-java-collections-conversions-2)
|
|
@ -3,9 +3,9 @@
|
|||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-conversions</artifactId>
|
||||
<artifactId>core-java-collections-conversions</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-conversions</name>
|
||||
<name>core-java-collections-conversions</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-collections-conversions</finalName>
|
||||
<finalName>core-java-collections-conversions</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
|
@ -8,3 +8,4 @@
|
|||
- [Java Map – keySet() vs. entrySet() vs. values() Methods](https://www.baeldung.com/java-map-entries-methods)
|
||||
- [Java IdentityHashMap Class and Its Use Cases](https://www.baeldung.com/java-identityhashmap)
|
||||
- [How to Invert a Map in Java](https://www.baeldung.com/java-invert-map)
|
||||
- More articles: [[<-- prev]](../core-java-collections-maps-4)
|
|
@ -3,9 +3,9 @@
|
|||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-maps-3</artifactId>
|
||||
<artifactId>core-java-collections-maps-5</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-maps-3</name>
|
||||
<name>core-java-collections-maps-5</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
|
@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AccountUnitTest {
|
||||
public class AccountManualTest {
|
||||
|
||||
private Account account;
|
||||
|
|
@ -3,4 +3,5 @@
|
|||
## Core Java 8 Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain)
|
||||
- [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain)
|
||||
- [Use Cases for Static Methods in Java](https://www.baeldung.com/java-static-methods-use-cases)
|
||||
|
|
|
@ -14,6 +14,26 @@
|
|||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>${mockito-inline.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-function</finalName>
|
||||
<resources>
|
||||
|
@ -24,4 +44,10 @@
|
|||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<mockito-inline.version>3.8.0</mockito-inline.version>
|
||||
<assertj.version>3.22.0</assertj.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
public final class CustomStringUtils {
|
||||
|
||||
private CustomStringUtils() {}
|
||||
|
||||
public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; }
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
public class StaticCounter {
|
||||
|
||||
private static int counter = 0;
|
||||
|
||||
public static int incrementCounter() {
|
||||
return ++counter;
|
||||
}
|
||||
|
||||
public static int getCounterValue() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CollectionUtilsUnitTest {
|
||||
|
||||
@Test
|
||||
void givenListOfNumbers_whenReverseStaticMethodIsCalled_thenNumbersInReversedOrderAreReturned() {
|
||||
List<String> list = Arrays.asList("1", "2", "3");
|
||||
Collections.reverse(list);
|
||||
assertThat(list).containsExactly("3", "2", "1");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CustomStringUtilsUnitTest {
|
||||
|
||||
@Test
|
||||
void givenNonEmptyString_whenIsEmptyMethodIsCalled_thenFalseIsReturned() {
|
||||
boolean empty = CustomStringUtils.isEmpty("baeldung");
|
||||
assertThat(empty).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenEmptyString_whenIsEmptyMethodIsCalled_thenTrueIsReturned() {
|
||||
boolean empty = CustomStringUtils.isEmpty("");
|
||||
assertThat(empty).isTrue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class StaticCounterUnitTest {
|
||||
|
||||
@Test
|
||||
void givenStaticCounter_whenIncrementCounterIsCalled_thenValueIsIncresedByOne() {
|
||||
int oldValue = StaticCounter.getCounterValue();
|
||||
int newValue = StaticCounter.incrementCounter();
|
||||
assertThat(newValue).isEqualTo(oldValue + 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.staticmethods;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class StringUtilsUnitTest {
|
||||
|
||||
@Test
|
||||
void givenSimpleString_whenCapitalizeStaticMethodIsCalled_thenCapitalizedStringIsReturned() {
|
||||
String str = StringUtils.capitalize("baeldung");
|
||||
assertThat(str).isEqualTo("Baeldung");
|
||||
}
|
||||
|
||||
}
|
|
@ -9,4 +9,5 @@ This module contains articles about core Java input/output(IO) conversions.
|
|||
- [Converting a BufferedReader to a JSONObject](https://www.baeldung.com/java-bufferedreader-to-jsonobject)
|
||||
- [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array)
|
||||
- [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv)
|
||||
- [How to Convert InputStream to Base64 String](https://www.baeldung.com/java-inputstream-to-base64-string)
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-io-conversions)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.inputstreamtobase64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
/**
|
||||
* Test the Stream to base64 conversion
|
||||
*/
|
||||
public class InputStreamToBase64UnitTest {
|
||||
|
||||
/**
|
||||
* Test stream to base64 conversion
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void givenABinaryInputStream_whenItIsConvertedToBase64_thenItCanBeDecoded() throws Exception {
|
||||
// given a binary input stream
|
||||
InputStream sourceStream = getClass().getClassLoader().getResourceAsStream("logo.png");
|
||||
byte[] sourceBytes = IOUtils.toByteArray(sourceStream);
|
||||
|
||||
// when it is converted to base64
|
||||
String encodedString = Base64.getEncoder().encodeToString(sourceBytes);
|
||||
assertNotNull(encodedString);
|
||||
|
||||
// then it can be decoded
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
assertNotNull(decodedBytes);
|
||||
assertTrue(decodedBytes.length == sourceBytes.length);
|
||||
assertTrue(calculateChecksum(decodedBytes) == calculateChecksum(sourceBytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a checksum
|
||||
* @param bytes array of bytes to check
|
||||
* @return the total sum of all bytes
|
||||
*/
|
||||
private int calculateChecksum(byte[] bytes) {
|
||||
int checksum = 0;
|
||||
for(int index=0; index < bytes.length; index++) {
|
||||
checksum+=bytes[index];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -8,4 +8,5 @@ This module contains articles about JAR files
|
|||
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
|
||||
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
||||
- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
|
||||
[Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
|
||||
- [Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
|
||||
- [Creating JAR Files Programmatically](https://www.baeldung.com/jar-create-programatically)
|
||||
|
|
|
@ -6,3 +6,4 @@ This module contains articles about types in Java
|
|||
|
||||
- [Convert an Array of Primitives to an Array of Objects](https://www.baeldung.com/java-primitive-array-to-object-array)
|
||||
- [Check if an Enum Value Exists in Java](https://www.baeldung.com/java-search-enum-values)
|
||||
- [Generate a Random Value From an Enum](https://www.baeldung.com/java-enum-random-value)
|
||||
|
|
|
@ -13,4 +13,4 @@ This module contains articles about numbers in Java.
|
|||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||
- [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple)
|
||||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||
- More articles: [[<-- prev]](../java-numbers) [[next -->]](../java-numbers-3)
|
||||
- More articles: [[<-- prev]](../core-java-numbers) [[next -->]](../core-java-numbers-3)
|
|
@ -3,9 +3,9 @@
|
|||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-numbers-2</artifactId>
|
||||
<artifactId>core-java-numbers-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-numbers-2</name>
|
||||
<name>core-java-numbers-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-numbers-2</finalName>
|
||||
<finalName>core-java-numbers-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
|
@ -14,4 +14,4 @@ This module contains articles about numbers in Java.
|
|||
- [Print an Integer in Binary Format in Java](https://www.baeldung.com/java-print-integer-binary)
|
||||
- [Number Formatting in Java](https://www.baeldung.com/java-number-formatting)
|
||||
- [Division by Zero in Java: Exception, Infinity, or Not a Number](https://www.baeldung.com/java-division-by-zero)
|
||||
- More articles: [[<-- prev]](../java-numbers-2) [[next -->]](../java-numbers-4)
|
||||
- More articles: [[<-- prev]](../core-java-numbers-2) [[next -->]](../core-java-numbers-4)
|
|
@ -2,8 +2,8 @@
|
|||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-numbers-3</artifactId>
|
||||
<name>java-numbers-3</name>
|
||||
<artifactId>core-java-numbers-3</artifactId>
|
||||
<name>core-java-numbers-3</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -32,7 +32,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-numbers-3</finalName>
|
||||
<finalName>core-java-numbers-3</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue