Skip to content

Commit

Permalink
Test Refactor (YamlServletProfileInitializerTest, YamlServletProfileI…
Browse files Browse the repository at this point in the history
…nitializerTests)

- Combine test files that test the same class
- Also, Extensions shouldn't have state, store state in the store!

[#162794188] https://www.pivotaltracker.com/story/show/162794188
  • Loading branch information
joshuatcasey authored and andrewedstrom committed Mar 18, 2019
1 parent cf1ac78 commit 73a2f0a
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 332 deletions.
Expand Up @@ -10,16 +10,19 @@

public class LoggerContextCleanupExtension implements BeforeAllCallback, AfterAllCallback {

private URI configLocation = null;

@Override
public void beforeAll(ExtensionContext context) {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
configLocation = loggerContext.getConfigLocation();

ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(context.getRequiredTestClass()));
store.put("configLocation", loggerContext.getConfigLocation());
}

@Override
public void afterAll(ExtensionContext context) {
ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(context.getRequiredTestClass()));
URI configLocation = store.get("configLocation", URI.class);

LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
loggerContext.setConfigLocation(configLocation);
}
Expand Down
Expand Up @@ -6,15 +6,17 @@

public class SpringProfileCleanupExtension implements BeforeAllCallback, AfterAllCallback {

private static String activeSpringProfiles;

@Override
public void beforeAll(ExtensionContext context) {
activeSpringProfiles = System.getProperty("spring.profiles.active");
ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(context.getRequiredTestClass()));
store.put("spring.profiles.active", System.getProperty("spring.profiles.active"));
}

@Override
public void afterAll(ExtensionContext context) {
ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(context.getRequiredTestClass()));
String activeSpringProfiles = store.get("spring.profiles.active", String.class);

if (activeSpringProfiles != null) {
System.setProperty("spring.profiles.active", activeSpringProfiles);
} else {
Expand Down

0 comments on commit 73a2f0a

Please sign in to comment.