Skip to content

Testing for a blank value #310

Closed
raboof opened this Issue Aug 21, 2013 · 4 comments

4 participants

@raboof
raboof commented Aug 21, 2013

Both in decision, query and script tables, I think it would be useful to be able to easily test for blank values.

This has been sort of discussed before (#102, http://stackoverflow.com/questions/3178554/fitnesse-test-against-empty-string-result/3219946#3219946 ), and indeed such a keyword does not currently exist, but I think it'd be useful to have (without resorting to a regular expression).

@amolenaar
Collaborator

Maybe as a symbol type? Is that feasible?

@ggramlich
Collaborator

I bumped into this problem today, too. I would like to solve it by registering a custom String Converter in the ConverterRegistry which might convert null to "<null>" and vice versa. Unfortunately there is another issue that I just discovered. #337

@ggramlich
Collaborator

I provided a patch #338 for #337.
For Decision Tables and Script Tables, we now use something similar to

ConverterRegistry.addConverter(String.class, new NullStringConverter());

and

import fitnesse.slim.Converter;

public class NullStringConverter implements Converter<String> {

    private static final String NULL = "<null>";
    private static final String BLANK = "<blank>";

    @Override
    public String fromString(String inputString) {
        if (inputString == null || inputString.isEmpty() || BLANK.equals(inputString)) {
            return "";
        }
        if (NULL.equals(inputString)) {
            return null;
        }
        return inputString.trim();
    }

    @Override
    public String toString(String obj) {
        if (obj == null) {
            return NULL;
        }
        if ("".equals(obj)) {
            return BLANK;
        }
        return obj.trim();
    }
}

For query tables, we do the conversion "by hand".

@amolenaar amolenaar closed this Oct 3, 2013
@mgibas
mgibas commented Nov 20, 2013

Is it implemented already ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.