Merge branch 'eugenp:master' into master
This commit is contained in:
commit
4670671add
@ -4,6 +4,4 @@ This module contains articles about Apache CXF
|
||||
|
||||
## Relevant Articles:
|
||||
|
||||
- [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api)
|
||||
- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring)
|
||||
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
|
||||
|
@ -19,7 +19,7 @@
|
||||
<dependency>
|
||||
<groupId>org.axonframework</groupId>
|
||||
<artifactId>axon-bom</artifactId>
|
||||
<version>${axon.version}</version>
|
||||
<version>${axon-bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@ -57,7 +57,7 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<axon.version>4.5.0</axon.version>
|
||||
<axon-bom.version>4.5.13</axon-bom.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,45 @@
|
||||
package com.baeldung.httpclient.parameters;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HttpClientParametersLiveTest {
|
||||
|
||||
private static HttpClient client;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
client = HttpClient.newHttpClient();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenQueryParams_whenGetRequest_thenResponseOk() throws IOException, InterruptedException {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.uri(URI.create("https://postman-echo.com/get?param1=value1¶m2=value2"))
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
assertEquals(response.statusCode(), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenQueryParams_whenGetRequestWithDefaultConfiguration_thenResponseOk() throws IOException, InterruptedException {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://postman-echo.com/get?param1=value1¶m2=value2"))
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
assertEquals(response.statusCode(), 200);
|
||||
}
|
||||
|
||||
}
|
@ -13,5 +13,4 @@ This module contains articles about the Java List collection
|
||||
- [Finding the Differences Between Two Lists in Java](https://www.baeldung.com/java-lists-difference)
|
||||
- [List vs. ArrayList in Java](https://www.baeldung.com/java-list-vs-arraylist)
|
||||
- [How to Store HashMap<String, ArrayList> Inside a List](https://www.baeldung.com/java-hashmap-inside-list)
|
||||
- [Working With a List of Lists in Java](https://www.baeldung.com/java-list-of-lists)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-collections-list-2)
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
public class SneakyRunnable implements Runnable {
|
||||
|
||||
@SneakyThrows
|
||||
public void run() {
|
||||
try {
|
||||
throw new InterruptedException();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new SneakyRunnable().run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SneakyThrows {
|
||||
|
||||
|
||||
public static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
|
||||
throw (E) e;
|
||||
}
|
||||
|
||||
public static void throwsSneakyIOException() {
|
||||
sneakyThrow(new IOException("sneaky"));
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
throwsSneakyIOException();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
public class SneakyThrowsExamples {
|
||||
|
||||
public static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
|
||||
throw (E) e;
|
||||
}
|
||||
|
||||
public static void throwSneakyIOException() {
|
||||
sneakyThrow(new IOException("sneaky"));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void throwSneakyIOExceptionUsingLombok() {
|
||||
throw new IOException("lombok sneaky");
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class SneakyRunnableUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCallSneakyRunnableMethod_thenThrowException() {
|
||||
try {
|
||||
new SneakyRunnable().run();
|
||||
} catch (Exception e) {
|
||||
assertEquals(InterruptedException.class, e.getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOException;
|
||||
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SneakyThrowsExamplesUnitTest {
|
||||
|
||||
@Test
|
||||
public void throwSneakyIOException_IOExceptionShouldBeThrown() {
|
||||
assertThatThrownBy(() -> throwSneakyIOException())
|
||||
.isInstanceOf(IOException.class)
|
||||
.hasMessage("sneaky")
|
||||
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwSneakyIOExceptionUsingLombok_IOExceptionShouldBeThrown() {
|
||||
assertThatThrownBy(() -> throwSneakyIOExceptionUsingLombok())
|
||||
.isInstanceOf(IOException.class)
|
||||
.hasMessage("lombok sneaky")
|
||||
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok");
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class SneakyThrowsUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCallSneakyMethod_thenThrowSneakyException() {
|
||||
try {
|
||||
SneakyThrows.throwsSneakyIOException();
|
||||
} catch (Exception ex) {
|
||||
assertEquals("sneaky", ex.getMessage().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.baeldung.threebool;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ThreeBooleans {
|
||||
public static boolean twoOrMoreAreTrueByLoop(boolean a, boolean b, boolean c) {
|
||||
int count = 0;
|
||||
for (boolean i : new Boolean[] { a, b, c }) {
|
||||
count += i ? 1 : 0;
|
||||
if (count >= 2)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean xOrMoreAreTrueByLoop(boolean[] booleans, int x) {
|
||||
int count = 0;
|
||||
for (boolean i : booleans) {
|
||||
count += i ? 1 : 0;
|
||||
if (count >= x)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean twoOrMoreAreTrueBySum(boolean a, boolean b, boolean c) {
|
||||
return (a ? 1 : 0) + (b ? 1 : 0) + (c ? 1 : 0) >= 2;
|
||||
}
|
||||
|
||||
public static boolean xOrMoreAreTrueBySum(Boolean[] booleans, int x) {
|
||||
return Arrays.stream(booleans).mapToInt(b -> Boolean.TRUE.equals(b) ? 1 : 0).sum() >= x;
|
||||
}
|
||||
|
||||
public static boolean twoorMoreAreTrueByKarnaughMap(boolean a, boolean b, boolean c) {
|
||||
return (c && (a || b)) || (a && b);
|
||||
}
|
||||
|
||||
public static boolean twoOrMoreAreTrueByOperators(boolean a, boolean b, boolean c) {
|
||||
return (a && b) || (a && c) || (b && c);
|
||||
}
|
||||
|
||||
public static boolean twoOrMoreAreTrueByXor(boolean a, boolean b, boolean c) {
|
||||
return a ^ b ? c : a;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.baeldung.threebool;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ThreeBooleansUnitTest {
|
||||
// @formatter:off
|
||||
private static final Map<boolean[], Boolean> TEST_CASES_AND_EXPECTED = ImmutableMap.of(
|
||||
new boolean[]{true, true, true}, true,
|
||||
new boolean[]{true, true, false}, true,
|
||||
new boolean[]{true, false, false}, false,
|
||||
new boolean[]{false, false, false}, false
|
||||
);
|
||||
// @formatter:on
|
||||
|
||||
@Test
|
||||
void given3Booleans_whenCallingTwoOrMoreAreTrueByLoop_thenGetExpectedResult() {
|
||||
TEST_CASES_AND_EXPECTED.forEach((array, expected) -> assertThat(ThreeBooleans.twoOrMoreAreTrueByLoop(array[0], array[1], array[2])).isEqualTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
void given3Booleans_whenCallingTwoOrMoreAreTrueByCounting_thenGetExpectedResult() {
|
||||
TEST_CASES_AND_EXPECTED.forEach((array, expected) -> assertThat(ThreeBooleans.twoOrMoreAreTrueBySum(array[0], array[1], array[2])).isEqualTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
void given3Booleans_whenCallingTwoOrMoreAreTrueByKarnaughMap_thenGetExpectedResult() {
|
||||
TEST_CASES_AND_EXPECTED.forEach((array, expected) -> assertThat(ThreeBooleans.twoorMoreAreTrueByKarnaughMap(array[0], array[1], array[2])).isEqualTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
void given3Booleans_whenCallingTwoOrMoreAreTrueByOperators_thenGetExpectedResult() {
|
||||
TEST_CASES_AND_EXPECTED.forEach((array, expected) -> assertThat(ThreeBooleans.twoOrMoreAreTrueByOperators(array[0], array[1], array[2])).isEqualTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
void given3Booleans_whenCallingTwoOrMoreAreTrueByXor_thenGetExpectedResult() {
|
||||
TEST_CASES_AND_EXPECTED.forEach((array, expected) -> assertThat(ThreeBooleans.twoOrMoreAreTrueByXor(array[0], array[1], array[2])).isEqualTo(expected));
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,25 @@
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.baeldung.reflection.privatemethods;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static Integer validateAndDouble(Integer input) {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("input should not be null");
|
||||
}
|
||||
return doubleInteger(input);
|
||||
}
|
||||
|
||||
private static Integer doubleInteger(Integer input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
return 2 * input;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.baeldung.reflection.privatemethods;
|
||||
|
||||
import static com.baeldung.reflection.privatemethods.Utils.validateAndDouble;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UtilsUnitTest {
|
||||
|
||||
// Let's start with the tests of the public API
|
||||
@Test
|
||||
void givenNull_WhenValidateAndDouble_ThenThrows() {
|
||||
assertThrows(IllegalArgumentException.class, () -> validateAndDouble(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenANonNullInteger_WhenValidateAndDouble_ThenDoublesIt() {
|
||||
assertEquals(4, validateAndDouble(2));
|
||||
}
|
||||
|
||||
// Further on, let's test the private method
|
||||
@Test
|
||||
void givenNull_WhenDoubleInteger_ThenNull() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
assertEquals(null, getDoubleIntegerMethod().invoke(null, new Integer[] { null }));
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenANonNullInteger_WhenDoubleInteger_ThenDoubleIt() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
assertEquals(74, getDoubleIntegerMethod().invoke(null, 37));
|
||||
}
|
||||
|
||||
private Method getDoubleIntegerMethod() throws NoSuchMethodException {
|
||||
Method method = Utils.class.getDeclaredMethod("doubleInteger", Integer.class);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
}
|
@ -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]](../java-numbers) [[next -->]](../java-numbers-3)
|
@ -9,10 +9,9 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
@ -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)
|
||||
- More articles: [[<-- prev]](../java-numbers-2) [[next -->]](../java-numbers-4)
|
@ -7,10 +7,9 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
@ -10,3 +10,4 @@
|
||||
- [Generate a Random Value From an Enum](https://www.baeldung.com/java-enum-random-value)
|
||||
- [Reverse a Number in Java](https://www.baeldung.com/java-reverse-number)
|
||||
- [Check if BigDecimal Value Is Zero](https://www.baeldung.com/java-bigdecimal-zero)
|
||||
- More articles: [[<-- prev]](../java-numbers-3)
|
@ -7,10 +7,9 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
@ -13,4 +13,4 @@ This module contains articles about numbers in Java.
|
||||
- [Convert Double to String, Removing Decimal Places](https://www.baeldung.com/java-double-to-string)
|
||||
- [Changing the Order in a Sum Operation Can Produce Different Results?](https://www.baeldung.com/java-floating-point-sum-order)
|
||||
- [Using Math.sin with Degrees](https://www.baeldung.com/java-math-sin-degrees)
|
||||
- More articles: [[next -->]](/../java-numbers-2)
|
||||
- More articles: [[next -->]](../java-numbers-2)
|
@ -9,10 +9,9 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user