aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/java/org/testng/ReporterConfig.java10
-rw-r--r--src/main/java/org/testng/TestNG.java9
-rwxr-xr-xsrc/main/java/org/testng/internal/IPathUtils.java26
-rwxr-xr-xsrc/main/java/org/testng/internal/IPropertyUtils.java28
-rwxr-xr-xsrc/main/java/org/testng/internal/PathUtils.java32
-rw-r--r--src/main/java/org/testng/internal/PathUtilsFactory.java51
-rwxr-xr-xsrc/main/java/org/testng/internal/PathUtilsMock.java28
-rwxr-xr-xsrc/main/java/org/testng/internal/PropertyUtils.java8
-rwxr-xr-xsrc/main/java/org/testng/internal/PropertyUtilsFactory.java51
-rwxr-xr-xsrc/main/java/org/testng/internal/PropertyUtilsMock.java36
10 files changed, 269 insertions, 10 deletions
diff --git a/src/main/java/org/testng/ReporterConfig.java b/src/main/java/org/testng/ReporterConfig.java
index de7f362c..e3e06391 100755
--- a/src/main/java/org/testng/ReporterConfig.java
+++ b/src/main/java/org/testng/ReporterConfig.java
@@ -2,7 +2,8 @@ package org.testng;
import org.testng.collections.Lists;
import org.testng.internal.ClassHelper;
-import org.testng.internal.PropertyUtils;
+import org.testng.internal.IPropertyUtils;
+import org.testng.internal.PropertyUtilsFactory;
import org.testng.internal.Utils;
import java.util.List;
@@ -27,6 +28,11 @@ public class ReporterConfig {
*/
private List<Property> m_properties = Lists.newArrayList();
+ /**
+ * JavaBeans properties access helper
+ */
+ private IPropertyUtils mPropertyUtils = PropertyUtilsFactory.newInstance();
+
public void addProperty(Property property) {
m_properties.add(property);
}
@@ -99,7 +105,7 @@ public class ReporterConfig {
if (reporterClass != null) {
result = ClassHelper.newInstance(reporterClass);
for (ReporterConfig.Property property : m_properties) {
- PropertyUtils.setProperty(result, property.getName(), property.getValue());
+ mPropertyUtils.setProperty(result, property.getName(), property.getValue());
}
}
return result;
diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index 1925690a..c3c7d7b7 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -5,8 +5,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -30,8 +28,10 @@ import org.testng.internal.ClassHelper;
import org.testng.internal.Configuration;
import org.testng.internal.DynamicGraph;
import org.testng.internal.IConfiguration;
+import org.testng.internal.IPathUtils;
import org.testng.internal.IResultListener2;
import org.testng.internal.OverrideProcessor;
+import org.testng.internal.PathUtilsFactory;
import org.testng.internal.SuiteRunnerMap;
import org.testng.internal.Utils;
import org.testng.internal.Version;
@@ -191,6 +191,8 @@ public class TestNG {
private boolean m_isInitialized = false;
+ private IPathUtils m_pathUtils = PathUtilsFactory.newInstance();
+
/**
* Default constructor. Setting also usage of default listeners/reporters.
*/
@@ -278,9 +280,8 @@ public class TestNG {
//to parse the suite files (<suite-file>), if any
for (XmlSuite s: m_suites) {
for (String suiteFile : s.getSuiteFiles()) {
- Path rootPath = Paths.get(s.getFileName()).getParent();
try {
- Collection<XmlSuite> childSuites = getParser(rootPath.resolve(suiteFile).normalize().toString()).parse();
+ Collection<XmlSuite> childSuites = getParser(m_pathUtils.getSuiteNormalizedPath(s, suiteFile)).parse();
for (XmlSuite cSuite : childSuites){
cSuite.setParentSuite(s);
s.getChildSuites().add(cSuite);
diff --git a/src/main/java/org/testng/internal/IPathUtils.java b/src/main/java/org/testng/internal/IPathUtils.java
new file mode 100755
index 00000000..325e3bd1
--- /dev/null
+++ b/src/main/java/org/testng/internal/IPathUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+import org.testng.xml.XmlSuite;
+
+/**
+ * Utility class for setting JavaBeans-style properties on instances.
+ */
+public interface IPathUtils {
+ public String getSuiteNormalizedPath(XmlSuite suite, String suiteFile);
+}
diff --git a/src/main/java/org/testng/internal/IPropertyUtils.java b/src/main/java/org/testng/internal/IPropertyUtils.java
new file mode 100755
index 00000000..2ea178ed
--- /dev/null
+++ b/src/main/java/org/testng/internal/IPropertyUtils.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+/**
+ * Utility class for setting JavaBeans-style properties on instances.
+ */
+public interface IPropertyUtils {
+ public void setProperty(Object instance, String name, String value);
+
+ public Class getPropertyType(Class instanceClass, String propertyName);
+
+ public void setPropertyRealValue(Object instance, String name, Object value);
+}
diff --git a/src/main/java/org/testng/internal/PathUtils.java b/src/main/java/org/testng/internal/PathUtils.java
new file mode 100755
index 00000000..2a2ec333
--- /dev/null
+++ b/src/main/java/org/testng/internal/PathUtils.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.testng.xml.XmlSuite;
+
+/**
+ * Utility class for using Paths.
+ */
+public class PathUtils implements IPathUtils {
+ public String getSuiteNormalizedPath(XmlSuite suite, String suiteFile) {
+ Path rootPath = Paths.get(suite.getFileName()).getParent();
+ return rootPath.resolve(suiteFile).normalize().toString();
+ }
+}
diff --git a/src/main/java/org/testng/internal/PathUtilsFactory.java b/src/main/java/org/testng/internal/PathUtilsFactory.java
new file mode 100644
index 00000000..f13c7c63
--- /dev/null
+++ b/src/main/java/org/testng/internal/PathUtilsFactory.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Factory for IPathUtils that returns a concrete instance.
+ */
+public class PathUtilsFactory {
+
+ /**
+ * Tries to make a real PathUtils, if the platform supports it. Otherwise creates
+ * a mock PathUtils that throws UnsupportedOperationException if any method is called on it.
+ */
+ public static IPathUtils newInstance() {
+ try {
+ Class<?> propertyUtilsClass = Class.forName("org.testng.internal.PathUtils");
+ Constructor<?> constructor = propertyUtilsClass.getConstructor();
+ try {
+ return (IPathUtils)constructor.newInstance();
+ }
+ catch (Exception e) {
+ // Impossible: Constructor should not be failing.
+ throw new AssertionError(e);
+ }
+ } catch (ClassNotFoundException e) {
+ // OK: On a platform where java beans are not supported
+ return new PathUtilsMock();
+ } catch (NoSuchMethodException e) {
+ // Impossible. PathUtils should have a 0-arg constructor.
+ throw new AssertionError(e);
+ }
+ }
+
+ private PathUtilsFactory() {}
+}
diff --git a/src/main/java/org/testng/internal/PathUtilsMock.java b/src/main/java/org/testng/internal/PathUtilsMock.java
new file mode 100755
index 00000000..ada51b45
--- /dev/null
+++ b/src/main/java/org/testng/internal/PathUtilsMock.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+import org.testng.xml.XmlSuite;
+
+/**
+ * Utility class for using Paths.
+ */
+public class PathUtilsMock implements IPathUtils {
+ public String getSuiteNormalizedPath(XmlSuite suite, String suiteFile) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/src/main/java/org/testng/internal/PropertyUtils.java b/src/main/java/org/testng/internal/PropertyUtils.java
index ba691104..0864d070 100755
--- a/src/main/java/org/testng/internal/PropertyUtils.java
+++ b/src/main/java/org/testng/internal/PropertyUtils.java
@@ -14,11 +14,11 @@ import java.lang.reflect.Method;
*
* @author Cosmin Marginean, Apr 12, 2007
*/
-public class PropertyUtils {
+public class PropertyUtils implements IPropertyUtils {
private static final Logger LOGGER = Logger.getLogger(PropertyUtils.class);
- public static void setProperty(Object instance, String name, String value) {
+ public void setProperty(Object instance, String name, String value) {
if (instance == null) {
LOGGER.warn("Cannot set property " + name + " with value " + value + ". The target instance is null");
return;
@@ -35,7 +35,7 @@ public class PropertyUtils {
setPropertyRealValue(instance, name, realValue);
}
- public static Class getPropertyType(Class instanceClass, String propertyName) {
+ public Class getPropertyType(Class instanceClass, String propertyName) {
if (instanceClass == null) {
LOGGER.warn("Cannot retrieve property class for " + propertyName + ". Target instance class is null");
}
@@ -64,7 +64,7 @@ public class PropertyUtils {
return result;
}
- public static void setPropertyRealValue(Object instance, String name, Object value) {
+ public void setPropertyRealValue(Object instance, String name, Object value) {
if (instance == null) {
LOGGER.warn("Cannot set property " + name + " with value " + value + ". Targe instance is null");
return;
diff --git a/src/main/java/org/testng/internal/PropertyUtilsFactory.java b/src/main/java/org/testng/internal/PropertyUtilsFactory.java
new file mode 100755
index 00000000..11a446e7
--- /dev/null
+++ b/src/main/java/org/testng/internal/PropertyUtilsFactory.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Factory for IPropertyUtils that returns a concrete instance.
+ */
+public class PropertyUtilsFactory {
+
+ /**
+ * Tries to make a real PropertyUtils, if the platform supports it. Otherwise creates
+ * a mock PropertyUtils that throws UnsupportedOperationException if any method is called on it.
+ */
+ public static IPropertyUtils newInstance() {
+ try {
+ Class<?> propertyUtilsClass = Class.forName("org.testng.internal.PropertyUtils");
+ Constructor<?> constructor = propertyUtilsClass.getConstructor();
+ try {
+ return (IPropertyUtils)constructor.newInstance();
+ }
+ catch (Exception e) {
+ // Impossible: Constructor should not be failing.
+ throw new AssertionError(e);
+ }
+ } catch (ClassNotFoundException e) {
+ // OK: On a platform where java beans are not supported
+ return new PropertyUtilsMock();
+ } catch (NoSuchMethodException e) {
+ // Impossible. PropertyUtils should have a 0-arg constructor.
+ throw new AssertionError(e);
+ }
+ }
+
+ private PropertyUtilsFactory() {}
+}
diff --git a/src/main/java/org/testng/internal/PropertyUtilsMock.java b/src/main/java/org/testng/internal/PropertyUtilsMock.java
new file mode 100755
index 00000000..93331776
--- /dev/null
+++ b/src/main/java/org/testng/internal/PropertyUtilsMock.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package org.testng.internal;
+
+/**
+ * Utility class for setting JavaBeans-style properties on instances.
+ *
+ * <p>Mock version for platforms that don't support java beans</p>.
+ */
+public class PropertyUtilsMock implements IPropertyUtils {
+ public void setProperty(Object instance, String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class getPropertyType(Class instanceClass, String propertyName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setPropertyRealValue(Object instance, String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
+}