Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
#293 Fixed sysprop set in the TestModule
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrzyzanowski committed Nov 5, 2018
1 parent ca75c7f commit 3d05958
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestModule extends AbstractModule {
@Override
protected void configure() {
System.setProperty(ConfigKeys.COOKIES_LOAD_AUTOMATICALLY, "false");
System.setProperty("bobcat.config.contexts", "additional-context1, additional-context4");
System.setProperty("bobcat.config.contexts", "additional-context1,additional-context4");
install(new CoreModule());
bind(Item.class).to(Food.class);
bind(ListItem.class).to(ListItemImpl.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.junit5.properties;

import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.create;

import java.util.Properties;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

public class SystemPropertyExtension implements BeforeEachCallback, AfterEachCallback {

private static final ExtensionContext.Namespace NAMESPACE = create("com.cognifide.qa.bb");
private static final String INITIAL_PROPERTIES = "initialProperties";

@Override
public void afterEach(ExtensionContext context) throws Exception {
Properties properties = context.getStore(NAMESPACE).get(INITIAL_PROPERTIES, Properties.class);
System.setProperties(properties);
}

@Override
public void beforeEach(ExtensionContext context) throws Exception {
Properties rawProps = System.getProperties();
context.getStore(NAMESPACE).put(INITIAL_PROPERTIES, rawProps);
System.setProperties(new Properties(rawProps));
}
}

0 comments on commit 3d05958

Please sign in to comment.