Merge branch 'master' of github.com:eugenp/tutorials into master

This commit is contained in:
Karsten Silz 2020-09-21 20:14:46 +01:00
commit 5e2147e6f4
22 changed files with 262 additions and 32 deletions

View File

@ -7,7 +7,7 @@ import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
public class AppUnitTest
extends TestCase
{
/**
@ -15,7 +15,7 @@ public class AppTest
*
* @param testName name of the test case
*/
public AppTest( String testName )
public AppUnitTest(String testName )
{
super( testName );
}
@ -25,7 +25,7 @@ public class AppTest
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
return new TestSuite( AppUnitTest.class );
}
/**

View File

@ -5,7 +5,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
public class StringAPITest {
public class StringAPIUnitTest {
@Test
public void whenPositiveArgument_thenReturnIndentedString() {

View File

@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class PersonTest {
public class PersonUnitTest {
@Test
public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() {

View File

@ -44,6 +44,16 @@
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
<build>
@ -77,6 +87,7 @@
<maven.compiler.target>1.9</maven.compiler.target>
<guava.version>25.1-jre</guava.version>
<commons-collections4.version>4.1</commons-collections4.version>
<commons-collections3.version>3.2.2</commons-collections3.version>
</properties>
</project>

View File

@ -17,7 +17,7 @@ import org.junit.Test;
/**
* Test case for the {@link MethodHandles} API
*/
public class MethodHandlesTest {
public class MethodHandlesUnitTest {
@Test
public void givenConcatMethodHandle_whenInvoked_thenCorrectlyConcatenated() throws Throwable {

View File

@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
public class TimestampToStringConverterTest {
public class TimestampToStringConverterUnitTest {
@Test
public void givenDatePattern_whenFormatting_thenResultingStringIsCorrect() {

View File

@ -17,7 +17,7 @@
<dependencies>
<dependency>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<artifactId>servicemodule1</artifactId>
<version>${servicemodule.version}</version>
</dependency>
</dependencies>

View File

@ -4,7 +4,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>servicemodule</artifactId>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule1</artifactId>
<packaging>jar</packaging>
<parent>

View File

@ -17,7 +17,7 @@
<dependencies>
<dependency>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<artifactId>servicemodule2</artifactId>
<version>${servicemodule.version}</version>
</dependency>
</dependencies>

View File

@ -4,7 +4,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>servicemodule</artifactId>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule2</artifactId>
<version>1.0</version>
<parent>

View File

@ -4,7 +4,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class CurrentDirectoryFetcherTest {
public class CurrentDirectoryFetcherUnitTest {
private static final String CURRENT_DIR = "core-java-os";

View File

@ -0,0 +1,19 @@
package com.baeldung.reflection.check.staticmethods;
import java.time.LocalDate;
import java.time.LocalTime;
public class StaticUtility {
public static String getAuthorName() {
return "Umang Budhwar";
}
public static LocalDate getLocalDate() {
return LocalDate.now();
}
public static LocalTime getLocalTime() {
return LocalTime.now();
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.reflection.check.staticmethods;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class StaticUtilityUnitTest {
@Test
void whenCheckStaticMethod_ThenSuccess() throws Exception {
Method method = StaticUtility.class.getMethod("getAuthorName", null);
Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
}
@Test
void whenCheckAllStaticMethods_thenSuccess() {
List<Method> methodList = Arrays.asList(StaticUtility.class.getMethods())
.stream()
.filter(method -> Modifier.isStatic(method.getModifiers()))
.collect(Collectors.toList());
Assertions.assertEquals(3, methodList.size());
}
}

View File

@ -0,0 +1,35 @@
package com.baeldung.cipher;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.security.Provider;
import java.security.Security;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class AvailableCiphersUnitTest {
private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class);
@Test
public void whenGetServices_thenGetAllCipherAlgorithms() {
for (Provider provider : Security.getProviders()) {
for (Provider.Service service : provider.getServices()) {
logger.info(service.getAlgorithm());
}
}
}
@Test
public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() {
List<String> algorithms = Arrays.stream(Security.getProviders())
.flatMap(provider -> provider.getServices().stream())
.filter(service -> "Cipher".equals(service.getType()))
.map(Provider.Service::getAlgorithm)
.collect(Collectors.toList());
algorithms.forEach(logger::info);
}
}

View File

@ -20,6 +20,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -20,6 +20,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -38,6 +38,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -33,6 +33,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -18,20 +18,9 @@
<modules>
<module>core-java</module>
<!-- <module>core-java-10</module> --> <!-- We haven't upgraded to java 10. Fixing in BAEL-10841 -->
<!-- <module>core-java-11</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
<!-- <module>core-java-12</module> --> <!-- We haven't upgraded to java 12. Fixing in BAEL-10841 -->
<!-- <module>core-java-13</module> --> <!-- We haven't upgraded to java 12. Fixing in BAEL-10841 -->
<!-- <module>core-java-14</module> --> <!-- We haven't upgraded to java 14.-->
<module>core-java-8</module>
<module>core-java-8-2</module>
<!-- <module>core-java-9</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<!-- <module>core-java-9-improvements</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<!-- <module>core-java-9-jigsaw</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<!-- <module>core-java-9-new-features</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<!-- <module>core-java-9-streams</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<module>core-java-annotations</module>
<module>core-java-arrays-sorting</module>
@ -51,7 +40,6 @@
<module>core-java-collections-maps</module>
<module>core-java-collections-maps-2</module>
<module>core-java-collections-maps-3</module>
<!-- <module>core-java-collections-set</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
<module>core-java-concurrency-2</module>
<module>core-java-concurrency-advanced</module>
@ -65,10 +53,7 @@
<!--<module>core-java-8-datetime</module>--> <!-- unit test case failure -->
<module>core-java-8-datetime-2</module>
<!-- <module>core-java-date-operations-1</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<module>core-java-date-operations-2</module>
<!-- We haven't upgraded to java 9. -->
<!-- <module>core-java-datetime-computations</module> <module>core-java-datetime-conversion</module> <module>core-java-datetime-java8</module> <module>core-java-datetime-string</module> -->
<module>core-java-8-datetime</module>
<module>core-java-exceptions</module>
@ -85,7 +70,6 @@
<module>core-java-jar</module>
<module>core-java-jndi</module>
<!-- <module>core-java-jpms</module> --> <!-- We haven't upgraded to java 10. Fixing in BAEL-10841 -->
<module>core-java-jvm</module>
<module>core-java-jvm-2</module>
@ -113,7 +97,6 @@
<module>core-java-nio-2</module>
<module>core-java-optional</module>
<!--<module>core-java-os</module> --> <!-- We haven't upgraded to java 9. -->
<module>core-java-perf</module>
@ -138,9 +121,6 @@
<module>core-java-sun</module>
<module>core-java-regex</module>
<!-- <module>core-java-time-measurements</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<!-- <module>multimodulemavenproject</module> --> <!-- We haven't upgraded to java 9. Fixing in BAEL-10841 -->
<module>pre-jpms</module>
</modules>

View File

@ -0,0 +1,18 @@
package com.baeldung.lombok.builder;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
@Builder(builderMethodName = "internalBuilder")
@Getter
public class RequiredFieldAnnotation {
@NonNull
String name;
String description;
public static RequiredFieldAnnotationBuilder builder(String name) {
return internalBuilder().name(name);
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.lombok.builder;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RequiredFieldAnnotationUnitTest {
RequiredFieldAnnotation requiredFieldTest;
@Before
public void setUp() {
requiredFieldTest = RequiredFieldAnnotation.builder("NameField").description("Field Description").build();
}
@Test
public void givenBuilderWithRequiredParameter_thenParameterIsPresent() {
assertEquals("NameField", requiredFieldTest.getName());
}
}

98
pom.xml
View File

@ -1334,6 +1334,104 @@
</profile>
<profile>
<id>default-jdk9-and-above</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>SpringContextTest</include>
<include>**/*UnitTest</include>
</includes>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LongRunningUnitTest.java</exclude>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/JdbcTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>core-java-modules/core-java-9</module>
<module>core-java-modules/core-java-9-improvements</module>
<!-- <module>core-java-modules/core-java-9-jigsaw</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-9-new-features</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-9-streams</module>
<module>core-java-modules/core-java-10</module>
<!-- <module>core-java-modules/core-java-11</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-12</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-13</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-14</module> --> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-collections-set</module>
<!-- <module>core-java-modules/core-java-date-operations-1</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-datetime-conversion</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-datetime-string</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-jpms</module>
<!-- <module>core-java-modules/core-java-os</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-time-measurements</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/multimodulemavenproject</module>
<!-- <module>maven-java-11</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
</modules>
</profile>
<profile>
<id>integration-jdk9-and-above</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*IntTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>core-java-modules/core-java-9</module>
<module>core-java-modules/core-java-9-improvements</module>
<!-- <module>core-java-modules/core-java-9-jigsaw</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-9-new-features</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-9-streams</module>
<module>core-java-modules/core-java-10</module>
<!-- <module>core-java-modules/core-java-11</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-12</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-13</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-14</module> --> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-collections-set</module>
<!-- <module>core-java-modules/core-java-date-operations-1</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-datetime-conversion</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-datetime-string</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/core-java-jpms</module>
<!-- <module>core-java-modules/core-java-os</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<!-- <module>core-java-modules/core-java-time-measurements</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
<module>core-java-modules/multimodulemavenproject</module>
<!-- <module>maven-java-11</module>--> <!-- to be fixed in http://team.baeldung.com/browse/JAVA-2824 -->
</modules>
</profile>
</profiles>
<reporting>