From 42e89c72c275b4f4a86683aa375d3d93d8e34840 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sat, 25 Nov 2017 01:43:02 +0530 Subject: [PATCH 01/17] BEAL-1173 - Add EC2 metadata access class and Integration Test --- .../cloud/aws/SpringCloudAwsApplication.java | 2 + .../cloud/aws/ec2/EC2EnableMetadata.java | 9 +++ .../spring/cloud/aws/ec2/EC2Metadata.java | 62 +++++++++++++++++++ .../src/main/resources/aws-config.xml | 11 ++++ .../aws/ec2/EC2MetadataIntegrationTest.java | 61 ++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2EnableMetadata.java create mode 100644 spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2Metadata.java create mode 100644 spring-cloud/spring-cloud-aws/src/main/resources/aws-config.xml create mode 100644 spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java diff --git a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/SpringCloudAwsApplication.java b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/SpringCloudAwsApplication.java index 2c3909b3eb..81bbc579ec 100644 --- a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/SpringCloudAwsApplication.java +++ b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/SpringCloudAwsApplication.java @@ -2,8 +2,10 @@ package com.baeldung.spring.cloud.aws; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; @SpringBootApplication +@ImportResource("classpath:aws-config.xml") public class SpringCloudAwsApplication { public static void main(String[] args) { diff --git a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2EnableMetadata.java b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2EnableMetadata.java new file mode 100644 index 0000000000..03a7db26de --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2EnableMetadata.java @@ -0,0 +1,9 @@ +package com.baeldung.spring.cloud.aws.ec2; + +import org.springframework.cloud.aws.context.config.annotation.EnableContextInstanceData; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableContextInstanceData +public class EC2EnableMetadata { +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2Metadata.java b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2Metadata.java new file mode 100644 index 0000000000..9466c14560 --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/ec2/EC2Metadata.java @@ -0,0 +1,62 @@ +package com.baeldung.spring.cloud.aws.ec2; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component +public class EC2Metadata { + + @Value("${ami-id:N/A}") + private String amiId; + + @Value("${hostname:N/A}") + private String hostname; + + @Value("${instance-type:N/A}") + private String instanceType; + + @Value("${services/domain:N/A}") + private String serviceDomain; + + @Value("#{instanceData['Name'] ?: 'N/A'}") + private String name; + + public String getAmiId() { + return amiId; + } + + public String getHostname() { + return hostname; + } + + public String getInstanceType() { + return instanceType; + } + + public String getServiceDomain() { + return serviceDomain; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EC2Metadata [amiId="); + builder.append(amiId); + builder.append(", hostname="); + builder.append(hostname); + builder.append(", instanceType="); + builder.append(instanceType); + builder.append(", serviceDomain="); + builder.append(serviceDomain); + builder.append(", name="); + builder.append(name); + builder.append("]"); + return builder.toString(); + } +} diff --git a/spring-cloud/spring-cloud-aws/src/main/resources/aws-config.xml b/spring-cloud/spring-cloud-aws/src/main/resources/aws-config.xml new file mode 100644 index 0000000000..5ca48f6b1e --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/resources/aws-config.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java new file mode 100644 index 0000000000..1e75134194 --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java @@ -0,0 +1,61 @@ +package com.baeldung.spring.cloud.aws.ec2; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import com.amazonaws.regions.Regions; +import com.amazonaws.services.ec2.AmazonEC2; + +@SpringBootTest +@RunWith(SpringRunner.class) +@TestPropertySource("classpath:application-test.properties") +public class EC2MetadataIntegrationTest { + + private static final Logger logger = LoggerFactory.getLogger(EC2MetadataIntegrationTest.class); + + private boolean serverEc2; + + @Before + public void setUp() { + serverEc2 = Regions.getCurrentRegion() != null; + } + + @Autowired + private EC2Metadata eC2Metadata; + + @Autowired + private AmazonEC2 amazonEC2; + + @Test + public void whenEC2ClinentNotNull_thenSuccess() { + assertThat(amazonEC2).isNotNull(); + } + + @Test + public void whenEC2MetadataNotNull_thenSuccess() { + assertThat(eC2Metadata).isNotNull(); + } + + @Test + public void whenMetdataValuesNotNull_thenSuccess() { + Assume.assumeTrue(serverEc2); + assertThat(eC2Metadata.getAmiId()).isNotEqualTo("N/A"); + assertThat(eC2Metadata.getInstanceType()).isNotEqualTo("N/A"); + } + + @Test + public void whenMetadataLogged_thenSuccess() { + logger.info("Environment is EC2: {}", serverEc2); + logger.info(eC2Metadata.toString()); + } +} From edec7ddbe51d7b5e51dcd4fafb33a1599b02ed14 Mon Sep 17 00:00:00 2001 From: abialas Date: Fri, 24 Nov 2017 22:29:08 +0100 Subject: [PATCH 02/17] BAEL-1344 (#3081) * BAEL-1344 add java8 convert methods date, localdate, localdatetime * BAEL-1344 add java9 example * Move Date to LocalDate and LocalDateTime converters from core-java-8 to core-java-9 --- .../datetime/DateToLocalDateConverter.java | 35 --------- .../DateToLocalDateTimeConverter.java | 35 --------- .../DateToLocalDateConverterTest.java | 72 ----------------- .../DateToLocalDateTimeConverterTest.java | 78 ------------------- .../datetime/DateToLocalDateConverter.java | 19 ++++- .../DateToLocalDateTimeConverter.java | 19 ++++- .../LocalDateTimeToDateConverter.java | 2 +- .../datetime/LocalDateToDateConverter.java | 2 +- .../DateToLocalDateConverterTest.java | 48 ++++++++++++ .../DateToLocalDateTimeConverterTest.java | 54 +++++++++++++ .../LocalDateTimeToDateConverterTest.java | 2 +- .../LocalDateToDateConverterTest.java | 2 +- 12 files changed, 142 insertions(+), 226 deletions(-) delete mode 100644 core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateConverter.java delete mode 100644 core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateTimeConverter.java delete mode 100644 core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateConverterTest.java delete mode 100644 core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateTimeConverterTest.java rename {core-java-8/src/main/java/com/baeldung => core-java-9/src/main/java/com/baeldung/java9}/datetime/LocalDateTimeToDateConverter.java (94%) rename {core-java-8/src/main/java/com/baeldung => core-java-9/src/main/java/com/baeldung/java9}/datetime/LocalDateToDateConverter.java (94%) rename {core-java-8/src/test/java/com/baeldung => core-java-9/src/test/java/com/baeldung/java9}/datetime/LocalDateTimeToDateConverterTest.java (97%) rename {core-java-8/src/test/java/com/baeldung => core-java-9/src/test/java/com/baeldung/java9}/datetime/LocalDateToDateConverterTest.java (97%) diff --git a/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateConverter.java b/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateConverter.java deleted file mode 100644 index 8788aac747..0000000000 --- a/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateConverter.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package com.baeldung.datetime; - -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; - -/** - * Class which shows different ways of converting java.util.Date into java.time.LocalDate. - * - * @author abialas - * - */ -public class DateToLocalDateConverter { - - public static LocalDate convertToLocalDateViaInstant(Date dateToConvert) { - return dateToConvert.toInstant() - .atZone(ZoneId.systemDefault()) - .toLocalDate(); - } - - public static LocalDate convertToLocalDateViaSqlDate(Date dateToConvert) { - return new java.sql.Date(dateToConvert.getTime()).toLocalDate(); - } - - public static LocalDate convertToLocalDateViaMilisecond(Date dateToConvert) { - return Instant.ofEpochMilli(dateToConvert.getTime()) - .atZone(ZoneId.systemDefault()) - .toLocalDate(); - } - -} diff --git a/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateTimeConverter.java b/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateTimeConverter.java deleted file mode 100644 index f994023526..0000000000 --- a/core-java-8/src/main/java/com/baeldung/datetime/DateToLocalDateTimeConverter.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package com.baeldung.datetime; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.Date; - -/** - * Class which shows different ways of converting java.util.Date into java.time.LocalDateTime. - * - * @author abialas - * - */ -public class DateToLocalDateTimeConverter { - - public static LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) { - return dateToConvert.toInstant() - .atZone(ZoneId.systemDefault()) - .toLocalDateTime(); - } - - public static LocalDateTime convertToLocalDateTimeViaSqlTimestamp(Date dateToConvert) { - return new java.sql.Timestamp(dateToConvert.getTime()).toLocalDateTime(); - } - - public static LocalDateTime convertToLocalDateTimeViaMilisecond(Date dateToConvert) { - return Instant.ofEpochMilli(dateToConvert.getTime()) - .atZone(ZoneId.systemDefault()) - .toLocalDateTime(); - } - -} diff --git a/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateConverterTest.java b/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateConverterTest.java deleted file mode 100644 index 5de6ae3e59..0000000000 --- a/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateConverterTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - */ -package com.baeldung.datetime; - -import static org.junit.Assert.assertEquals; - -import java.time.LocalDate; -import java.time.temporal.ChronoField; -import java.util.Calendar; -import java.util.Date; - -import org.junit.Test; - -/** - * - * JUnits for {@link DateToLocalDateConverter} class. - * - * @author abialas - * - */ -public class DateToLocalDateConverterTest { - - @Test - public void shouldReturn10thNovember2010WhenConvertViaInstant() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10); - Date dateToConvert = calendar.getTime(); - - // when - LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaInstant(dateToConvert); - - // then - assertEquals(2010, localDate.get(ChronoField.YEAR)); - assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); - } - - @Test - public void shouldReturn10thNovember2010WhenConvertViaMiliseconds() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10); - Date dateToConvert = calendar.getTime(); - - // when - LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaMilisecond(dateToConvert); - - // then - assertEquals(2010, localDate.get(ChronoField.YEAR)); - assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); - } - - @Test - public void shouldReturn10thNovember2010WhenConvertViaSqlDate() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10); - Date dateToConvert = calendar.getTime(); - - // when - LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaSqlDate(dateToConvert); - - // then - assertEquals(2010, localDate.get(ChronoField.YEAR)); - assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); - } - -} diff --git a/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateTimeConverterTest.java b/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateTimeConverterTest.java deleted file mode 100644 index 6d8fb8ea93..0000000000 --- a/core-java-8/src/test/java/com/baeldung/datetime/DateToLocalDateTimeConverterTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - */ -package com.baeldung.datetime; - -import static org.junit.Assert.assertEquals; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoField; -import java.util.Calendar; -import java.util.Date; - -import org.junit.Test; - -/** - * - * JUnits for {@link DateToLocalDateTimeConverter} class. - * - * @author abialas - * - */ -public class DateToLocalDateTimeConverterTest { - - @Test - public void shouldReturn10thNovember2010time8hour20minWhenConvertViaInstant() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10, 8, 20); - Date dateToConvert = calendar.getTime(); - - // when - LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaInstant(dateToConvert); - - // then - assertEquals(2010, localDateTime.get(ChronoField.YEAR)); - assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); - assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); - assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); - } - - @Test - public void shouldReturn10thNovember2010time8hour20minWhenConvertViaMiliseconds() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10, 8, 20); - Date dateToConvert = calendar.getTime(); - - // when - LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaMilisecond(dateToConvert); - - // then - assertEquals(2010, localDateTime.get(ChronoField.YEAR)); - assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); - assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); - assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); - } - - @Test - public void shouldReturn10thNovember2010time8hour20minWhenConvertViaSqlTimestamp() { - // given - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 10, 10, 8, 20); - Date dateToConvert = calendar.getTime(); - - // when - LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaSqlTimestamp(dateToConvert); - - // then - assertEquals(2010, localDateTime.get(ChronoField.YEAR)); - assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); - assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); - assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); - assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); - } - -} diff --git a/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateConverter.java b/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateConverter.java index bafa9ebff1..c794c57e87 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateConverter.java +++ b/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateConverter.java @@ -3,18 +3,35 @@ */ package com.baeldung.java9.datetime; +import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; /** - * Class which shows a way to convert java.util.Date into java.time.LocalDate with new Java 1.9. + * Class which shows a way to convert java.util.Date into java.time.LocalDate. * * @author abialas * */ public class DateToLocalDateConverter { + public static LocalDate convertToLocalDateViaInstant(Date dateToConvert) { + return dateToConvert.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + } + + public static LocalDate convertToLocalDateViaSqlDate(Date dateToConvert) { + return new java.sql.Date(dateToConvert.getTime()).toLocalDate(); + } + + public static LocalDate convertToLocalDateViaMilisecond(Date dateToConvert) { + return Instant.ofEpochMilli(dateToConvert.getTime()) + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + } + public static LocalDate convertToLocalDate(Date dateToConvert) { return LocalDate.ofInstant(dateToConvert.toInstant(), ZoneId.systemDefault()); } diff --git a/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverter.java b/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverter.java index 538d5a9f63..17ca5b1122 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverter.java +++ b/core-java-9/src/main/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverter.java @@ -3,18 +3,35 @@ */ package com.baeldung.java9.datetime; +import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; /** - * Class which shows a way to convert java.util.Date into java.time.LocalDateTime with new Java 1.9. + * Class which shows a way to convert java.util.Date into java.time.LocalDateTime. * * @author abialas * */ public class DateToLocalDateTimeConverter { + public static LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) { + return dateToConvert.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); + } + + public static LocalDateTime convertToLocalDateTimeViaSqlTimestamp(Date dateToConvert) { + return new java.sql.Timestamp(dateToConvert.getTime()).toLocalDateTime(); + } + + public static LocalDateTime convertToLocalDateTimeViaMilisecond(Date dateToConvert) { + return Instant.ofEpochMilli(dateToConvert.getTime()) + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); + } + public static LocalDateTime convertToLocalDateTime(Date dateToConvert) { return LocalDateTime.ofInstant(dateToConvert.toInstant(), ZoneId.systemDefault()); } diff --git a/core-java-8/src/main/java/com/baeldung/datetime/LocalDateTimeToDateConverter.java b/core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverter.java similarity index 94% rename from core-java-8/src/main/java/com/baeldung/datetime/LocalDateTimeToDateConverter.java rename to core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverter.java index ef72c8b4fb..f219dcf038 100644 --- a/core-java-8/src/main/java/com/baeldung/datetime/LocalDateTimeToDateConverter.java +++ b/core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverter.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.datetime; +package com.baeldung.java9.datetime; import java.time.LocalDateTime; import java.time.ZoneId; diff --git a/core-java-8/src/main/java/com/baeldung/datetime/LocalDateToDateConverter.java b/core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateToDateConverter.java similarity index 94% rename from core-java-8/src/main/java/com/baeldung/datetime/LocalDateToDateConverter.java rename to core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateToDateConverter.java index 8050815799..f9893da5d0 100644 --- a/core-java-8/src/main/java/com/baeldung/datetime/LocalDateToDateConverter.java +++ b/core-java-9/src/main/java/com/baeldung/java9/datetime/LocalDateToDateConverter.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.datetime; +package com.baeldung.java9.datetime; import java.time.LocalDate; import java.time.ZoneId; diff --git a/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateConverterTest.java b/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateConverterTest.java index 2e0fb0dedd..ab69bba359 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateConverterTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateConverterTest.java @@ -22,6 +22,54 @@ import com.baeldung.java9.datetime.DateToLocalDateConverter; */ public class DateToLocalDateConverterTest { + @Test + public void shouldReturn10thNovember2010WhenConvertViaInstant() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10); + Date dateToConvert = calendar.getTime(); + + // when + LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaInstant(dateToConvert); + + // then + assertEquals(2010, localDate.get(ChronoField.YEAR)); + assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); + } + + @Test + public void shouldReturn10thNovember2010WhenConvertViaMiliseconds() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10); + Date dateToConvert = calendar.getTime(); + + // when + LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaMilisecond(dateToConvert); + + // then + assertEquals(2010, localDate.get(ChronoField.YEAR)); + assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); + } + + @Test + public void shouldReturn10thNovember2010WhenConvertViaSqlDate() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10); + Date dateToConvert = calendar.getTime(); + + // when + LocalDate localDate = DateToLocalDateConverter.convertToLocalDateViaSqlDate(dateToConvert); + + // then + assertEquals(2010, localDate.get(ChronoField.YEAR)); + assertEquals(11, localDate.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDate.get(ChronoField.DAY_OF_MONTH)); + } + @Test public void shouldReturn10thNovember2010WhenConvertToLocalDate() { // given diff --git a/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverterTest.java b/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverterTest.java index 49988c8b33..97c70ee5ac 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverterTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/datetime/DateToLocalDateTimeConverterTest.java @@ -29,6 +29,60 @@ public class DateToLocalDateTimeConverterTest { calendar.set(2010, 10, 10, 8, 20); Date dateToConvert = calendar.getTime(); + // when + LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaInstant(dateToConvert); + + // then + assertEquals(2010, localDateTime.get(ChronoField.YEAR)); + assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); + assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); + assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); + } + + @Test + public void shouldReturn10thNovember2010time8hour20minWhenConvertViaMiliseconds() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10, 8, 20); + Date dateToConvert = calendar.getTime(); + + // when + LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaMilisecond(dateToConvert); + + // then + assertEquals(2010, localDateTime.get(ChronoField.YEAR)); + assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); + assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); + assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); + } + + @Test + public void shouldReturn10thNovember2010time8hour20minWhenConvertViaSqlTimestamp() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10, 8, 20); + Date dateToConvert = calendar.getTime(); + + // when + LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTimeViaSqlTimestamp(dateToConvert); + + // then + assertEquals(2010, localDateTime.get(ChronoField.YEAR)); + assertEquals(11, localDateTime.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(10, localDateTime.get(ChronoField.DAY_OF_MONTH)); + assertEquals(8, localDateTime.get(ChronoField.HOUR_OF_DAY)); + assertEquals(20, localDateTime.get(ChronoField.MINUTE_OF_HOUR)); + } + + @Test + public void shouldReturn10thNovember2010time8hour20minWhenConvertToLocalDateTime() { + // given + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 10, 10, 8, 20); + Date dateToConvert = calendar.getTime(); + // when LocalDateTime localDateTime = DateToLocalDateTimeConverter.convertToLocalDateTime(dateToConvert); diff --git a/core-java-8/src/test/java/com/baeldung/datetime/LocalDateTimeToDateConverterTest.java b/core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverterTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/datetime/LocalDateTimeToDateConverterTest.java rename to core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverterTest.java index 519fa69f04..2c6898381f 100644 --- a/core-java-8/src/test/java/com/baeldung/datetime/LocalDateTimeToDateConverterTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateTimeToDateConverterTest.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.datetime; +package com.baeldung.java9.datetime; import static org.junit.Assert.assertEquals; diff --git a/core-java-8/src/test/java/com/baeldung/datetime/LocalDateToDateConverterTest.java b/core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateToDateConverterTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/datetime/LocalDateToDateConverterTest.java rename to core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateToDateConverterTest.java index c1da3af052..7f20d5d2d2 100644 --- a/core-java-8/src/test/java/com/baeldung/datetime/LocalDateToDateConverterTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/datetime/LocalDateToDateConverterTest.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.datetime; +package com.baeldung.java9.datetime; import static org.junit.Assert.assertEquals; From c8d11d0b81057621702f0028c1a1c05149f243f1 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 25 Nov 2017 11:41:31 +0200 Subject: [PATCH 03/17] fix log display issue (#3117) --- spring-aop/src/main/resources/logback.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-aop/src/main/resources/logback.xml b/spring-aop/src/main/resources/logback.xml index ec0dc2469a..3245e94f08 100644 --- a/spring-aop/src/main/resources/logback.xml +++ b/spring-aop/src/main/resources/logback.xml @@ -13,7 +13,11 @@ - + + + + + \ No newline at end of file From 6435d5723a977c554b2759e669e8a62e711d3feb Mon Sep 17 00:00:00 2001 From: Ahmed Tawila Date: Sat, 25 Nov 2017 12:18:49 +0200 Subject: [PATCH 04/17] BAEL-1309 Append Data to a File with Java (#3054) * Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting * close cache instances properly * remove latest commit * BAEL-1057 Introduction to rxjava-jdbc * refactor rxjava-jdbc * Refactor rxjava-jdbc * Refactoring rxjava-jdbc * BAEL-1171 java.lang.String API * refactor rxjava-jdbc * refactor String * String API - move multiple classes into a single class * move class into test package * BAEL-1171 String.lang.String API * BAEL-1171 java.lang.String API * BAEL-1250 Initializing Arrays in Java * BAEL-1250 Initializing Arrays in Java * BAEL-1250 Initializing Arrays in Java * small fix * BAEL-1171 java.lang.String API * BAEL-1263 Daemon Threads in Java * merge with fork * BAEL-1263 Daemon Threads in Java * fix compilation error * BAEL-1309 Append Data to a File with Java * fix build fails * fix test error * fix build failures * cleanup * fix Sneaky Runnable test * revert sneaky runnable fix attempt * fix test failure * fix test failure * fix all test failures * fix test failure * fix test failures * Nested Classes in Java --- .../baeldung/concurrent/daemon/NewThread.java | 1 - .../com/baeldung/nestedclass/Enclosing.java | 11 +++++ .../baeldung/nestedclass/NewEnclosing.java | 15 ++++++ .../java/com/baeldung/nestedclass/Outer.java | 11 +++++ .../nestedclass/SimpleAbstractClass.java | 5 ++ .../java/com/baeldung/util/StreamUtils.java | 16 +++++++ .../src/main/resources/countries.properties | 3 ++ .../baeldung/file/FileOutputStreamTest.java | 36 ++++++++++++++ .../java/com/baeldung/file/FileUtilsTest.java | 37 ++++++++++++++ .../com/baeldung/file/FileWriterTest.java | 40 ++++++++++++++++ .../java/com/baeldung/file/FilesTest.java | 36 ++++++++++++++ .../java/com/baeldung/file/GuavaTest.java | 48 +++++++++++++++++++ .../nestedclass/AnonymousInnerTest.java | 16 +++++++ .../baeldung/nestedclass/InnerClassTest.java | 13 +++++ .../baeldung/nestedclass/LocalClassTest.java | 12 +++++ .../baeldung/nestedclass/NestedClassTest.java | 12 +++++ .../baeldung/nestedclass/NewOuterTest.java | 32 +++++++++++++ .../java/com/baeldung/string/StringTest.java | 2 +- 18 files changed, 344 insertions(+), 2 deletions(-) create mode 100644 core-java/src/main/java/com/baeldung/nestedclass/Enclosing.java create mode 100644 core-java/src/main/java/com/baeldung/nestedclass/NewEnclosing.java create mode 100644 core-java/src/main/java/com/baeldung/nestedclass/Outer.java create mode 100644 core-java/src/main/java/com/baeldung/nestedclass/SimpleAbstractClass.java create mode 100644 core-java/src/main/java/com/baeldung/util/StreamUtils.java create mode 100644 core-java/src/main/resources/countries.properties create mode 100644 core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java create mode 100644 core-java/src/test/java/com/baeldung/file/FileUtilsTest.java create mode 100644 core-java/src/test/java/com/baeldung/file/FileWriterTest.java create mode 100644 core-java/src/test/java/com/baeldung/file/FilesTest.java create mode 100644 core-java/src/test/java/com/baeldung/file/GuavaTest.java create mode 100644 core-java/src/test/java/com/baeldung/nestedclass/AnonymousInnerTest.java create mode 100644 core-java/src/test/java/com/baeldung/nestedclass/InnerClassTest.java create mode 100644 core-java/src/test/java/com/baeldung/nestedclass/LocalClassTest.java create mode 100644 core-java/src/test/java/com/baeldung/nestedclass/NestedClassTest.java create mode 100644 core-java/src/test/java/com/baeldung/nestedclass/NewOuterTest.java diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java index d742d3a55f..4d87978070 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java @@ -3,7 +3,6 @@ package com.baeldung.concurrent.daemon; public class NewThread extends Thread { public void run() { - long startTime = System.currentTimeMillis(); while (true) { for (int i = 0; i < 10; i++) { diff --git a/core-java/src/main/java/com/baeldung/nestedclass/Enclosing.java b/core-java/src/main/java/com/baeldung/nestedclass/Enclosing.java new file mode 100644 index 0000000000..a9911538b0 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/nestedclass/Enclosing.java @@ -0,0 +1,11 @@ +package com.baeldung.nestedclass; + +public class Enclosing { + + public static class Nested { + + public void test() { + System.out.println("Calling test..."); + } + } +} diff --git a/core-java/src/main/java/com/baeldung/nestedclass/NewEnclosing.java b/core-java/src/main/java/com/baeldung/nestedclass/NewEnclosing.java new file mode 100644 index 0000000000..c7e04e8600 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/nestedclass/NewEnclosing.java @@ -0,0 +1,15 @@ +package com.baeldung.nestedclass; + +public class NewEnclosing { + + void run() { + class Local { + + void run() { + System.out.println("Welcome to Baeldung!"); + } + } + Local local = new Local(); + local.run(); + } +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/nestedclass/Outer.java b/core-java/src/main/java/com/baeldung/nestedclass/Outer.java new file mode 100644 index 0000000000..ebd6d27293 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/nestedclass/Outer.java @@ -0,0 +1,11 @@ +package com.baeldung.nestedclass; + +public class Outer { + + public class Inner { + + public void test() { + System.out.println("Calling test..."); + } + } +} diff --git a/core-java/src/main/java/com/baeldung/nestedclass/SimpleAbstractClass.java b/core-java/src/main/java/com/baeldung/nestedclass/SimpleAbstractClass.java new file mode 100644 index 0000000000..586e2d12b4 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/nestedclass/SimpleAbstractClass.java @@ -0,0 +1,5 @@ +package com.baeldung.nestedclass; + +abstract class SimpleAbstractClass { + abstract void run(); +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/util/StreamUtils.java b/core-java/src/main/java/com/baeldung/util/StreamUtils.java new file mode 100644 index 0000000000..42f438732f --- /dev/null +++ b/core-java/src/main/java/com/baeldung/util/StreamUtils.java @@ -0,0 +1,16 @@ +package com.baeldung.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; + +import org.apache.commons.io.IOUtils; + +public class StreamUtils { + + public static String getStringFromInputStream(InputStream input) throws IOException { + StringWriter writer = new StringWriter(); + IOUtils.copy(input, writer, "UTF-8"); + return writer.toString(); + } +} diff --git a/core-java/src/main/resources/countries.properties b/core-java/src/main/resources/countries.properties new file mode 100644 index 0000000000..3c1f53aded --- /dev/null +++ b/core-java/src/main/resources/countries.properties @@ -0,0 +1,3 @@ +UK +US +Germany diff --git a/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java b/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java new file mode 100644 index 0000000000..451c1b4c4d --- /dev/null +++ b/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java @@ -0,0 +1,36 @@ +package com.baeldung.file; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.junit.After; +import org.junit.Test; + +import com.baeldung.util.StreamUtils; + +public class FileOutputStreamTest { + + public static final String fileName = "src/main/resources/countries.properties"; + + @Test + public void whenAppendToFileUsingFileOutputStream_thenCorrect() throws Exception { + FileOutputStream fos = new FileOutputStream(fileName, true); + fos.write("Spain\r\n".getBytes()); + fos.close(); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @After + public void revertFile() throws IOException { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } +} diff --git a/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java b/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java new file mode 100644 index 0000000000..9ee8726575 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java @@ -0,0 +1,37 @@ +package com.baeldung.file; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Test; + +import com.baeldung.util.StreamUtils; + +public class FileUtilsTest { + + public static final String fileName = "src/main/resources/countries.properties"; + + @Test + public void whenAppendToFileUsingFiles_thenCorrect() throws IOException { + File file = new File(fileName); + FileUtils.writeStringToFile(file, "Spain\r\n", StandardCharsets.UTF_8, true); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @After + public void revertFile() throws IOException { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } +} diff --git a/core-java/src/test/java/com/baeldung/file/FileWriterTest.java b/core-java/src/test/java/com/baeldung/file/FileWriterTest.java new file mode 100644 index 0000000000..8d2ce4310e --- /dev/null +++ b/core-java/src/test/java/com/baeldung/file/FileWriterTest.java @@ -0,0 +1,40 @@ +package com.baeldung.file; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +import org.junit.After; +import org.junit.Test; + +import com.baeldung.util.StreamUtils; + +public class FileWriterTest { + + public static final String fileName = "src/main/resources/countries.properties"; + + @Test + public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException { + FileWriter fw = new FileWriter(fileName, true); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("Spain"); + bw.newLine(); + bw.close(); + + assertThat( + StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n"); + } + + @After + public void revertFile() throws IOException { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } +} diff --git a/core-java/src/test/java/com/baeldung/file/FilesTest.java b/core-java/src/test/java/com/baeldung/file/FilesTest.java new file mode 100644 index 0000000000..bd39d004d3 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/file/FilesTest.java @@ -0,0 +1,36 @@ +package com.baeldung.file; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +import org.junit.After; +import org.junit.Test; + +import com.baeldung.util.StreamUtils; + +public class FilesTest { + + public static final String fileName = "src/main/resources/countries.properties"; + + @Test + public void whenAppendToFileUsingFiles_thenCorrect() throws IOException { + Files.write(Paths.get(fileName), "Spain\r\n".getBytes(), StandardOpenOption.APPEND); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @After + public void revertFile() throws IOException { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } +} diff --git a/core-java/src/test/java/com/baeldung/file/GuavaTest.java b/core-java/src/test/java/com/baeldung/file/GuavaTest.java new file mode 100644 index 0000000000..5a7ec6c4a8 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/file/GuavaTest.java @@ -0,0 +1,48 @@ +package com.baeldung.file; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.util.StreamUtils; +import com.google.common.base.Charsets; +import com.google.common.io.CharSink; +import com.google.common.io.FileWriteMode; +import com.google.common.io.Files; + +public class GuavaTest { + + public static final String fileName = "src/main/resources/countries.properties"; + + @Before + public void setup() throws Exception { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } + + @Test + public void whenAppendToFileUsingGuava_thenCorrect() throws IOException { + File file = new File(fileName); + CharSink chs = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND); + chs.write("Spain\r\n"); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @After + public void revertFile() throws IOException { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } +} diff --git a/core-java/src/test/java/com/baeldung/nestedclass/AnonymousInnerTest.java b/core-java/src/test/java/com/baeldung/nestedclass/AnonymousInnerTest.java new file mode 100644 index 0000000000..394c0bb57a --- /dev/null +++ b/core-java/src/test/java/com/baeldung/nestedclass/AnonymousInnerTest.java @@ -0,0 +1,16 @@ +package com.baeldung.nestedclass; + +import org.junit.Test; + +public class AnonymousInnerTest { + + @Test + public void whenRunAnonymousClass_thenCorrect() { + SimpleAbstractClass simpleAbstractClass = new SimpleAbstractClass() { + void run() { + System.out.println("Running Anonymous Class..."); + } + }; + simpleAbstractClass.run(); + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/nestedclass/InnerClassTest.java b/core-java/src/test/java/com/baeldung/nestedclass/InnerClassTest.java new file mode 100644 index 0000000000..e9cb119ac2 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/nestedclass/InnerClassTest.java @@ -0,0 +1,13 @@ +package com.baeldung.nestedclass; + +import org.junit.Test; + +public class InnerClassTest { + + @Test + public void givenInnerClassWhenInstantiating_thenCorrect() { + Outer outer = new Outer(); + Outer.Inner inner = outer.new Inner(); + inner.test(); + } +} diff --git a/core-java/src/test/java/com/baeldung/nestedclass/LocalClassTest.java b/core-java/src/test/java/com/baeldung/nestedclass/LocalClassTest.java new file mode 100644 index 0000000000..dad19161ad --- /dev/null +++ b/core-java/src/test/java/com/baeldung/nestedclass/LocalClassTest.java @@ -0,0 +1,12 @@ +package com.baeldung.nestedclass; + +import org.junit.Test; + +public class LocalClassTest { + + @Test + public void whenTestingLocalClass_thenCorrect() { + NewEnclosing newEnclosing = new NewEnclosing(); + newEnclosing.run(); + } +} diff --git a/core-java/src/test/java/com/baeldung/nestedclass/NestedClassTest.java b/core-java/src/test/java/com/baeldung/nestedclass/NestedClassTest.java new file mode 100644 index 0000000000..16c883689a --- /dev/null +++ b/core-java/src/test/java/com/baeldung/nestedclass/NestedClassTest.java @@ -0,0 +1,12 @@ +package com.baeldung.nestedclass; + +import org.junit.Test; + +public class NestedClassTest { + + @Test + public void whenInstantiatingStaticNestedClass_thenCorrect() { + Enclosing.Nested nested = new Enclosing.Nested(); + nested.test(); + } +} diff --git a/core-java/src/test/java/com/baeldung/nestedclass/NewOuterTest.java b/core-java/src/test/java/com/baeldung/nestedclass/NewOuterTest.java new file mode 100644 index 0000000000..e883687d33 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/nestedclass/NewOuterTest.java @@ -0,0 +1,32 @@ +package com.baeldung.nestedclass; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class NewOuterTest { + + int a = 1; + static int b = 2; + + public class InnerClass { + int a = 3; + static final int b = 4; + + @Test + public void whenShadowing_thenCorrect() { + assertEquals(3, a); + assertEquals(4, b); + assertEquals(1, NewOuterTest.this.a); + assertEquals(2, NewOuterTest.b); + assertEquals(2, NewOuterTest.this.b); + } + } + + @Test + public void shadowingTest() { + NewOuterTest outer = new NewOuterTest(); + NewOuterTest.InnerClass inner = outer.new InnerClass(); + inner.whenShadowing_thenCorrect(); + + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/string/StringTest.java b/core-java/src/test/java/com/baeldung/string/StringTest.java index fe1a69aa23..e88b2d7c2c 100644 --- a/core-java/src/test/java/com/baeldung/string/StringTest.java +++ b/core-java/src/test/java/com/baeldung/string/StringTest.java @@ -223,4 +223,4 @@ public class StringTest { assertEquals("200", String.valueOf(l)); } -} +} \ No newline at end of file From 04dc60bd1216a4673b4aeaf23e1990c43cd5f35e Mon Sep 17 00:00:00 2001 From: Muhammed Almas Date: Sat, 25 Nov 2017 16:06:23 +0530 Subject: [PATCH 05/17] BAEL-1370 Added test to show usage of ArrayDeque. (#3128) --- .../baeldung/arraydeque/ArrayDequeTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/arraydeque/ArrayDequeTest.java diff --git a/core-java/src/test/java/com/baeldung/arraydeque/ArrayDequeTest.java b/core-java/src/test/java/com/baeldung/arraydeque/ArrayDequeTest.java new file mode 100644 index 0000000000..50813a8601 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/arraydeque/ArrayDequeTest.java @@ -0,0 +1,50 @@ +package com.baeldung.arraydeque; + +import java.util.ArrayDeque; +import java.util.Deque; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class ArrayDequeTest { + + @Test + public void whenOffer_addsAtLast() { + final Deque deque = new ArrayDeque<>(); + + deque.offer("first"); + deque.offer("second"); + + assertEquals("second", deque.getLast()); + } + + @Test + public void whenPoll_removesFirst() { + final Deque deque = new ArrayDeque<>(); + + deque.offer("first"); + deque.offer("second"); + + assertEquals("first", deque.poll()); + } + + @Test + public void whenPush_addsAtFirst() { + final Deque deque = new ArrayDeque<>(); + + deque.push("first"); + deque.push("second"); + + assertEquals("second", deque.getFirst()); + } + + @Test + public void whenPop_removesLast() { + final Deque deque = new ArrayDeque<>(); + + deque.push("first"); + deque.push("second"); + + assertEquals("second", deque.pop()); + } +} From aa46858c0fce198e59b7cf03bec89ddf1ac1fcac Mon Sep 17 00:00:00 2001 From: adamd1985 Date: Sun, 26 Nov 2017 00:03:05 +0100 Subject: [PATCH 06/17] BAEL-1289 - Merge (#3136) * Initial Commit * Added Domain Classes * Update HighEndComputer.java * Update StandardComputer.java * Update TemplateMethodPatternTest.java * Update parent pom.xml * Update pom.xml in template-method submodule * Update readme.md * Update README.md * Initial Commit * Update HighEndComputer.java * Delete article folder * Initial Commit * Initial Commit * Initial Commit * Added Article Folder * Delete Article Folder * Added Article Folder --- .../pom.xml | 4 ++-- .../templatemethod}/application/Application.java | 14 +++++++------- .../pattern/templatemethod}/model/Computer.java | 4 +--- .../templatemethod}/model/ComputerBuilder.java | 3 ++- .../templatemethod}/model/HighEndComputer.java | 5 +++-- .../model/HighEndComputerBuilder.java | 2 +- .../templatemethod}/model/StandardComputer.java | 5 +++-- .../model/StandardComputerBuilder.java | 2 +- .../test}/TemplateMethodPatternTest.java | 12 +++++------- patterns/pom.xml | 2 +- 10 files changed, 26 insertions(+), 27 deletions(-) rename patterns/{template-method => behavioral-patterns}/pom.xml (92%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/application/Application.java (59%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/Computer.java (77%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/ComputerBuilder.java (88%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/HighEndComputer.java (59%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/HighEndComputerBuilder.java (92%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/StandardComputer.java (60%) rename patterns/{template-method/src/main/java/com/baeldung/templatemethodpattern => behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod}/model/StandardComputerBuilder.java (92%) rename patterns/{template-method/src/test/java/com/baeldung/templatemethodpatterntest => behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test}/TemplateMethodPatternTest.java (89%) diff --git a/patterns/template-method/pom.xml b/patterns/behavioral-patterns/pom.xml similarity index 92% rename from patterns/template-method/pom.xml rename to patterns/behavioral-patterns/pom.xml index 4b863fe0a4..3c40520ce1 100644 --- a/patterns/template-method/pom.xml +++ b/patterns/behavioral-patterns/pom.xml @@ -1,8 +1,8 @@ 4.0.0 - com.baeldung.templatemethod - template-method + com.baeldung.pattern.templatemethod + pattern.templatemethod 1.0 jar diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/application/Application.java similarity index 59% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/application/Application.java index bd383b4568..9ab34c3cd8 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/application/Application.java @@ -1,11 +1,11 @@ -package com.baeldung.templatemethodpattern.application; +package com.baeldung.pattern.templatemethod.application; -import com.baeldung.templatemethodpattern.model.Computer; -import com.baeldung.templatemethodpattern.model.StandardComputer; -import com.baeldung.templatemethodpattern.model.HighEndComputer; -import com.baeldung.templatemethodpattern.model.ComputerBuilder; -import com.baeldung.templatemethodpattern.model.HighEndComputerBuilder; -import com.baeldung.templatemethodpattern.model.StandardComputerBuilder; +import com.baeldung.pattern.templatemethod.model.Computer; +import com.baeldung.pattern.templatemethod.model.StandardComputer; +import com.baeldung.pattern.templatemethod.model.HighEndComputer; +import com.baeldung.pattern.templatemethod.model.ComputerBuilder; +import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder; +import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder; public class Application { diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/Computer.java similarity index 77% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/Computer.java index 128eec59ad..1419398f62 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/Computer.java @@ -1,9 +1,7 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; import java.util.HashMap; import java.util.Map; -import java.util.ArrayList; -import java.util.List; public class Computer { diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/ComputerBuilder.java similarity index 88% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/ComputerBuilder.java index 39052f4776..515a6940f5 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/ComputerBuilder.java @@ -1,5 +1,6 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; +import com.baeldung.pattern.templatemethod.model.Computer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputer.java similarity index 59% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputer.java index 16d89f1ad6..0684b1b233 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputer.java @@ -1,10 +1,11 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; +import com.baeldung.pattern.templatemethod.model.Computer; import java.util.Map; public class HighEndComputer extends Computer { public HighEndComputer(Map computerParts) { super(computerParts); - } + } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputerBuilder.java similarity index 92% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputerBuilder.java index baa800ca8f..c992aa2bff 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputerBuilder.java @@ -1,4 +1,4 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; public class HighEndComputerBuilder extends ComputerBuilder { diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputer.java similarity index 60% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputer.java index 14d32d7b64..4e1d857016 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputer.java @@ -1,10 +1,11 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; +import com.baeldung.pattern.templatemethod.model.Computer; import java.util.Map; public class StandardComputer extends Computer { public StandardComputer(Map computerParts) { super(computerParts); - } + } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputerBuilder.java similarity index 92% rename from patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputerBuilder.java index 78547dc38b..cc81dddc1b 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputerBuilder.java @@ -1,4 +1,4 @@ -package com.baeldung.templatemethodpattern.model; +package com.baeldung.pattern.templatemethod.model; public class StandardComputerBuilder extends ComputerBuilder { diff --git a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test/TemplateMethodPatternTest.java similarity index 89% rename from patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java rename to patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test/TemplateMethodPatternTest.java index 1d608ff2c2..679559af9f 100644 --- a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java +++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test/TemplateMethodPatternTest.java @@ -1,10 +1,8 @@ -package com.baeldung.templatemethodpatterntest; +package com.baeldung.pattern.templatemethod.test; -import com.baeldung.templatemethodpattern.model.Computer; -import com.baeldung.templatemethodpattern.model.HighEndComputerBuilder; -import com.baeldung.templatemethodpattern.model.StandardComputerBuilder; -import com.baeldung.templatemethodpattern.model.HighEndComputer; -import com.baeldung.templatemethodpattern.model.StandardComputer; +import com.baeldung.pattern.templatemethod.model.Computer; +import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder; +import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder; import org.junit.Assert; import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; @@ -82,7 +80,7 @@ public class TemplateMethodPatternTest { assertEquals(2, highEndComputerBuilder.getComputerParts().size()); } - @Test + @Test public void givenAllHighEndParts_whenComputerisBuilt_thenComputerInstance() { assertThat(standardComputerBuilder.buildComputer(), instanceOf(Computer.class)); } diff --git a/patterns/pom.xml b/patterns/pom.xml index 68e5316f64..1462952e37 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -9,7 +9,7 @@ front-controller intercepting-filter - template-method + behavioral-patterns From c1ecbf57100c5909c6860a41304ea4f992ae7f60 Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Sun, 26 Nov 2017 09:40:54 +0200 Subject: [PATCH 07/17] move spring-jpa to persistence-modules (#3134) * move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict * cleanup * group and cleanup * add readme to grouping modules * move spring-jpa to persistence-modules --- {spring-jpa => persistence-modules/spring-jpa}/.gitignore | 0 {spring-jpa => persistence-modules/spring-jpa}/README.md | 0 {spring-jpa => persistence-modules/spring-jpa}/pom.xml | 1 + .../main/java/org/baeldung/config/PersistenceJNDIConfig.java | 0 .../src/main/java/org/baeldung/config/PersistenceJPAConfig.java | 0 .../java/org/baeldung/config/PersistenceJPAConfigL2Cache.java | 0 .../main/java/org/baeldung/config/PersistenceJPAConfigXml.java | 0 .../src/main/java/org/baeldung/config/ProductConfig.java | 0 .../src/main/java/org/baeldung/config/SpringWebConfig.java | 0 .../src/main/java/org/baeldung/config/StudentJPAH2Config.java | 0 .../src/main/java/org/baeldung/config/StudentJpaConfig.java | 0 .../src/main/java/org/baeldung/config/UserConfig.java | 0 .../src/main/java/org/baeldung/config/WebInitializer.java | 0 .../src/main/java/org/baeldung/dsrouting/ClientDao.java | 0 .../java/org/baeldung/dsrouting/ClientDataSourceRouter.java | 0 .../src/main/java/org/baeldung/dsrouting/ClientDatabase.java | 0 .../org/baeldung/dsrouting/ClientDatabaseContextHolder.java | 0 .../src/main/java/org/baeldung/dsrouting/ClientService.java | 0 .../baeldung/extended/persistence/dao/ExtendedRepository.java | 0 .../extended/persistence/dao/ExtendedRepositoryImpl.java | 0 .../extended/persistence/dao/ExtendedStudentRepository.java | 0 .../baeldung/inmemory/persistence/dao/StudentRepository.java | 0 .../java/org/baeldung/inmemory/persistence/model/Student.java | 0 .../main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java | 0 .../src/main/java/org/baeldung/persistence/dao/FooDao.java | 0 .../src/main/java/org/baeldung/persistence/dao/IFooDao.java | 0 .../src/main/java/org/baeldung/persistence/model/Bar.java | 0 .../src/main/java/org/baeldung/persistence/model/Foo.java | 0 .../persistence/multiple/dao/product/ProductRepository.java | 0 .../persistence/multiple/dao/user/PossessionRepository.java | 0 .../baeldung/persistence/multiple/dao/user/UserRepository.java | 0 .../baeldung/persistence/multiple/model/product/Product.java | 0 .../baeldung/persistence/multiple/model/user/Possession.java | 0 .../java/org/baeldung/persistence/multiple/model/user/User.java | 0 .../main/java/org/baeldung/persistence/service/FooService.java | 0 .../src/main/java/org/baeldung/sqlfiles/Country.java | 0 .../src/main/java/org/baeldung/web/MainController.java | 0 .../spring-jpa}/src/main/resources/context.xml | 0 .../spring-jpa}/src/main/resources/logback.xml | 0 .../spring-jpa}/src/main/resources/persistence-h2.properties | 0 .../spring-jpa}/src/main/resources/persistence-jndi.properties | 0 .../src/main/resources/persistence-multiple-db.properties | 0 .../spring-jpa}/src/main/resources/persistence-mysql.properties | 0 .../src/main/resources/persistence-student-h2.properties | 0 .../src/main/resources/persistence-student.properties | 0 .../spring-jpa}/src/main/resources/persistence.xml | 0 .../spring-jpa}/src/main/resources/server.xml | 0 .../spring-jpa}/src/main/resources/sqlfiles.properties | 0 .../spring-jpa}/src/main/webapp/WEB-INF/views/jsp/index.jsp | 0 .../spring-jpa}/src/test/java/META-INF/persistence.xml | 0 .../baeldung/dsrouting/DataSourceRoutingIntegrationTest.java | 0 .../baeldung/dsrouting/DataSourceRoutingTestConfiguration.java | 0 .../deletion/config/PersistenceJPAConfigDeletion.java | 0 .../test/java/org/baeldung/persistence/deletion/model/Bar.java | 0 .../test/java/org/baeldung/persistence/deletion/model/Baz.java | 0 .../test/java/org/baeldung/persistence/deletion/model/Foo.java | 0 .../repository/ExtendedStudentRepositoryIntegrationTest.java | 0 .../persistence/repository/InMemoryDBIntegrationTest.java | 0 .../baeldung/persistence/service/DeletionIntegrationTest.java | 0 .../service/FooPaginationPersistenceIntegrationTest.java | 0 .../service/FooServicePersistenceIntegrationTest.java | 0 .../persistence/service/FooServiceSortingIntegrationTest.java | 0 .../service/FooServiceSortingWitNullsManualIntegrationTest.java | 0 .../persistence/service/JpaMultipleDBIntegrationTest.java | 0 .../org/baeldung/persistence/service/PersistenceTestSuite.java | 0 .../persistence/service/SecondLevelCacheIntegrationTest.java | 0 .../spring-jpa}/src/test/resources/.gitignore | 0 .../spring-jpa}/src/test/resources/dsrouting-db.sql | 0 .../src/test/resources/persistence-student.properties | 0 pom.xml | 2 +- 70 files changed, 2 insertions(+), 1 deletion(-) rename {spring-jpa => persistence-modules/spring-jpa}/.gitignore (100%) rename {spring-jpa => persistence-modules/spring-jpa}/README.md (100%) rename {spring-jpa => persistence-modules/spring-jpa}/pom.xml (99%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/PersistenceJNDIConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/PersistenceJPAConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/ProductConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/SpringWebConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/StudentJPAH2Config.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/StudentJpaConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/UserConfig.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/config/WebInitializer.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/dsrouting/ClientDao.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/dsrouting/ClientDataSourceRouter.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/dsrouting/ClientDatabase.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/dsrouting/ClientDatabaseContextHolder.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/dsrouting/ClientService.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepositoryImpl.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/extended/persistence/dao/ExtendedStudentRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/inmemory/persistence/dao/StudentRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/inmemory/persistence/model/Student.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/dao/FooDao.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/dao/IFooDao.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/model/Bar.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/model/Foo.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/multiple/model/user/User.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/persistence/service/FooService.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/sqlfiles/Country.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/java/org/baeldung/web/MainController.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/context.xml (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/logback.xml (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-h2.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-jndi.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-multiple-db.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-mysql.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-student-h2.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence-student.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/persistence.xml (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/server.xml (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/resources/sqlfiles.properties (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/main/webapp/WEB-INF/views/jsp/index.jsp (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/META-INF/persistence.xml (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/dsrouting/DataSourceRoutingTestConfiguration.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/deletion/model/Bar.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/deletion/model/Baz.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/deletion/model/Foo.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/repository/ExtendedStudentRepositoryIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/repository/InMemoryDBIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/DeletionIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/java/org/baeldung/persistence/service/SecondLevelCacheIntegrationTest.java (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/resources/.gitignore (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/resources/dsrouting-db.sql (100%) rename {spring-jpa => persistence-modules/spring-jpa}/src/test/resources/persistence-student.properties (100%) diff --git a/spring-jpa/.gitignore b/persistence-modules/spring-jpa/.gitignore similarity index 100% rename from spring-jpa/.gitignore rename to persistence-modules/spring-jpa/.gitignore diff --git a/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md similarity index 100% rename from spring-jpa/README.md rename to persistence-modules/spring-jpa/README.md diff --git a/spring-jpa/pom.xml b/persistence-modules/spring-jpa/pom.xml similarity index 99% rename from spring-jpa/pom.xml rename to persistence-modules/spring-jpa/pom.xml index 960dcbc588..04c64fafc3 100644 --- a/spring-jpa/pom.xml +++ b/persistence-modules/spring-jpa/pom.xml @@ -13,6 +13,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../ diff --git a/spring-jpa/src/main/java/org/baeldung/config/PersistenceJNDIConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJNDIConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/PersistenceJNDIConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJNDIConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigXml.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/SpringWebConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/SpringWebConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/SpringWebConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/SpringWebConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/StudentJPAH2Config.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/StudentJPAH2Config.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/StudentJPAH2Config.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/StudentJPAH2Config.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/StudentJpaConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/StudentJpaConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/StudentJpaConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/StudentJpaConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/UserConfig.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java diff --git a/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java diff --git a/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDao.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDao.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDao.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDao.java diff --git a/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDataSourceRouter.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDataSourceRouter.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDataSourceRouter.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDataSourceRouter.java diff --git a/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabase.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabase.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabase.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabase.java diff --git a/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabaseContextHolder.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabaseContextHolder.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabaseContextHolder.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientDatabaseContextHolder.java diff --git a/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientService.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientService.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/dsrouting/ClientService.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/dsrouting/ClientService.java diff --git a/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepositoryImpl.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepositoryImpl.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepositoryImpl.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedRepositoryImpl.java diff --git a/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedStudentRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedStudentRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedStudentRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/extended/persistence/dao/ExtendedStudentRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/dao/StudentRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/dao/StudentRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/inmemory/persistence/dao/StudentRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/dao/StudentRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/model/Student.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/model/Student.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/inmemory/persistence/model/Student.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/inmemory/persistence/model/Student.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/dao/FooDao.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/FooDao.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/dao/FooDao.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/FooDao.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/dao/IFooDao.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/IFooDao.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/dao/IFooDao.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/IFooDao.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/model/Bar.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Bar.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/model/Bar.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Bar.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/model/Foo.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Foo.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/model/Foo.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Foo.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/service/FooService.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/service/FooService.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/persistence/service/FooService.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/service/FooService.java diff --git a/spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/sqlfiles/Country.java diff --git a/spring-jpa/src/main/java/org/baeldung/web/MainController.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/web/MainController.java similarity index 100% rename from spring-jpa/src/main/java/org/baeldung/web/MainController.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/web/MainController.java diff --git a/spring-jpa/src/main/resources/context.xml b/persistence-modules/spring-jpa/src/main/resources/context.xml similarity index 100% rename from spring-jpa/src/main/resources/context.xml rename to persistence-modules/spring-jpa/src/main/resources/context.xml diff --git a/spring-jpa/src/main/resources/logback.xml b/persistence-modules/spring-jpa/src/main/resources/logback.xml similarity index 100% rename from spring-jpa/src/main/resources/logback.xml rename to persistence-modules/spring-jpa/src/main/resources/logback.xml diff --git a/spring-jpa/src/main/resources/persistence-h2.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-h2.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-h2.properties diff --git a/spring-jpa/src/main/resources/persistence-jndi.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-jndi.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-jndi.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-jndi.properties diff --git a/spring-jpa/src/main/resources/persistence-multiple-db.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-multiple-db.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-multiple-db.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-multiple-db.properties diff --git a/spring-jpa/src/main/resources/persistence-mysql.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-mysql.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-mysql.properties diff --git a/spring-jpa/src/main/resources/persistence-student-h2.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-student-h2.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-student-h2.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-student-h2.properties diff --git a/spring-jpa/src/main/resources/persistence-student.properties b/persistence-modules/spring-jpa/src/main/resources/persistence-student.properties similarity index 100% rename from spring-jpa/src/main/resources/persistence-student.properties rename to persistence-modules/spring-jpa/src/main/resources/persistence-student.properties diff --git a/spring-jpa/src/main/resources/persistence.xml b/persistence-modules/spring-jpa/src/main/resources/persistence.xml similarity index 100% rename from spring-jpa/src/main/resources/persistence.xml rename to persistence-modules/spring-jpa/src/main/resources/persistence.xml diff --git a/spring-jpa/src/main/resources/server.xml b/persistence-modules/spring-jpa/src/main/resources/server.xml similarity index 100% rename from spring-jpa/src/main/resources/server.xml rename to persistence-modules/spring-jpa/src/main/resources/server.xml diff --git a/spring-jpa/src/main/resources/sqlfiles.properties b/persistence-modules/spring-jpa/src/main/resources/sqlfiles.properties similarity index 100% rename from spring-jpa/src/main/resources/sqlfiles.properties rename to persistence-modules/spring-jpa/src/main/resources/sqlfiles.properties diff --git a/spring-jpa/src/main/webapp/WEB-INF/views/jsp/index.jsp b/persistence-modules/spring-jpa/src/main/webapp/WEB-INF/views/jsp/index.jsp similarity index 100% rename from spring-jpa/src/main/webapp/WEB-INF/views/jsp/index.jsp rename to persistence-modules/spring-jpa/src/main/webapp/WEB-INF/views/jsp/index.jsp diff --git a/spring-jpa/src/test/java/META-INF/persistence.xml b/persistence-modules/spring-jpa/src/test/java/META-INF/persistence.xml similarity index 100% rename from spring-jpa/src/test/java/META-INF/persistence.xml rename to persistence-modules/spring-jpa/src/test/java/META-INF/persistence.xml diff --git a/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingTestConfiguration.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingTestConfiguration.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingTestConfiguration.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/dsrouting/DataSourceRoutingTestConfiguration.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/config/PersistenceJPAConfigDeletion.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Bar.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Bar.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Bar.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Bar.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Baz.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Baz.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Baz.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Baz.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Foo.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Foo.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Foo.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/deletion/model/Foo.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/repository/ExtendedStudentRepositoryIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/ExtendedStudentRepositoryIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/repository/ExtendedStudentRepositoryIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/ExtendedStudentRepositoryIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/repository/InMemoryDBIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/InMemoryDBIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/repository/InMemoryDBIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/InMemoryDBIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/DeletionIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/DeletionIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/DeletionIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/DeletionIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/SecondLevelCacheIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/SecondLevelCacheIntegrationTest.java similarity index 100% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/SecondLevelCacheIntegrationTest.java rename to persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/service/SecondLevelCacheIntegrationTest.java diff --git a/spring-jpa/src/test/resources/.gitignore b/persistence-modules/spring-jpa/src/test/resources/.gitignore similarity index 100% rename from spring-jpa/src/test/resources/.gitignore rename to persistence-modules/spring-jpa/src/test/resources/.gitignore diff --git a/spring-jpa/src/test/resources/dsrouting-db.sql b/persistence-modules/spring-jpa/src/test/resources/dsrouting-db.sql similarity index 100% rename from spring-jpa/src/test/resources/dsrouting-db.sql rename to persistence-modules/spring-jpa/src/test/resources/dsrouting-db.sql diff --git a/spring-jpa/src/test/resources/persistence-student.properties b/persistence-modules/spring-jpa/src/test/resources/persistence-student.properties similarity index 100% rename from spring-jpa/src/test/resources/persistence-student.properties rename to persistence-modules/spring-jpa/src/test/resources/persistence-student.properties diff --git a/pom.xml b/pom.xml index 20f7c4ffad..9b1f50f05e 100644 --- a/pom.xml +++ b/pom.xml @@ -177,7 +177,7 @@ spring-jmeter-jenkins spring-jms spring-jooq - spring-jpa + persistence-modules/spring-jpa spring-kafka spring-katharsis spring-ldap From d418a40b7cdd15aea337d2a5bb590a5bff1f2d19 Mon Sep 17 00:00:00 2001 From: daoire Date: Sun, 26 Nov 2017 17:29:14 +0000 Subject: [PATCH 08/17] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 4573d5f7e2..1feee4126e 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -119,4 +119,5 @@ - [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array) - [Guide to Java String Pool](http://www.baeldung.com/java-string-pool) - [Copy a File with Java](http://www.baeldung.com/java-copy-file) +- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns) From 29bfac0e957bdbb6a6d0a4549107376b1a33659e Mon Sep 17 00:00:00 2001 From: Shouvik Bhattacharya <33756821+shouvikbhattacharya@users.noreply.github.com> Date: Mon, 27 Nov 2017 03:36:18 +0530 Subject: [PATCH 09/17] BAEL-1305: A Simple Guide to Java Loops. (#3133) --- .../java/com/baeldung/loops/LoopsInJava.java | 43 +++++++++++++++++++ .../com/baeldung/loops/WhenUsingLoops.java | 37 ++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/loops/LoopsInJava.java create mode 100644 core-java/src/test/java/com/baeldung/loops/WhenUsingLoops.java diff --git a/core-java/src/main/java/com/baeldung/loops/LoopsInJava.java b/core-java/src/main/java/com/baeldung/loops/LoopsInJava.java new file mode 100644 index 0000000000..1b2e621b52 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/loops/LoopsInJava.java @@ -0,0 +1,43 @@ +package com.baeldung.loops; + +public class LoopsInJava { + + public int[] simple_for_loop() { + int[] arr = new int[5]; + for (int i = 0; i < 5; i++) { + arr[i] = i; + System.out.println("Simple for loop: i - " + i); + } + return arr; + } + + public int[] enhanced_for_each_loop() { + int[] intArr = { 0, 1, 2, 3, 4 }; + int[] arr = new int[5]; + for (int num : intArr) { + arr[num] = num; + System.out.println("Enhanced for-each loop: i - " + num); + } + return arr; + } + + public int[] while_loop() { + int i = 0; + int[] arr = new int[5]; + while (i < 5) { + arr[i] = i; + System.out.println("While loop: i - " + i++); + } + return arr; + } + + public int[] do_while_loop() { + int i = 0; + int[] arr = new int[5]; + do { + arr[i] = i; + System.out.println("Do-While loop: i - " + i++); + } while (i < 5); + return arr; + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/loops/WhenUsingLoops.java b/core-java/src/test/java/com/baeldung/loops/WhenUsingLoops.java new file mode 100644 index 0000000000..9590eabfef --- /dev/null +++ b/core-java/src/test/java/com/baeldung/loops/WhenUsingLoops.java @@ -0,0 +1,37 @@ +package com.baeldung.loops; + +import org.junit.Assert; +import org.junit.Test; + +public class WhenUsingLoops { + + private LoopsInJava loops = new LoopsInJava(); + + @Test + public void shouldRunForLoop() { + int[] expected = { 0, 1, 2, 3, 4 }; + int[] actual = loops.simple_for_loop(); + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void shouldRunEnhancedForeachLoop() { + int[] expected = { 0, 1, 2, 3, 4 }; + int[] actual = loops.enhanced_for_each_loop(); + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void shouldRunWhileLoop() { + int[] expected = { 0, 1, 2, 3, 4 }; + int[] actual = loops.while_loop(); + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void shouldRunDoWhileLoop() { + int[] expected = { 0, 1, 2, 3, 4 }; + int[] actual = loops.do_while_loop(); + Assert.assertArrayEquals(expected, actual); + } +} From b4d83ef9b2360e599fb3223a473d1a1b3aae51dc Mon Sep 17 00:00:00 2001 From: Daniele Demichelis Date: Sun, 26 Nov 2017 23:12:22 +0100 Subject: [PATCH 10/17] upgraded to OSGi 6.0.0 & maven-bundle-plugin 3.3.0 (#3141) --- osgi/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osgi/pom.xml b/osgi/pom.xml index 4298a0d3eb..e6ef9c3192 100644 --- a/osgi/pom.xml +++ b/osgi/pom.xml @@ -65,7 +65,7 @@ org.osgi org.osgi.core - 5.0.0 + 6.0.0 provided @@ -77,7 +77,7 @@ org.apache.felix maven-bundle-plugin - 1.4.0 + 3.3.0 true From 6536e39622dffac0693c2c79f7debd4a192a078c Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 27 Nov 2017 10:03:08 +0100 Subject: [PATCH 11/17] Update README.md (#3050) --- noexception/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noexception/README.md b/noexception/README.md index d840191369..9dd4c11190 100644 --- a/noexception/README.md +++ b/noexception/README.md @@ -1,2 +1,2 @@ ### Relevant Articles: -- [Introduction to NoException](http://www.baeldung.com/intrduction-to-noexception) +- [Introduction to NoException](http://www.baeldung.com/introduction-to-noexception) From ebc25b2b41a765b3503b1de50e17c5fc8090501a Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Mon, 27 Nov 2017 15:56:07 +0200 Subject: [PATCH 12/17] minor cleanup work --- bootique/dependency-reduced-pom.xml | 8 +++++++- ...yAnnotationJavaConfigMainIntegrationTest.java | 16 ++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml index ed18f4e42a..ab09cfb7b1 100644 --- a/bootique/dependency-reduced-pom.xml +++ b/bootique/dependency-reduced-pom.xml @@ -28,8 +28,14 @@ junit junit - 3.8.1 + 4.12 test + + + hamcrest-core + org.hamcrest + + diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java index 61d821e85e..614de6d3ad 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java +++ b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationJavaConfigMainIntegrationTest.java @@ -1,6 +1,5 @@ package com.baeldung.hibernate.manytomany; - import java.util.HashSet; import java.util.Set; import org.hibernate.Session; @@ -17,10 +16,8 @@ import com.baeldung.hibernate.manytomany.model.Employee; import com.baeldung.hibernate.manytomany.model.Project; import com.baeldung.manytomany.spring.PersistenceConfig; - - @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) public class HibernateManyToManyAnnotationJavaConfigMainIntegrationTest { @Autowired @@ -28,7 +25,6 @@ public class HibernateManyToManyAnnotationJavaConfigMainIntegrationTest { private Session session; - @Before public final void before() { session = sessionFactory.openSession(); @@ -43,11 +39,11 @@ public class HibernateManyToManyAnnotationJavaConfigMainIntegrationTest { @Test public final void whenEntitiesAreCreated_thenNoExceptions() { - Set projects = new HashSet(); - projects.add(new Project("IT Project")); - projects.add(new Project("Networking Project")); - session.persist(new Employee("Peter", "Oven", projects)); - session.persist(new Employee("Allan", "Norman", projects)); + Set projects = new HashSet(); + projects.add(new Project("IT Project")); + projects.add(new Project("Networking Project")); + session.persist(new Employee("Peter", "Oven", projects)); + session.persist(new Employee("Allan", "Norman", projects)); } } From bac574a7c22d2a20730ebbce70b51a7c90d46f47 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Mon, 27 Nov 2017 16:08:53 +0200 Subject: [PATCH 13/17] cleanup work after build --- undertow/dependency-reduced-pom.xml | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 undertow/dependency-reduced-pom.xml diff --git a/undertow/dependency-reduced-pom.xml b/undertow/dependency-reduced-pom.xml new file mode 100644 index 0000000000..0654c82b74 --- /dev/null +++ b/undertow/dependency-reduced-pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + com.baeldung.undertow + undertow + undertow + 1.0-SNAPSHOT + http://maven.apache.org + + ${project.artifactId} + + + maven-shade-plugin + + + package + + shade + + + + + + maven-jar-plugin + + + + com.baeldung.undertow.SimpleServer + + + + + + + + 1.8 + 1.8 + + + From 7f2ace0da913567513f9c4d6a2da15639054be86 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 27 Nov 2017 21:02:42 +0100 Subject: [PATCH 14/17] FilesTest fix (#3146) * FilesTest fix * StopThreadTest fix --- .../concurrent/stopping/StopThreadTest.java | 14 ++-- .../baeldung/file/FileOutputStreamTest.java | 36 ---------- .../java/com/baeldung/file/FileUtilsTest.java | 37 ---------- .../com/baeldung/file/FileWriterTest.java | 40 ----------- .../java/com/baeldung/file/FilesTest.java | 68 +++++++++++++++++-- .../java/com/baeldung/file/GuavaTest.java | 48 ------------- 6 files changed, 72 insertions(+), 171 deletions(-) delete mode 100644 core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java delete mode 100644 core-java/src/test/java/com/baeldung/file/FileUtilsTest.java delete mode 100644 core-java/src/test/java/com/baeldung/file/FileWriterTest.java delete mode 100644 core-java/src/test/java/com/baeldung/file/GuavaTest.java diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java index 8c1bdbf787..70854f013f 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java @@ -1,7 +1,11 @@ package com.baeldung.concurrent.stopping; +import com.jayway.awaitility.Awaitility; import org.junit.Test; +import java.util.concurrent.TimeUnit; + +import static com.jayway.awaitility.Awaitility.await; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -22,11 +26,10 @@ public class StopThreadTest { // Stop it and make sure the flags have been reversed controlSubThread.stop(); - Thread.sleep(interval); - assertTrue(controlSubThread.isStopped()); + await() + .until(() -> assertTrue(controlSubThread.isStopped())); } - @Test public void whenInterruptedThreadIsStopped() throws InterruptedException { @@ -44,7 +47,8 @@ public class StopThreadTest { controlSubThread.interrupt(); // Wait less than the time we would normally sleep, and make sure we exited. - Thread.sleep(interval/10); - assertTrue(controlSubThread.isStopped()); + Awaitility.await() + .atMost(interval/ 10, TimeUnit.MILLISECONDS) + .until(controlSubThread::isStopped); } } diff --git a/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java b/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java deleted file mode 100644 index 451c1b4c4d..0000000000 --- a/core-java/src/test/java/com/baeldung/file/FileOutputStreamTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.file; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.junit.After; -import org.junit.Test; - -import com.baeldung.util.StreamUtils; - -public class FileOutputStreamTest { - - public static final String fileName = "src/main/resources/countries.properties"; - - @Test - public void whenAppendToFileUsingFileOutputStream_thenCorrect() throws Exception { - FileOutputStream fos = new FileOutputStream(fileName, true); - fos.write("Spain\r\n".getBytes()); - fos.close(); - - assertThat(StreamUtils.getStringFromInputStream( - new FileInputStream(fileName))) - .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); - } - - @After - public void revertFile() throws IOException { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); - } -} diff --git a/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java b/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java deleted file mode 100644 index 9ee8726575..0000000000 --- a/core-java/src/test/java/com/baeldung/file/FileUtilsTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.file; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; - -import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Test; - -import com.baeldung.util.StreamUtils; - -public class FileUtilsTest { - - public static final String fileName = "src/main/resources/countries.properties"; - - @Test - public void whenAppendToFileUsingFiles_thenCorrect() throws IOException { - File file = new File(fileName); - FileUtils.writeStringToFile(file, "Spain\r\n", StandardCharsets.UTF_8, true); - - assertThat(StreamUtils.getStringFromInputStream( - new FileInputStream(fileName))) - .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); - } - - @After - public void revertFile() throws IOException { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); - } -} diff --git a/core-java/src/test/java/com/baeldung/file/FileWriterTest.java b/core-java/src/test/java/com/baeldung/file/FileWriterTest.java deleted file mode 100644 index 8d2ce4310e..0000000000 --- a/core-java/src/test/java/com/baeldung/file/FileWriterTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.file; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.BufferedWriter; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; - -import org.junit.After; -import org.junit.Test; - -import com.baeldung.util.StreamUtils; - -public class FileWriterTest { - - public static final String fileName = "src/main/resources/countries.properties"; - - @Test - public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException { - FileWriter fw = new FileWriter(fileName, true); - BufferedWriter bw = new BufferedWriter(fw); - bw.write("Spain"); - bw.newLine(); - bw.close(); - - assertThat( - StreamUtils.getStringFromInputStream( - new FileInputStream(fileName))) - .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n"); - } - - @After - public void revertFile() throws IOException { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); - } -} diff --git a/core-java/src/test/java/com/baeldung/file/FilesTest.java b/core-java/src/test/java/com/baeldung/file/FilesTest.java index bd39d004d3..e17e8580aa 100644 --- a/core-java/src/test/java/com/baeldung/file/FilesTest.java +++ b/core-java/src/test/java/com/baeldung/file/FilesTest.java @@ -2,14 +2,24 @@ package com.baeldung.file; import static org.assertj.core.api.Assertions.assertThat; +import java.io.BufferedWriter; +import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import com.google.common.base.Charsets; +import com.google.common.io.CharSink; +import com.google.common.io.FileWriteMode; +import org.apache.commons.io.FileUtils; import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.baeldung.util.StreamUtils; @@ -18,6 +28,26 @@ public class FilesTest { public static final String fileName = "src/main/resources/countries.properties"; + @Before + @After + public void setup() throws Exception { + PrintWriter writer = new PrintWriter(fileName); + writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); + writer.close(); + } + + @Test + public void whenAppendToFileUsingGuava_thenCorrect() throws IOException { + File file = new File(fileName); + CharSink chs = com.google.common.io.Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND); + chs.write("Spain\r\n"); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @Test public void whenAppendToFileUsingFiles_thenCorrect() throws IOException { Files.write(Paths.get(fileName), "Spain\r\n".getBytes(), StandardOpenOption.APPEND); @@ -27,10 +57,38 @@ public class FilesTest { .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); } - @After - public void revertFile() throws IOException { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); + @Test + public void whenAppendToFileUsingFileUtils_thenCorrect() throws IOException { + File file = new File(fileName); + FileUtils.writeStringToFile(file, "Spain\r\n", StandardCharsets.UTF_8, true); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @Test + public void whenAppendToFileUsingFileOutputStream_thenCorrect() throws Exception { + FileOutputStream fos = new FileOutputStream(fileName, true); + fos.write("Spain\r\n".getBytes()); + fos.close(); + + assertThat(StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); + } + + @Test + public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException { + FileWriter fw = new FileWriter(fileName, true); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("Spain"); + bw.newLine(); + bw.close(); + + assertThat( + StreamUtils.getStringFromInputStream( + new FileInputStream(fileName))) + .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n"); } } diff --git a/core-java/src/test/java/com/baeldung/file/GuavaTest.java b/core-java/src/test/java/com/baeldung/file/GuavaTest.java deleted file mode 100644 index 5a7ec6c4a8..0000000000 --- a/core-java/src/test/java/com/baeldung/file/GuavaTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.file; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.util.StreamUtils; -import com.google.common.base.Charsets; -import com.google.common.io.CharSink; -import com.google.common.io.FileWriteMode; -import com.google.common.io.Files; - -public class GuavaTest { - - public static final String fileName = "src/main/resources/countries.properties"; - - @Before - public void setup() throws Exception { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); - } - - @Test - public void whenAppendToFileUsingGuava_thenCorrect() throws IOException { - File file = new File(fileName); - CharSink chs = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND); - chs.write("Spain\r\n"); - - assertThat(StreamUtils.getStringFromInputStream( - new FileInputStream(fileName))) - .isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); - } - - @After - public void revertFile() throws IOException { - PrintWriter writer = new PrintWriter(fileName); - writer.print("UK\r\n" + "US\r\n" + "Germany\r\n"); - writer.close(); - } -} From 5f57a6cb4bfb7aecd3bba2245f6caf472015279d Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Tue, 28 Nov 2017 12:36:54 +0200 Subject: [PATCH 15/17] separating the sun specific functionality into a new module --- core-java-sun/.gitignore | 26 + core-java-sun/README.md | 123 +++++ core-java-sun/pom.xml | 489 ++++++++++++++++++ .../src/main/java/com/baeldung/.gitignore | 13 + .../src/main/java/com/baeldung/README.md | 2 + .../java/com/baeldung/javac/Positive.java | 0 .../com/baeldung/javac/SampleJavacPlugin.java | 0 .../src/main/resources/log4j.properties | 6 + core-java-sun/src/main/resources/logback.xml | 19 + .../SampleJavacPluginIntegrationTest.java | 0 .../com/baeldung/javac/SimpleClassFile.java | 0 .../com/baeldung/javac/SimpleFileManager.java | 0 .../com/baeldung/javac/SimpleSourceFile.java | 0 .../java/com/baeldung/javac/TestCompiler.java | 0 .../java/com/baeldung/javac/TestRunner.java | 0 core-java-sun/src/test/resources/.gitignore | 13 + core-java/pom.xml | 12 - 17 files changed, 691 insertions(+), 12 deletions(-) create mode 100644 core-java-sun/.gitignore create mode 100644 core-java-sun/README.md create mode 100644 core-java-sun/pom.xml create mode 100644 core-java-sun/src/main/java/com/baeldung/.gitignore create mode 100644 core-java-sun/src/main/java/com/baeldung/README.md rename {core-java => core-java-sun}/src/main/java/com/baeldung/javac/Positive.java (100%) rename {core-java => core-java-sun}/src/main/java/com/baeldung/javac/SampleJavacPlugin.java (100%) create mode 100644 core-java-sun/src/main/resources/log4j.properties create mode 100644 core-java-sun/src/main/resources/logback.xml rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java (100%) rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/SimpleClassFile.java (100%) rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/SimpleFileManager.java (100%) rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/SimpleSourceFile.java (100%) rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/TestCompiler.java (100%) rename {core-java => core-java-sun}/src/test/java/com/baeldung/javac/TestRunner.java (100%) create mode 100644 core-java-sun/src/test/resources/.gitignore diff --git a/core-java-sun/.gitignore b/core-java-sun/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/core-java-sun/.gitignore @@ -0,0 +1,26 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java-sun/README.md b/core-java-sun/README.md new file mode 100644 index 0000000000..1feee4126e --- /dev/null +++ b/core-java-sun/README.md @@ -0,0 +1,123 @@ +========= + +## Core Java Cookbooks and Examples + +### Relevant Articles: +- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list) +- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file) +- [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) +- [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) +- [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) +- [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) +- [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) +- [Java – Write to File](http://www.baeldung.com/java-write-to-file) +- [Java - Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream) +- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) +- [Java – Generate Random String](http://www.baeldung.com/java-random-string) +- [Java Scanner](http://www.baeldung.com/java-scanner) +- [Java Timer](http://www.baeldung.com/java-timer-and-timertask) +- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) +- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) +- [MD5 Hashing in Java](http://www.baeldung.com/java-md5) +- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist) +- [Guide to Java Reflection](http://www.baeldung.com/java-reflection) +- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) +- [Convert char to String in Java](http://www.baeldung.com/java-convert-char-to-string) +- [Random List Element](http://www.baeldung.com/java-random-list-element) +- [Convert String to int or Integer in Java](http://www.baeldung.com/java-convert-string-to-int-or-integer) +- [Java – Directory Size](http://www.baeldung.com/java-folder-size) +- [Java – Try with Resources](http://www.baeldung.com/java-try-with-resources) +- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) +- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java) +- [How to Convert String to different data types in Java](http://www.baeldung.com/java-string-conversions) +- [Introduction to Java Generics](http://www.baeldung.com/java-generics) +- [Generate equals() and hashCode() with Eclipse](http://www.baeldung.com/java-eclipse-equals-and-hashcode) +- [A Guide To Java Regular Expressions API](http://www.baeldung.com/regular-expressions-java) +- [Sorting in Java](http://www.baeldung.com/java-sorting) +- [Getting Started with Java Properties](http://www.baeldung.com/java-properties) +- [Grep in Java](http://www.baeldung.com/grep-in-java) +- [Java - Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections) +- [Simulated Annealing for Travelling Salesman Problem](http://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) +- [Slope One Algorithm: Collaborative Filtering Recommendation Systems](http://www.baeldung.com/java-collaborative-filtering-recommendations) +- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](http://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library) +- [Pattern Search with Grep in Java](http://www.baeldung.com/grep-in-java) +- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding) +- [Calculate the Size of a File in Java](http://www.baeldung.com/java-file-size) +- [The Basics of Java Generics](http://www.baeldung.com/java-generics) +- [The Traveling Salesman Problem in Java](http://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) +- [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) +- [How to Design a Genetic Algorithm in Java](http://www.baeldung.com/java-genetic-algorithm) +- [Guide to WeakHashMap in Java](http://www.baeldung.com/java-weakhashmap) +- [Spring Security – Cache Control Headers](http://www.baeldung.com/spring-security-cache-control-headers) +- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions) +- [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda) +- [Introduction to Nashorn](http://www.baeldung.com/java-nashorn) +- [Guide to the Guava BiMap](http://www.baeldung.com/guava-bimap) +- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream) +- [Chained Exceptions in Java](http://www.baeldung.com/java-chained-exceptions) +- [The Java HashMap Under the Hood](http://www.baeldung.com/java-hashmap) +- [A Guide to LinkedHashMap in Java](http://www.baeldung.com/java-linked-hashmap) +- [A Guide to TreeMap in Java](http://www.baeldung.com/java-treemap) +- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng) +- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions) +- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) +- [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list) +- [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list) +- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow) +- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum) +- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections) +- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer) +- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging) +- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe) +- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset) +- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) +- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection) +- [Guide to UUID in JAVA](http://www.baeldung.com/guide-to-uuid-in-java) +- [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path) +- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend) +- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration) +- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) +- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer) +- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number) +- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params) +- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) +- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream) +- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order) +- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) +- [Iterate over a Map in Java](http://www.baeldung.com/java-iterate-map) +- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies) +- [How to Copy an Array in Java](http://www.baeldung.com/java-array-copy) +- [Introduction to JDBC](http://www.baeldung.com/java-jdbc) +- [Period and Duration in Java](http://www.baeldung.com/java-period-duration) +- [Converting a Stack Trace to a String in Java](http://www.baeldung.com/java-stacktrace-to-string) +- [Count Occurrences of a Char in a String](http://www.baeldung.com/java-count-chars) +- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization) +- [The StackOverflowError in Java](http://www.baeldung.com/java-stack-overflow-error) +- [Split a String in Java](http://www.baeldung.com/java-split-string) +- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) +- [How to Remove the Last Character of a String?](http://www.baeldung.com/java-remove-last-character-of-string) +- [ClassNotFoundException vs NoClassDefFoundError](http://www.baeldung.com/java-classnotfoundexception-and-noclassdeffounderror) +- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) +- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char) +- [Guide to hashCode() in Java](http://www.baeldung.com/java-hashcode) +- [Collect a Java Stream to an Immutable Collection](http://www.baeldung.com/java-stream-immutable-collection) +- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri) +- [Broadcasting and Multicasting in Java](http://www.baeldung.com/java-broadcast-multicast) +- [Converting a List to String in Java](http://www.baeldung.com/java-list-to-string) +- [CharSequence vs. String in Java](http://www.baeldung.com/java-char-sequence-string) +- [Period and Duration in Java](http://www.baeldung.com/java-period-duration) +- [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator) +- [Singletons in Java](http://www.baeldung.com/java-singleton) +- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) +- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded) +- [How to Iterate Over a Stream With Indices](http://www.baeldung.com/java-stream-indices) +- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer) +- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) +- [Proxy, Decorator, Adapter and Bridge Patterns](http://www.baeldung.com/java-structural-design-patterns) +- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) +- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static) +- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array) +- [Guide to Java String Pool](http://www.baeldung.com/java-string-pool) +- [Copy a File with Java](http://www.baeldung.com/java-copy-file) +- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns) + diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml new file mode 100644 index 0000000000..3997f47d19 --- /dev/null +++ b/core-java-sun/pom.xml @@ -0,0 +1,489 @@ + + 4.0.0 + com.baeldung + core-java-sun + 0.1.0-SNAPSHOT + jar + + core-java-sun + + + + + + net.sourceforge.collections + collections-generic + ${collections-generic.version} + + + com.google.guava + guava + ${guava.version} + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + org.apache.commons + commons-math3 + ${commons-math3.version} + + + + org.decimal4j + decimal4j + ${decimal4j.version} + + + + org.bouncycastle + bcprov-jdk15on + ${bouncycastle.version} + + + + org.unix4j + unix4j-command + ${unix4j.version} + + + + com.googlecode.grep4j + grep4j + ${grep4j.version} + + + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + + log4j + log4j + 1.2.17 + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + + junit + junit + ${junit.version} + test + + + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + com.jayway.awaitility + awaitility + ${avaitility.version} + test + + + + commons-codec + commons-codec + ${commons-codec.version} + + + + org.javamoney + moneta + 1.1 + + + + org.owasp.esapi + esapi + 2.1.0.1 + + + + com.sun.messaging.mq + fscontext + ${fscontext.version} + + + com.codepoetics + protonpack + ${protonpack.version} + + + one.util + streamex + ${streamex.version} + + + io.vavr + vavr + ${vavr.version} + + + org.openjdk.jmh + jmh-core + 1.19 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.19 + + + org.springframework + spring-web + 4.3.4.RELEASE + + + com.sun + tools + 1.8.0 + system + ${java.home}/../lib/tools.jar + + + + + core-java + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*LiveTest.java + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + libs/ + org.baeldung.executable.ExecutableMavenJar + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + ${project.basedir} + + + org.baeldung.executable.ExecutableMavenJar + + + + jar-with-dependencies + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + + true + + + org.baeldung.executable.ExecutableMavenJar + + + + + + + + + com.jolira + onejar-maven-plugin + + + + org.baeldung.executable.ExecutableMavenJar + true + ${project.build.finalName}-onejar.${project.packaging} + + + one-jar + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + spring-boot + org.baeldung.executable.ExecutableMavenJar + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + java + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + -Xmx300m + -XX:+UseParallelGC + -classpath + + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + + + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + + 2.8.5 + + + 1.7.21 + 1.1.7 + + + 23.0 + 3.5 + 1.55 + 1.10 + 3.6.1 + 1.0.3 + 2.5 + 4.1 + 4.01 + 0.4 + 1.8.7 + 1.16.12 + 4.6-b01 + 1.13 + 0.6.5 + 0.9.0 + + + 1.3 + 4.12 + 2.8.9 + 3.6.1 + 1.7.0 + + + 3.6.0 + 2.19.1 + + \ No newline at end of file diff --git a/core-java-sun/src/main/java/com/baeldung/.gitignore b/core-java-sun/src/main/java/com/baeldung/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/core-java-sun/src/main/java/com/baeldung/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/core-java-sun/src/main/java/com/baeldung/README.md b/core-java-sun/src/main/java/com/baeldung/README.md new file mode 100644 index 0000000000..51809b2882 --- /dev/null +++ b/core-java-sun/src/main/java/com/baeldung/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [SHA-256 Hashing in Java](http://www.baeldung.com/sha-256-hashing-java) diff --git a/core-java/src/main/java/com/baeldung/javac/Positive.java b/core-java-sun/src/main/java/com/baeldung/javac/Positive.java similarity index 100% rename from core-java/src/main/java/com/baeldung/javac/Positive.java rename to core-java-sun/src/main/java/com/baeldung/javac/Positive.java diff --git a/core-java/src/main/java/com/baeldung/javac/SampleJavacPlugin.java b/core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java similarity index 100% rename from core-java/src/main/java/com/baeldung/javac/SampleJavacPlugin.java rename to core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java diff --git a/core-java-sun/src/main/resources/log4j.properties b/core-java-sun/src/main/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/core-java-sun/src/main/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/core-java-sun/src/main/resources/logback.xml b/core-java-sun/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/core-java-sun/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java b/core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java rename to core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleClassFile.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/SimpleClassFile.java rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleFileManager.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/SimpleFileManager.java rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleSourceFile.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/SimpleSourceFile.java rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java diff --git a/core-java/src/test/java/com/baeldung/javac/TestCompiler.java b/core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/TestCompiler.java rename to core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java diff --git a/core-java/src/test/java/com/baeldung/javac/TestRunner.java b/core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java similarity index 100% rename from core-java/src/test/java/com/baeldung/javac/TestRunner.java rename to core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java diff --git a/core-java-sun/src/test/resources/.gitignore b/core-java-sun/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/core-java-sun/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/core-java/pom.xml b/core-java/pom.xml index 77000b8741..2c4cbfc37b 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -181,11 +181,6 @@ 2.1.0.1 - - com.sun.messaging.mq - fscontext - ${fscontext.version} - com.codepoetics protonpack @@ -216,13 +211,6 @@ spring-web 4.3.4.RELEASE - - com.sun - tools - 1.8.0 - system - ${java.home}/../lib/tools.jar - From 1854175cb9b0ba85685abb88bed4de6b8fdd8587 Mon Sep 17 00:00:00 2001 From: Eugen Date: Tue, 28 Nov 2017 12:39:39 +0200 Subject: [PATCH 16/17] Update README.md --- core-java-sun/README.md | 117 ---------------------------------------- 1 file changed, 117 deletions(-) diff --git a/core-java-sun/README.md b/core-java-sun/README.md index 1feee4126e..9cf8b26f1b 100644 --- a/core-java-sun/README.md +++ b/core-java-sun/README.md @@ -3,121 +3,4 @@ ## Core Java Cookbooks and Examples ### Relevant Articles: -- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list) -- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file) -- [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) -- [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) -- [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) -- [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) -- [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) -- [Java – Write to File](http://www.baeldung.com/java-write-to-file) -- [Java - Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream) -- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) -- [Java – Generate Random String](http://www.baeldung.com/java-random-string) -- [Java Scanner](http://www.baeldung.com/java-scanner) -- [Java Timer](http://www.baeldung.com/java-timer-and-timertask) -- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) -- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) -- [MD5 Hashing in Java](http://www.baeldung.com/java-md5) -- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist) -- [Guide to Java Reflection](http://www.baeldung.com/java-reflection) -- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) -- [Convert char to String in Java](http://www.baeldung.com/java-convert-char-to-string) -- [Random List Element](http://www.baeldung.com/java-random-list-element) -- [Convert String to int or Integer in Java](http://www.baeldung.com/java-convert-string-to-int-or-integer) -- [Java – Directory Size](http://www.baeldung.com/java-folder-size) -- [Java – Try with Resources](http://www.baeldung.com/java-try-with-resources) -- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) -- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java) -- [How to Convert String to different data types in Java](http://www.baeldung.com/java-string-conversions) -- [Introduction to Java Generics](http://www.baeldung.com/java-generics) -- [Generate equals() and hashCode() with Eclipse](http://www.baeldung.com/java-eclipse-equals-and-hashcode) -- [A Guide To Java Regular Expressions API](http://www.baeldung.com/regular-expressions-java) -- [Sorting in Java](http://www.baeldung.com/java-sorting) -- [Getting Started with Java Properties](http://www.baeldung.com/java-properties) -- [Grep in Java](http://www.baeldung.com/grep-in-java) -- [Java - Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections) -- [Simulated Annealing for Travelling Salesman Problem](http://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) -- [Slope One Algorithm: Collaborative Filtering Recommendation Systems](http://www.baeldung.com/java-collaborative-filtering-recommendations) -- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](http://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library) -- [Pattern Search with Grep in Java](http://www.baeldung.com/grep-in-java) -- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding) -- [Calculate the Size of a File in Java](http://www.baeldung.com/java-file-size) -- [The Basics of Java Generics](http://www.baeldung.com/java-generics) -- [The Traveling Salesman Problem in Java](http://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) -- [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) -- [How to Design a Genetic Algorithm in Java](http://www.baeldung.com/java-genetic-algorithm) -- [Guide to WeakHashMap in Java](http://www.baeldung.com/java-weakhashmap) -- [Spring Security – Cache Control Headers](http://www.baeldung.com/spring-security-cache-control-headers) -- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions) -- [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda) -- [Introduction to Nashorn](http://www.baeldung.com/java-nashorn) -- [Guide to the Guava BiMap](http://www.baeldung.com/guava-bimap) -- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream) -- [Chained Exceptions in Java](http://www.baeldung.com/java-chained-exceptions) -- [The Java HashMap Under the Hood](http://www.baeldung.com/java-hashmap) -- [A Guide to LinkedHashMap in Java](http://www.baeldung.com/java-linked-hashmap) -- [A Guide to TreeMap in Java](http://www.baeldung.com/java-treemap) -- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng) -- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions) -- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) -- [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list) -- [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list) -- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow) -- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum) -- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections) -- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer) -- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging) -- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe) -- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset) -- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) -- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection) -- [Guide to UUID in JAVA](http://www.baeldung.com/guide-to-uuid-in-java) -- [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path) -- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend) -- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration) -- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) -- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer) -- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number) -- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params) -- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) -- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream) -- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order) -- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) -- [Iterate over a Map in Java](http://www.baeldung.com/java-iterate-map) -- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies) -- [How to Copy an Array in Java](http://www.baeldung.com/java-array-copy) -- [Introduction to JDBC](http://www.baeldung.com/java-jdbc) -- [Period and Duration in Java](http://www.baeldung.com/java-period-duration) -- [Converting a Stack Trace to a String in Java](http://www.baeldung.com/java-stacktrace-to-string) -- [Count Occurrences of a Char in a String](http://www.baeldung.com/java-count-chars) -- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization) -- [The StackOverflowError in Java](http://www.baeldung.com/java-stack-overflow-error) -- [Split a String in Java](http://www.baeldung.com/java-split-string) -- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) -- [How to Remove the Last Character of a String?](http://www.baeldung.com/java-remove-last-character-of-string) -- [ClassNotFoundException vs NoClassDefFoundError](http://www.baeldung.com/java-classnotfoundexception-and-noclassdeffounderror) -- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) -- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char) -- [Guide to hashCode() in Java](http://www.baeldung.com/java-hashcode) -- [Collect a Java Stream to an Immutable Collection](http://www.baeldung.com/java-stream-immutable-collection) -- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri) -- [Broadcasting and Multicasting in Java](http://www.baeldung.com/java-broadcast-multicast) -- [Converting a List to String in Java](http://www.baeldung.com/java-list-to-string) -- [CharSequence vs. String in Java](http://www.baeldung.com/java-char-sequence-string) -- [Period and Duration in Java](http://www.baeldung.com/java-period-duration) -- [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator) -- [Singletons in Java](http://www.baeldung.com/java-singleton) -- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) -- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded) -- [How to Iterate Over a Stream With Indices](http://www.baeldung.com/java-stream-indices) -- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer) -- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) -- [Proxy, Decorator, Adapter and Bridge Patterns](http://www.baeldung.com/java-structural-design-patterns) - [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) -- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static) -- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array) -- [Guide to Java String Pool](http://www.baeldung.com/java-string-pool) -- [Copy a File with Java](http://www.baeldung.com/java-copy-file) -- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns) - From d10a8d7f474d47345b7ef7118c6303644bab30cf Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Wed, 29 Nov 2017 09:53:43 +0100 Subject: [PATCH 17/17] spring junit config (#3124) --- .../jupiter/SpringJUnitConfigTest.java | 33 ++++++++++++++++++ .../jupiter/SpringJUnitWebConfigTest.java | 34 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java create mode 100644 spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java diff --git a/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java b/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java new file mode 100644 index 0000000000..6b0a6f9808 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java @@ -0,0 +1,33 @@ +package com.baeldung.jupiter; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +/** + * @SpringJUnitConfig(SpringJUnitConfigTest.Config.class) is equivalent to: + * + * @ExtendWith(SpringExtension.class) + * @ContextConfiguration(classes = SpringJUnitConfigTest.Config.class ) + * + */ +@SpringJUnitConfig(SpringJUnitConfigTest.Config.class) +public class SpringJUnitConfigTest { + + @Configuration + static class Config { + } + + @Autowired + private ApplicationContext applicationContext; + + @Test + void givenAppContext_WhenInjected_ThenItShouldNotBeNull() { + assertNotNull(applicationContext); + } + +} diff --git a/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java b/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java new file mode 100644 index 0000000000..c679dce77f --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java @@ -0,0 +1,34 @@ +package com.baeldung.jupiter; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.web.context.WebApplicationContext; + +/** + * @SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) is equivalent to: + * + * @ExtendWith(SpringExtension.class) + * @WebAppConfiguration + * @ContextConfiguration(classes = SpringJUnitWebConfigTest.Config.class ) + * + */ +@SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) +public class SpringJUnitWebConfigTest { + + @Configuration + static class Config { + } + + @Autowired + private WebApplicationContext webAppContext; + + @Test + void givenWebAppContext_WhenInjected_ThenItShouldNotBeNull() { + assertNotNull(webAppContext); + } + +}