[givwenzen_user] Support for varargs in beta10

26 views
Skip to first unread message

Robert

unread,
Apr 22, 2010, 1:19:00 PM4/22/10
to givwenzen_user
I'm a bit confused with the new varargs feature. Issue 13 (http://
code.google.com/p/givwenzen/issues/detail?id=13) posted the following
example

Example:

Given: a route through points: FOO, BAR, BAZ

@DomainStep("a route through points: (.*)")
public void foo(String ... points) {

What's the meaning behind the syntax String... (the additional dots)?
Please provide a complete example - one that includes what the
FitNesse page will look like (Given, When and Then), as well as what
the underlying Java code will look like?

Other than the additional dot syntax, is there anything else that
needs to be implemented to get this to work?

Regards,
Robert


--
Subscription settings: http://groups.google.com/group/givwenzen_user/subscribe?hl=en

szczepiq

unread,
Apr 22, 2010, 3:09:20 PM4/22/10
to givwenz...@googlegroups.com
Additional dots are ordinary java 1.5> varargs. This should work as well:


@DomainStep("a route through points: (.*)")
public void foo(String[] points) {

...because varargs are implemented via arrays.

Hope that helps,
Cheers
Szczepan

Williams, Wesley

unread,
Apr 22, 2010, 9:27:43 PM4/22/10
to givwenz...@googlegroups.com

there is a test of this functionality in the SlimExamples checked in and in the full zip,  Here is an example given step and a link to the fitnesse page:

 

given: a var arg method of !-TestObjects-! o1,o2,o3

 

note: !- and -! are just for fitnesse not to turn a wiki word into a link

 

http://code.google.com/p/givwenzen/source/browse/trunk/FitNesseRoot/SlimExamples/ObjectVarArgsExample/content.txt

 

The method for the given step ‘given: a var arg method of TestObjects o1, o2, o3’ could be handled with the method below.


   @DomainStep("a var arg method of TestObjects (.*)")

   public void objectArrayParameterMethod(ExampleObject... objects) {

      this.objects = objects;

   }

 

instead of the … as Szczepan noted, the parameter could be an array of ExampleObject as well.

 

http://code.google.com/p/givwenzen/source/browse/trunk/src/examples/java/bdd/steps/ExampleSteps.java

 

This method is a bit more detailed as it does not use a string array but an object array so it requires a property editor for the object like the one here:

 

http://code.google.com/p/givwenzen/source/browse/trunk/src/examples/java/bdd/steps/ExampleObjectEditor.java

 

hope this helps.

 

-wes

Robert

unread,
Apr 25, 2010, 1:36:49 PM4/25/10
to givwenzen_user
Wes,

Thanks for the detailed information. It certainly has helped in
understanding this new feature. Our QA Team is currently using
FitNesse (predominantly, ColumnFixtures) with Selenium (using the page
object pattern) to test some of our internal facing web applications.
After further research, I do have some additional questions that
relate to the ExampleObjectEditor example you referred to earlier

1. What is a PropertyEditorSupport class all about?
2. When would extending from the PropertyEditorSupport class be
required?
3. Once the PropertyEditorSupport class has been extended, are there
any other methods to override (i.e., beyond the setAsText method)?
3. In what sort of situations would this pattern prove useful?

Apologies for the additional questions - it's just that we don't have
a whole lot of development background over here. I guess I'm trying
to get more context around the example you provided within the
givwenzen distribution.

Regards,
Robert

On Apr 22, 6:27 pm, "Williams, Wesley" <Wesley.Willi...@sabre.com>
wrote:
> there is a test of this functionality in the SlimExamples checked in and
> in the full zip,  Here is an example given step and a link to the
> fitnesse page:
>
> given: a var arg method of !-TestObjects-! o1,o2,o3
>
> note: !- and -! are just for fitnesse not to turn a wiki word into a
> link
>
> http://code.google.com/p/givwenzen/source/browse/trunk/FitNesseRoot/Slim
> Examples/ObjectVarArgsExample/content.txt
>
> The method for the given step 'given: a var arg method of TestObjects
> o1, o2, o3' could be handled with the method below.
>
>    @DomainStep("a var arg method of TestObjects (.*)")
>
>    public void objectArrayParameterMethod(ExampleObject... objects) {
>
>       this.objects = objects;
>
>    }
>
> instead of the ... as Szczepan noted, the parameter could be an array of
> ExampleObject as well.
>
> http://code.google.com/p/givwenzen/source/browse/trunk/src/examples/j...
>
> This method is a bit more detailed as it does not use a string array but
> an object array so it requires a property editor for the object like the
> one here:
>
> http://code.google.com/p/givwenzen/source/browse/trunk/src/examples/j...
>
> hope this helps.
>
> -wes
>
> From: givwenz...@googlegroups.com
> [mailto:givwenz...@googlegroups.com] On Behalf Of szczepiq
> Sent: Friday, April 23, 2010 03:09
> To: givwenz...@googlegroups.com
> Subject: Re: [givwenzen_user] Support for varargs in beta10
>
> Additional dots are ordinary java 1.5> varargs. This should work as
> well:
>
> @DomainStep("a route through points: (.*)")
> public void foo(String[] points) {
>
> ...because varargs are implemented via arrays.
>
> Hope that helps,
> Cheers
> Szczepan
>

Williams, Wesley

unread,
Apr 25, 2010, 9:32:27 PM4/25/10
to givwenz...@googlegroups.com
1) PropertyEditor and PropertyEditorSupport - This is Java's mechanism for converting from Object to String and String to Object. http://java.sun.com/javase/6/docs/api/java/beans/PropertyEditor.html PropertyEditorSupport is a support class to make creating property editors simpler.

2) You would create a class that extends from PropertyEditorSupport when you want a method parameter that is not a string or native type (int, float, etc.). The class extending PropertyEditorSuport would be used to convert the string captured by the regular expression into an Object of the correct type. The class extending PropertyEditorSuport can be put into the bdd.parse package or into the same package as the Class type it support converting between string and object for. There are a couple of examples in the GivWenZen source, http://code.google.com/p/givwenzen/source/browse/trunk/src/test/java/bdd/parse/TestCustomObjectParser.java.

3) For GivWenZen you only need override the setAsText because we never need to go from Object to String.

4) Many different frameworks use PropertyEditor to go both directions. A GUI would be a good place for both directions, String to Object and Object to String to represent an object to the user. There are many frameworks that use this especially frameworks that deal with JavaBeans.

hope this helps.

wes

Robert

unread,
Apr 25, 2010, 10:02:19 PM4/25/10
to givwenzen_user
Wes,

Fantastic!! Thanks for the detailed response.

Regards,
Robert

On Apr 25, 6:32 pm, "Williams, Wesley" <Wesley.Willi...@sabre.com>
wrote:
> 1) PropertyEditor and PropertyEditorSupport - This is Java's mechanism for converting from Object to String and String to Object.  http://java.sun.com/javase/6/docs/api/java/beans/PropertyEditor.html PropertyEditorSupport is a support class to make creating property editors simpler.
>
> 2) You would create a class that extends from PropertyEditorSupport when you want a method parameter that is not a string or native type (int, float, etc.).  The class extending PropertyEditorSuport would be used to convert the string captured by the regular expression into an Object of the correct type.  The class extending PropertyEditorSuport can be put into the bdd.parse package or into the same package as the Class type it support converting between string and object for.  There are a couple of examples in the GivWenZen source,http://code.google.com/p/givwenzen/source/browse/trunk/src/test/java/....
Reply all
Reply to author
Forward
0 new messages