Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: hajar.qaibou_juliusbaer.com <[email protected]>
  • Loading branch information
hajarrs and hajar.qaibou_juliusbaer.com authored Nov 25, 2024
1 parent f569901 commit ea9eaa8
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 6 deletions.
12 changes: 7 additions & 5 deletions spring-boot-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,24 @@
<module>spring-boot-telegram</module>
<module>spring-boot-springdoc</module>
<module>spring-boot-swagger</module>
<!-- <module>spring-boot-swagger-2</module>--> <!-- failing after upgrading to spring boot 3. Swagger codegen yet not compatible?!-->
<!-- <module>spring-boot-swagger-2</module>--> <!-- failing after upgrading to spring boot 3. Swagger codegen yet not
compatible?!-->
<module>spring-boot-swagger-jwt</module>
<module>spring-boot-swagger-keycloak</module>
<module>spring-boot-swagger-springfox</module>
<module>spring-boot-testing</module>
<module>spring-boot-testing-2</module>
<module>spring-boot-testing-3</module>
<module>spring-boot-testing-4</module>
<module>spring-boot-testing-spock</module>
<module>spring-boot-vue</module>
<module>spring-boot-actuator</module>
<module>spring-boot-data-2</module>
<module>spring-boot-validation</module>
<!-- <module>spring-boot-data-3</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-data-3</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-redis</module>
<module>spring-boot-cassandre</module>
<!-- <module>spring-boot-react</module>--> <!-- Migrated to heavy profile -->
<!-- <module>spring-boot-react</module>--> <!-- Migrated to heavy profile -->
<module>spring-caching-3</module>
<!-- <module>spring-boot-3</module> --> <!-- JAVA-20931 -->
<module>spring-boot-3-grpc</module>
Expand Down Expand Up @@ -132,7 +134,7 @@
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugin>
</plugins>
</build>

Expand All @@ -155,4 +157,4 @@
</dependencies>
</dependencyManagement>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
}
5 changes: 5 additions & 0 deletions spring-boot-modules/spring-boot-testing-4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
.settings/
.classpath
.project

9 changes: 9 additions & 0 deletions spring-boot-modules/spring-boot-testing-4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Spring Boot Testing

This module contains articles about Spring Boot testing

### The Course

The "REST With Spring" Classes: http://bit.ly/restwithspring

### Relevant Articles:
58 changes: 58 additions & 0 deletions spring-boot-modules/spring-boot-testing-4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>spring-boot-testing-4</artifactId>
<name>spring-boot-testing-4</name>
<packaging>jar</packaging>
<description>This is simple boot application for demonstrating testing features.</description>

<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<configuration>
<excludes>
<exclude>com/baeldung/Application*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<start-class>com.baeldung.Application</start-class>
<gson.version>2.11.0</gson.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.baeldung.mainclasstest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class Application {
/*
//@Generated(value = "Spring Boot")
@SuppressWarnings("unused")
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.OFF); app.setLogStartupInfo(false);
app.setDefaultProperties(Collections.singletonMap("server.port", "8083")); app.run(args);
}
*/
public static void main(String[] args) {
initializeApplication(args);
}

static ConfigurableApplicationContext initializeApplication(String[] args) {
return SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.baeldung.mainclasstest;

import org.junit.jupiter.api.Test;

public class ApplicationArgumentsTest {
@Test
public void testMainWithArguments() {
String[] args = { "--spring.profiles.active=test" };
Application.main(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.baeldung.mainclasstest;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ApplicationContextTest {

@Test
void contextLoads() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.baeldung.mainclasstest;

import org.junit.jupiter.api.Test;

public class ApplicationMainTest {

@Test
public void testMain() {
Application.main(new String[] {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.baeldung.mainclasstest;

import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

public class ApplicationMockTest {

@Test
public void testInitializeApplicationWithMock() {
try (MockedStatic<SpringApplication> springApplicationMock = mockStatic(SpringApplication.class)) {
ConfigurableApplicationContext mockContext = mock(ConfigurableApplicationContext.class);

springApplicationMock.when(() -> SpringApplication.run(Application.class, new String[] {}))
.thenReturn(mockContext);

Application.initializeApplication(new String[] {});

springApplicationMock.verify(() -> SpringApplication.run(Application.class, new String[] {}));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.baeldung.mainclasstest;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(useMainMethod = SpringBootTest.UseMainMethod.ALWAYS)
public class ApplicationUseMainTest {
@Test
public void contextLoads() {
}
}

0 comments on commit ea9eaa8

Please sign in to comment.