Merge branch 'master' of https://github.com/Maiklins/tutorials into BAEL-20598-Fix-unit-test-in-core-java-jndi-module

 Conflicts:
	core-java-modules/core-java-jndi/pom.xml
This commit is contained in:
mikr
2020-01-22 08:52:27 +01:00
53 changed files with 1187 additions and 483 deletions
@@ -1,6 +1,7 @@
package com.baeldung.rejection;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import java.util.ArrayList;
@@ -28,6 +29,7 @@ public class SaturationPolicyUnitTest {
}
}
@Ignore
@Test
public void givenAbortPolicy_WhenSaturated_ThenShouldThrowRejectedExecutionException() {
executor = new ThreadPoolExecutor(1, 1, 0, MILLISECONDS, new SynchronousQueue<>(), new AbortPolicy());
@@ -36,6 +38,7 @@ public class SaturationPolicyUnitTest {
assertThatThrownBy(() -> executor.execute(() -> System.out.println("Will be rejected"))).isInstanceOf(RejectedExecutionException.class);
}
@Ignore
@Test
public void givenCallerRunsPolicy_WhenSaturated_ThenTheCallerThreadRunsTheTask() {
executor = new ThreadPoolExecutor(1, 1, 0, MILLISECONDS, new SynchronousQueue<>(), new CallerRunsPolicy());
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>core-java-datetime-java8</artifactId>
<version>${project.parent.version}</version>
<name>core-java-datetime-java8</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>core-java-datetime-java8</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<joda-time.version>2.10</joda-time.version>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
</properties>
</project>
@@ -0,0 +1,31 @@
package com.baeldung.localdate;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
public class LocalDateExample {
public LocalDate getCustomDateOne(int year, int month, int dayOfMonth) {
return LocalDate.of(year, month, dayOfMonth);
}
public LocalDate getCustomDateTwo(int year, Month month, int dayOfMonth) {
return LocalDate.of(year, month, dayOfMonth);
}
public LocalDate getDateFromEpochDay(long epochDay) {
return LocalDate.ofEpochDay(epochDay);
}
public LocalDate getDateFromYearAndDayOfYear(int year, int dayOfYear) {
return LocalDate.ofYearDay(year, dayOfYear);
}
public LocalDate getDateFromString(String date) {
return LocalDate.parse(date);
}
public LocalDate getDateFromStringAndFormatter(String date, String pattern) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(pattern));
}
}
@@ -1,4 +1,4 @@
package com.baeldung.datebasics;
package com.baeldung.localdate;
import static org.junit.Assert.assertEquals;
@@ -6,49 +6,34 @@ import java.time.Month;
import org.junit.Test;
public class CreateDateUnitTest {
private CreateDate date = new CreateDate();
@Test
public void whenUsingNowMethod_thenLocalDate() {
assertEquals("2020-01-08", date.getTodaysDate());
}
@Test
public void whenUsingClock_thenLocalDate() {
assertEquals("2020-01-08", date.getTodaysDateFromClock());
}
@Test
public void givenValues_whenUsingZone_thenLocalDate() {
assertEquals("2020-01-08", date.getTodaysDateFromZone("Asia/Kolkata"));
}
public class LocalDateExampleUnitTest {
private LocalDateExample date = new LocalDateExample();
@Test
public void givenValues_whenUsingOfMethod_thenLocalDate() {
assertEquals("2020-01-08", date.getCustomDateOne(2020, 1, 8));
}
@Test
public void givenValuesWithMonthEnum_whenUsingOfMethod_thenLocalDate() {
assertEquals("2020-01-08", date.getCustomDateTwo(2020, Month.JANUARY, 8));
}
@Test
public void givenValues_whenUsingEpochDay_thenLocalDate() {
assertEquals("2020-01-08", date.getDateFromEpochDay(18269));
}
@Test
public void givenValues_whenUsingYearDay_thenLocalDate() {
assertEquals("2020-01-08", date.getDateFromYearAndDayOfYear(2020, 8));
}
@Test
public void givenValues_whenUsingParse_thenLocalDate() {
assertEquals("2020-01-08", date.getDateFromString("2020-01-08"));
}
@Test
public void givenValuesWithFormatter_whenUsingParse_thenLocalDate() {
assertEquals("2020-01-08", date.getDateFromStringAndFormatter("8-Jan-2020", "d-MMM-yyyy"));
@@ -1,45 +0,0 @@
package com.baeldung.datebasics;
import java.time.Clock;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
public class CreateDate {
public LocalDate getTodaysDate() {
return LocalDate.now();
}
public LocalDate getTodaysDateFromClock() {
return LocalDate.now(Clock.systemDefaultZone());
}
public LocalDate getTodaysDateFromZone(String zone) {
return LocalDate.now(ZoneId.of(zone));
}
public LocalDate getCustomDateOne(int year, int month, int dayOfMonth) {
return LocalDate.of(year, month, dayOfMonth);
}
public LocalDate getCustomDateTwo(int year, Month month, int dayOfMonth) {
return LocalDate.of(year, month, dayOfMonth);
}
public LocalDate getDateFromEpochDay(long epochDay) {
return LocalDate.ofEpochDay(epochDay);
}
public LocalDate getDateFromYearAndDayOfYear(int year, int dayOfYear) {
return LocalDate.ofYearDay(year, dayOfYear);
}
public LocalDate getDateFromString(String date) {
return LocalDate.parse(date);
}
public LocalDate getDateFromStringAndFormatter(String date, String pattern) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(pattern));
}
}
@@ -1,5 +1,6 @@
package com.baeldung.file;
import org.junit.Ignore;
import org.junit.Test;
import java.io.*;
@@ -73,6 +74,7 @@ public class FileClassUnitTest {
assertFalse(writable);
}
@Ignore
@Test
public void givenWriteOnlyFile_whenCreateNewFile_thenCantReadFile() {
File parentDir = makeDir("writeDir");
+8 -3
View File
@@ -9,10 +9,9 @@
<name>core-java-jndi</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
@@ -22,6 +21,12 @@
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@@ -1,5 +1,12 @@
package com.baeldung.jndi.exceptions;
import static org.junit.jupiter.api.Assertions.assertThrows;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NoInitialContextException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -7,15 +14,10 @@ import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.jndi.JndiTemplate;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NoInitialContextException;
import static org.junit.jupiter.api.Assertions.assertThrows;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class JndiExceptionsUnitTest {
@Disabled
@Test
@Order(1)
void givenNoContext_whenLookupObject_thenThrowNoInitialContext() {
@@ -2,7 +2,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<packaging>jar</packaging>
@@ -8,8 +8,8 @@
<version>1.0</version>
<parent>
<groupId>decoupling-pattern2</groupId>
<artifactId>com.baeldung.decoupling-pattern2</artifactId>
<groupId>com.baeldung.decoupling-pattern2</groupId>
<artifactId>decoupling-pattern2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
@@ -8,8 +8,8 @@
<version>1.0</version>
<parent>
<groupId>decoupling-pattern2</groupId>
<artifactId>com.baeldung.decoupling-pattern2</artifactId>
<groupId>com.baeldung.decoupling-pattern2</groupId>
<artifactId>decoupling-pattern2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
@@ -3,13 +3,12 @@
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>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<version>1.0</version>
<parent>
<groupId>decoupling-pattern2</groupId>
<artifactId>>com.baeldung.decoupling-pattern2</artifactId>
<groupId>com.baeldung.decoupling-pattern2</groupId>
<artifactId>decoupling-pattern2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>core-java-jpms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>core-java-jpms</name>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modules>
<module>decoupling-pattern1</module>
<module>decoupling-pattern2</module>
</modules>
</project>
@@ -2,7 +2,7 @@ package com.baeldung.exitvshalt;
import org.junit.Test;
public class JvmExitDemoUnitTest {
public class JvmExitDemoManualTest {
JvmExitAndHaltDemo jvmExitAndHaltDemo = new JvmExitAndHaltDemo();
@@ -2,7 +2,7 @@ package com.baeldung.exitvshalt;
import org.junit.Test;
public class JvmHaltDemoUnitTest {
public class JvmHaltDemoManualTest {
JvmExitAndHaltDemo jvmExitAndHaltDemo = new JvmExitAndHaltDemo();
@@ -1,6 +1,8 @@
package com.baeldung.optional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class Person {
private String name;
@@ -21,7 +23,7 @@ public class Person {
}
public Optional<Integer> getAge() {
return Optional.ofNullable(age);
return Optional.of(age);
}
public void setAge(int age) {
@@ -36,4 +38,37 @@ public class Person {
return Optional.ofNullable(password);
}
public static List<Person> search(List<Person> people, String name, Optional<Integer> age) {
// Null checks for people and name
return people.stream()
.filter(p -> p.getName().equals(name))
.filter(p -> p.getAge().get() >= age.orElse(0))
.collect(Collectors.toList());
}
public static List<Person> search(List<Person> people, String name, Integer age) {
// Null checks for people and name
final Integer ageFilter = age != null ? age : 0;
return people.stream()
.filter(p -> p.getName().equals(name))
.filter(p -> p.getAge().get() >= ageFilter)
.collect(Collectors.toList());
}
public static List<Person> search(List<Person> people, String name) {
return doSearch(people, name, 0);
}
public static List<Person> search(List<Person> people, String name, int age) {
return doSearch(people, name, age);
}
private static List<Person> doSearch(List<Person> people, String name, int age) {
// Null checks for people and name
return people.stream()
.filter(p -> p.getName().equals(name))
.filter(p -> p.getAge().get().intValue() >= age)
.collect(Collectors.toList());
}
}
+103 -4
View File
@@ -14,11 +14,110 @@
</parent>
<modules>
<module>pre-jpms</module>
<module>core-java-optional</module>
<module>core-java-lang-operators</module>
<module>core-java-networking-2</module>
<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-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</module>
<module>core-java-arrays-2</module>
<module>core-java-collections</module>
<module>core-java-collections-2</module>
<module>core-java-collections-3</module>
<module>core-java-collections-array-list</module>
<module>core-java-collections-list</module>
<module>core-java-collections-list-2</module>
<module>core-java-collections-list-3</module>
<module>core-java-collections-set</module>
<module>core-java-concurrency-2</module>
<module>core-java-concurrency-advanced</module>
<module>core-java-concurrency-advanced-2</module>
<module>core-java-concurrency-advanced-3</module>
<module>core-java-concurrency-basic</module>
<module>core-java-concurrency-basic-2</module>
<module>core-java-concurrency-collections</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-exceptions</module>
<module>core-java-exceptions-2</module>
<module>core-java-function</module>
<module>core-java-io</module>
<module>core-java-io-2</module>
<module>core-java-io-apis</module>
<module>core-java-io-conversions</module>
<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-lambdas</module>
<module>core-java-lang</module>
<module>core-java-lang-2</module>
<module>core-java-lang-math</module>
<module>core-java-lang-oop</module>
<module>core-java-lang-oop-2</module>
<module>core-java-lang-oop-3</module>
<module>core-java-lang-oop-4</module>
<module>core-java-lang-operators</module>
<module>core-java-lang-syntax</module>
<module>core-java-lang-syntax-2</module>
<module>core-java-networking</module>
<module>core-java-networking-2</module>
<module>core-java-nio</module>
<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>
<module>core-java-reflection</module>
<module>core-java-security</module>
<module>core-java-streams</module>
<module>core-java-streams-2</module>
<module>core-java-streams-3</module>
<module>core-java-string-algorithms</module>
<module>core-java-string-algorithms-2</module>
<module>core-java-string-algorithms-3</module>
<module>core-java-string-apis</module>
<module>core-java-string-conversions</module>
<module>core-java-string-conversions-2</module>
<module>core-java-string-operations</module>
<module>core-java-string-operations-2</module>
<module>core-java-strings</module>
<module>core-java-sun</module>
<module>core-java-text</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>
</project>