forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hajarrs/[email protected] (eugenp#17902)
Co-authored-by: hajar.qaibou_juliusbaer.com <[email protected]>
- Loading branch information
Showing
11 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/target/ | ||
.settings/ | ||
.classpath | ||
.project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
26 changes: 26 additions & 0 deletions
26
spring-boot-modules/spring-boot-testing-4/src/main/java/com/baeldung/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ing-boot-testing-4/src/test/java/com/baeldung/mainclasstest/ApplicationArgumentsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...pring-boot-testing-4/src/test/java/com/baeldung/mainclasstest/ApplicationContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...s/spring-boot-testing-4/src/test/java/com/baeldung/mainclasstest/ApplicationMainTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] {}); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...s/spring-boot-testing-4/src/test/java/com/baeldung/mainclasstest/ApplicationMockTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] {})); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...pring-boot-testing-4/src/test/java/com/baeldung/mainclasstest/ApplicationUseMainTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |