* commit first as binodpanta

* revert test change

* A short example of real-time event streaming using Spring WebFlux

* Code for http://jira.baeldung.com/browse/BAEL-1527

* remove unrelated files

* Apply feedback changes to rename test and remove link from readme file, ongoing work

* Update formatting fixes to code and add pom changes, that partially fix test runnning issues in IDE but not in cmdline

* Apply Eclipse formatter to test code and apply suggested pom fixes

* BAEL-1527 Formatting fix in pom.xml
This commit is contained in:
Binod Pant 2018-05-27 18:25:01 -04:00 committed by Predrag Maric
parent a3563f0ef5
commit db233245e3
4 changed files with 70 additions and 2 deletions

View File

@ -12,3 +12,5 @@
- [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception)
- [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall)
- [Migrating from JUnit 4 to JUnit 5](http://www.baeldung.com/junit-5-migration)

View File

@ -56,6 +56,11 @@
</build>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
@ -96,8 +101,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.jupiter.version>5.1.0</junit.jupiter.version>
<junit.platform.version>1.0.1</junit.platform.version>
<junit.vintage.version>4.12.1</junit.vintage.version>
<junit.platform.version>1.1.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<log4j2.version>2.8.2</log4j2.version>
<h2.version>1.4.196</h2.version>
<mockito.version>2.11.0</mockito.version>

View File

@ -0,0 +1,27 @@
package com.baeldung;
import com.baeldung.extensions.RegisterExtensionSampleExtension;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/**
* This test demonstrates the use of the same extension in two ways.
* 1. Once as instance level field: Only method level callbacks are called.
* 2. Once as class level static field: All methods are called.
*/
public class RegisterExtensionUnitTest {
@RegisterExtension
static RegisterExtensionSampleExtension staticExtension = new RegisterExtensionSampleExtension("static version");
@RegisterExtension
RegisterExtensionSampleExtension instanceLevelExtension = new RegisterExtensionSampleExtension("instance version");
@Test
public void demoTest() {
Assertions.assertEquals("instance version", instanceLevelExtension.getType());
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.extensions;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This extension is meant to demonstrate the use of RegisterExtension.
*/
public class RegisterExtensionSampleExtension implements BeforeAllCallback, BeforeEachCallback {
private final String type;
Logger logger = LoggerFactory.getLogger(RegisterExtensionSampleExtension.class);
public RegisterExtensionSampleExtension(String type) {
this.type = type;
}
@Override
public void beforeAll(ExtensionContext extensionContext) throws Exception {
logger.info("Type " + type + " In beforeAll : " + extensionContext.getDisplayName());
}
@Override
public void beforeEach(ExtensionContext extensionContext) throws Exception {
logger.info("Type " + type + " In beforeEach : " + extensionContext.getDisplayName());
}
public String getType() {
return type;
}
}