Skip to content

Package: CucumberWithProperties

CucumberWithProperties

nameinstructionbranchcomplexitylinemethod
CucumberWithProperties(Class)
M: 69 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getProperties(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.qa.common.cucumber;
14:
15: import cucumber.api.junit.Cucumber;
16: import org.junit.runners.model.InitializationError;
17: import org.slf4j.Logger;
18: import org.slf4j.LoggerFactory;
19:
20: import java.io.IOException;
21:
22: /**
23: * Extension of Cucumber junit runner that adds functionality of System properties
24: * that are set with CucumberProperty repeatable annotation with key and value attribute
25: * that represents system property.
26: */
27: public class CucumberWithProperties extends Cucumber {
28:
29: private static final Logger logger = LoggerFactory.getLogger(CucumberWithProperties.class);
30:
31: public CucumberWithProperties(Class<?> clazz) throws InitializationError, IOException {
32: super(clazz);
33:
34: CucumberProperty[] systemProperties = getProperties(clazz);
35:• for (CucumberProperty property : systemProperties) {
36:• if ((property.value() == null) || (property.value().length() == 0)) {
37: logger.info("Clearing property " + property.key());
38: System.clearProperty(property.key());
39: } else {
40: logger.info("Setting property " + property.key() + ", value is " + property.value());
41: System.setProperty(property.key(), property.value());
42: }
43: }
44: }
45:
46: /**
47: * Extract repeatable CucumberProperty from annotation on junit runner CucumberWithProperties
48: *
49: * @param clazz Class that is annotated
50: * @return property repeatable array of key / value pairs as CucumberProperty class
51: */
52: private CucumberProperty[] getProperties(Class<?> clazz) {
53:
54: return clazz.getAnnotationsByType(CucumberProperty.class);
55: }
56: }