Merge branch 'master' of github.com:eugenp/tutorials into master
This commit is contained in:
@@ -5,3 +5,4 @@ This module contains articles about AWS Lambda
|
||||
### Relevant Articles:
|
||||
- [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway)
|
||||
- [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless)
|
||||
- [How to Implement Hibernate in an AWS Lambda Function in Java](https://www.baeldung.com/java-aws-lambda-hibernate)
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-groovy-strings</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>core-groovy-strings</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
<version>${groovy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>${groovy-all.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-dateutil</artifactId>
|
||||
<version>${groovy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-sql</artifactId>
|
||||
<version>${groovy-sql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>${hsqldb.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>spock-core</artifactId>
|
||||
<version>${spock-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>${gmavenplus-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addSources</goal>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${maven-failsafe-plugin.version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>junit5</id>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Test5.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
<groovy-all.version>2.5.6</groovy-all.version>
|
||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.baeldung.removeprefix
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class RemovePrefixTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void whenCasePrefixIsRemoved_thenReturnTrue() {
|
||||
def trimPrefix = {
|
||||
it.startsWith('Groovy-') ? it.minus('Groovy-') : it
|
||||
}
|
||||
|
||||
def actual = trimPrefix("Groovy-Tutorials at Baeldung")
|
||||
def expected = "Tutorials at Baeldung"
|
||||
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPrefixIsRemoved_thenReturnTrue() {
|
||||
|
||||
String prefix = "groovy-"
|
||||
String trimPrefix = "Groovy-Tutorials at Baeldung"
|
||||
def actual;
|
||||
if(trimPrefix.startsWithIgnoreCase(prefix)) {
|
||||
actual = trimPrefix.substring(prefix.length())
|
||||
}
|
||||
|
||||
def expected = "Tutorials at Baeldung"
|
||||
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPrefixIsRemovedUsingRegex_thenReturnTrue() {
|
||||
|
||||
def regex = ~"^([Gg])roovy-"
|
||||
String trimPrefix = "Groovy-Tutorials at Baeldung"
|
||||
String actual = trimPrefix - regex
|
||||
|
||||
def expected = "Tutorials at Baeldung"
|
||||
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() {
|
||||
def regex = ~"^groovy"
|
||||
String trimPrefix = "groovyTutorials at Baeldung's groovy page"
|
||||
String actual = trimPrefix.replaceFirst(regex, "")
|
||||
|
||||
def expected = "Tutorials at Baeldung's groovy page"
|
||||
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() {
|
||||
|
||||
String trimPrefix = "groovyTutorials at Baeldung groovy"
|
||||
String actual = trimPrefix.replaceAll(/^groovy/, "")
|
||||
|
||||
def expected = "Tutorials at Baeldung groovy"
|
||||
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,3 +6,4 @@ This module contains complete guides about arrays in Java
|
||||
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
|
||||
- [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays)
|
||||
- [What is \[Ljava.lang.Object;?](https://www.baeldung.com/java-tostring-array)
|
||||
- [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception)
|
||||
|
||||
+43
-20
@@ -1,6 +1,8 @@
|
||||
package com.baeldung.date;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.Minutes;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -16,7 +18,7 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DateDiffUnitTest {
|
||||
|
||||
@@ -29,18 +31,39 @@ public class DateDiffUnitTest {
|
||||
long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
|
||||
long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate sixDaysBehind = now.minusDays(6);
|
||||
public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenWorks() {
|
||||
LocalDate aDate = LocalDate.of(2020, 9, 11);
|
||||
LocalDate sixDaysBehind = aDate.minusDays(6);
|
||||
|
||||
Period period = Period.between(now, sixDaysBehind);
|
||||
Period period = Period.between(aDate, sixDaysBehind);
|
||||
int diff = Math.abs(period.getDays());
|
||||
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenDoesNotWork() {
|
||||
LocalDate aDate = LocalDate.of(2020, 9, 11);
|
||||
LocalDate sixtyDaysBehind = aDate.minusDays(60);
|
||||
Period period = Period.between(aDate, sixtyDaysBehind);
|
||||
int diff = Math.abs(period.getDays());
|
||||
//not equals
|
||||
assertNotEquals(60, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDatesInJava8_whenUsingPeriod_thenWeGet0Year1Month29Days() {
|
||||
LocalDate aDate = LocalDate.of(2020, 9, 11);
|
||||
LocalDate sixtyDaysBehind = aDate.minusDays(60);
|
||||
Period period = Period.between(aDate, sixtyDaysBehind);
|
||||
int years = Math.abs(period.getYears());
|
||||
int months = Math.abs(period.getMonths());
|
||||
int days = Math.abs(period.getDays());
|
||||
assertArrayEquals(new int[] { 0, 1, 29 }, new int[] { years, months, days });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +74,7 @@ public class DateDiffUnitTest {
|
||||
Duration duration = Duration.between(now, sixMinutesBehind);
|
||||
long diff = Math.abs(duration.toMinutes());
|
||||
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +84,7 @@ public class DateDiffUnitTest {
|
||||
|
||||
long diff = ChronoUnit.SECONDS.between(now, tenSecondsLater);
|
||||
|
||||
assertEquals(diff, 10);
|
||||
assertEquals(10, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,9 +92,9 @@ public class DateDiffUnitTest {
|
||||
LocalDateTime ldt = LocalDateTime.now();
|
||||
ZonedDateTime now = ldt.atZone(ZoneId.of("America/Montreal"));
|
||||
ZonedDateTime sixDaysBehind = now.withZoneSameInstant(ZoneId.of("Asia/Singapore"))
|
||||
.minusDays(6);
|
||||
.minusDays(6);
|
||||
long diff = ChronoUnit.DAYS.between(sixDaysBehind, now);
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +104,7 @@ public class DateDiffUnitTest {
|
||||
|
||||
long diff = now.until(tenSecondsLater, ChronoUnit.SECONDS);
|
||||
|
||||
assertEquals(diff, 10);
|
||||
assertEquals(10, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,10 +112,9 @@ public class DateDiffUnitTest {
|
||||
org.joda.time.LocalDate now = org.joda.time.LocalDate.now();
|
||||
org.joda.time.LocalDate sixDaysBehind = now.minusDays(6);
|
||||
|
||||
org.joda.time.Period period = new org.joda.time.Period(now, sixDaysBehind);
|
||||
long diff = Math.abs(period.getDays());
|
||||
long diff = Math.abs(Days.daysBetween(now, sixDaysBehind).getDays());
|
||||
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,8 +122,9 @@ public class DateDiffUnitTest {
|
||||
org.joda.time.LocalDateTime now = org.joda.time.LocalDateTime.now();
|
||||
org.joda.time.LocalDateTime sixMinutesBehind = now.minusMinutes(6);
|
||||
|
||||
org.joda.time.Period period = new org.joda.time.Period(now, sixMinutesBehind);
|
||||
long diff = Math.abs(period.getDays());
|
||||
long diff = Math.abs(Minutes.minutesBetween(now, sixMinutesBehind).getMinutes());
|
||||
assertEquals(6, diff);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,6 +134,6 @@ public class DateDiffUnitTest {
|
||||
|
||||
long diff = Math.abs(now.numDaysFrom(sixDaysBehind));
|
||||
|
||||
assertEquals(diff, 6);
|
||||
assertEquals(6, diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [NoSuchMethodError in Java](https://www.baeldung.com/java-nosuchmethod-error)
|
||||
- [IllegalArgumentException or NullPointerException for a Null Parameter?](https://www.baeldung.com/java-illegalargumentexception-or-nullpointerexception)
|
||||
- [IllegalMonitorStateException in Java](https://www.baeldung.com/java-illegalmonitorstateexception)
|
||||
|
||||
@@ -10,4 +10,5 @@ This module contains articles about core Java input and output (IO)
|
||||
- [Copy a Directory in Java](https://www.baeldung.com/java-copy-directory)
|
||||
- [Java Files Open Options](https://www.baeldung.com/java-file-options)
|
||||
- [Creating Temporary Directories in Java](https://www.baeldung.com/java-temp-directories)
|
||||
- [Reading a Line at a Given Line Number From a File in Java](https://www.baeldung.com/java-read-line-at-number)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-io-2)
|
||||
|
||||
@@ -5,4 +5,5 @@ This module contains articles about core features in the Java language
|
||||
- [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom)
|
||||
- [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean)
|
||||
- [When are Static Variables Initialized in Java?](https://www.baeldung.com/java-static-variables-initialization)
|
||||
- [Checking if a Class Exists in Java](https://www.baeldung.com/java-check-class-exists)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-2)
|
||||
|
||||
@@ -13,4 +13,5 @@
|
||||
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
|
||||
- [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging)
|
||||
- [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication)
|
||||
- [Largest Power of 2 That Is Less Than the Given Number](https://www.baeldung.com/java-largest-power-of-2-less-than-number)
|
||||
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math)
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
This module contains articles about core Kotlin collections.
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
## Relevant articles:
|
||||
|
||||
- [Aggregate Operations in Kotlin](https://www.baeldung.com/kotlin/aggregate-operations)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
## Relevant Articles:
|
||||
|
||||
- [Passing Command Line Arguments in Gradle](https://www.baeldung.com/gradle-command-line-arguments)
|
||||
@@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Gradle Source Sets](https://www.baeldung.com/gradle-source-sets)
|
||||
@@ -11,3 +11,4 @@ This module contains articles about security libraries.
|
||||
- [Intro to Jasypt](https://www.baeldung.com/jasypt)
|
||||
- [Digital Signatures in Java](https://www.baeldung.com/java-digital-signature)
|
||||
- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys)
|
||||
- [SSH Connection With Java](https://www.baeldung.com/java-ssh-connection)
|
||||
|
||||
@@ -12,3 +12,4 @@ This module contains articles about test libraries.
|
||||
- [Introduction to Hoverfly in Java](https://www.baeldung.com/hoverfly)
|
||||
- [Testing with Hamcrest](https://www.baeldung.com/java-junit-hamcrest-guide)
|
||||
- [Introduction To DBUnit](https://www.baeldung.com/java-dbunit)
|
||||
- [Introduction to ArchUnit](https://www.baeldung.com/java-archunit-intro)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
- [Service Locator Pattern](https://www.baeldung.com/java-service-locator-pattern)
|
||||
- [The DAO Pattern in Java](https://www.baeldung.com/java-dao-pattern)
|
||||
- [DAO vs Repository Patterns](https://www.baeldung.com/java-dao-vs-repository)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway)
|
||||
- [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks)
|
||||
- [Rolling Back Migrations with Flyway](https://www.baeldung.com/flyway-roll-back)
|
||||
@@ -383,6 +383,7 @@
|
||||
<module>core-groovy</module>
|
||||
<module>core-groovy-2</module>
|
||||
<module>core-groovy-collections</module>
|
||||
<module>core-groovy-strings</module>
|
||||
|
||||
<module>core-java-modules</module>
|
||||
<module>core-kotlin-modules</module>
|
||||
@@ -894,6 +895,7 @@
|
||||
<module>core-groovy</module>
|
||||
<module>core-groovy-2</module>
|
||||
<module>core-groovy-collections</module>
|
||||
<module>core-groovy-strings</module>
|
||||
|
||||
<module>core-java-modules</module>
|
||||
<module>core-kotlin-modules</module>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
## Relevant Articles:
|
||||
|
||||
- [Guide to QuarkusIO](https://www.baeldung.com/quarkus-io)
|
||||
- [Testing Quarkus Applications](https://www.baeldung.com/java-quarkus-testing)
|
||||
|
||||
@@ -99,6 +99,8 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<systemProperties>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
</systemProperties>
|
||||
|
||||
@@ -7,3 +7,4 @@ This module contains articles about Spring 5 OAuth Security
|
||||
- [Spring Security 5 – OAuth2 Login](https://www.baeldung.com/spring-security-5-oauth2-login)
|
||||
- [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor)
|
||||
- [Customizing Authorization and Token Requests with Spring Security 5.1 Client](https://www.baeldung.com/spring-security-custom-oauth-requests)
|
||||
- [Social Login with Spring Security in a Jersey Application](https://www.baeldung.com/spring-security-social-login-jersey)
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.inmemory;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
//@Configuration
|
||||
public class InMemoryNoOpAuthWebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication()
|
||||
.withUser("spring")
|
||||
.password("{noop}secret")
|
||||
.roles("USER");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/private/**")
|
||||
.authenticated()
|
||||
.antMatchers("/public/**")
|
||||
.permitAll()
|
||||
.and()
|
||||
.httpBasic();
|
||||
}
|
||||
}
|
||||
@@ -8,3 +8,4 @@ This module contains articles about Spring 5 WebFlux
|
||||
- [How to Return 404 with Spring WebFlux](https://www.baeldung.com/spring-webflux-404)
|
||||
- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters)
|
||||
- [RSocket Using Spring Boot](https://www.baeldung.com/spring-boot-rsocket)
|
||||
- [Spring MVC Async vs Spring WebFlux](https://www.baeldung.com/spring-mvc-async-vs-webflux)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user