-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support params in Factory in ITestResult
Closes #1041
- Loading branch information
1 parent
b543b4f
commit 43f3104
Showing
18 changed files
with
280 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.testng.internal; | ||
|
||
/** | ||
* Represents the ability to retrieve the parameters associated with a factory method. | ||
*/ | ||
public interface IParameterInfo { | ||
|
||
/** | ||
* @return - The actual instance associated with a factory method | ||
*/ | ||
Object getInstance(); | ||
|
||
/** | ||
* @return - The parameters associated with the factory method as an array. | ||
*/ | ||
Object[] getParameters(); | ||
|
||
static Object embeddedInstance(Object original) { | ||
if (original instanceof IParameterInfo) { | ||
return ((IParameterInfo) original).getInstance(); | ||
} | ||
return original; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.testng.internal; | ||
|
||
public class ParameterInfo implements IParameterInfo { | ||
private Object instance; | ||
private Object[] parameters; | ||
|
||
public ParameterInfo(Object instance, Object[] parameters) { | ||
this.instance = instance; | ||
this.parameters = parameters; | ||
} | ||
|
||
@Override | ||
public Object getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public Object[] getParameters() { | ||
return parameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/test/factory/issue1041/FactoryAnnotatedConstructorExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package test.factory.issue1041; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
import org.testng.collections.Lists; | ||
|
||
public class FactoryAnnotatedConstructorExample { | ||
static List<FactoryAnnotatedConstructorExample> objects = Lists.newArrayList(); | ||
|
||
private int data; | ||
|
||
@Factory(dataProvider = "dp") | ||
public FactoryAnnotatedConstructorExample(int data) { | ||
this.data = data; | ||
addInstance(this); | ||
} | ||
|
||
private static void addInstance(FactoryAnnotatedConstructorExample instance) { | ||
objects.add(instance); | ||
} | ||
|
||
@DataProvider(name = "dp") | ||
public static Object[][] getData() { | ||
return new Object[][]{ | ||
{1}, | ||
{2} | ||
}; | ||
} | ||
|
||
@Test | ||
public void testMethod() { | ||
Assert.assertTrue(data > 0); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
FactoryAnnotatedConstructorExample that = (FactoryAnnotatedConstructorExample) o; | ||
return data == that.data; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(data); | ||
} | ||
} |
Oops, something went wrong.