Merge pull request #11428 from chaos2418/JAVA-1672

Java 1672 - updating root pom junit and surefire configurations for jhipster
This commit is contained in:
Loredana Crusoveanu 2021-11-08 20:23:45 +02:00 committed by GitHub
commit 6d6eb8b200
9 changed files with 113 additions and 3 deletions

View File

@ -0,0 +1,20 @@
package com.baeldung.firstword;
public class FirstWordGetter {
public static void main(String[] args) {
String input = "Roberto \"I wish you a bug-free day\"";
System.out.println("Using split: " + getFirstWordUsingSplit(input));
System.out.println("Using subString: " + getFirstWordUsingSubString(input));
}
public static String getFirstWordUsingSubString(String input) {
int index = input.contains(" ") ? input.indexOf(" ") : 0;
return input.substring(0, index);
}
public static String getFirstWordUsingSplit(String input) {
String[] tokens = input.split(" ", 2);
return tokens[0];
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.firstword;
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSplit;
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSubString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class FirstWordGetterUnitTest {
@Test
public void givenString_whenSplit_thenFirstWordIsReturned() {
assertEquals("Roberto", getFirstWordUsingSplit("Roberto \"I wish you a bug-free day\""));
}
@Test
public void givenStringWithNoSpace_whenSplit_thenFirstWordIsReturned() {
assertEquals("StringWithNoSpace", getFirstWordUsingSplit("StringWithNoSpace"));
}
@Test
public void givenString_whenPassedToSubstring_thenFirstWordIsReturned() {
assertEquals("Roberto", getFirstWordUsingSubString("Roberto \"I wish you a bug-free day\""));
}
@Test
public void givenStringWithNoSpace_whenPassedToSubstring_thenFirstWordIsReturned() {
assertEquals("", getFirstWordUsingSubString("StringWithNoSpace"));
}
}

View File

@ -1054,7 +1054,6 @@
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
<jib-maven-plugin.version>0.9.11</jib-maven-plugin.version>
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>

View File

@ -874,7 +874,6 @@
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
<jib-maven-plugin.version>0.9.11</jib-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version>

View File

@ -875,7 +875,6 @@
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
<jib-maven-plugin.version>0.9.11</jib-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version>

View File

@ -1,3 +1,5 @@
drop table if exists client;
create table client (
id numeric,
name varchar(50),

View File

@ -0,0 +1,17 @@
package com.baeldung.startup;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
@Component
public class ResourceInitializer {
ResourceInitializer() throws Exception {
// simulate resource init with random delay of a few seconds
int randomDelay = ThreadLocalRandom.current().nextInt(5, 9);
TimeUnit.SECONDS.sleep(randomDelay);
}
}

View File

@ -0,0 +1,38 @@
package com.baeldung.startup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import static java.lang.Boolean.FALSE;
@SpringBootApplication(exclude = {
SecurityAutoConfiguration.class,
ManagementWebSecurityAutoConfiguration.class}
)
public class StartupTrackingApplication {
public static void main(String[] args) {
// only load properties for this application
System.setProperty("spring.config.location", "classpath:application-startup.properties");
SpringApplication app = new SpringApplication(StartupTrackingApplication.class);
BufferingApplicationStartup startup = new BufferingApplicationStartup(2048);
if (shouldFilterSteps()) {
startup.addFilter(startupStep -> startupStep.getName().matches("spring.beans.instantiate"));
}
app.setApplicationStartup(startup);
app.run(args);
}
private static boolean shouldFilterSteps() {
return Boolean.parseBoolean(
System.getProperty("startup.steps.filter", FALSE.toString())
);
}
}

View File

@ -0,0 +1,6 @@
management.endpoints.web.exposure.include=startup
# JPA is not required for startup actuator endpoint
spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, \
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, \
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration