Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.util;

import junit.framework.*;

import org.litesoft.core.util.*;

public class HintControllerTest extends TestCase
{
    public static TestSuite suite()
    {
        return new TestSuite( HintControllerTest.class );
    }

    public HintControllerTest( String name )
    {
        super( name );
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    }

    private static final String ERROR = "Value Not 'Value'";
    private static final String PREFIXED_ERROR = HintController.PER_PROBLEM_PREFIX + ERROR;
    private static final String ERROR2 = "Value Not 'Value2'";
    private static final String PREFIXED_ERROR2 = HintController.PER_PROBLEM_PREFIX + ERROR2;

    public void test_validate()
            throws Exception
    {
        HintController.add( new MyHintValidator( "WildCards", null, null ) );

        assertEquals( "1a", PREFIXED_ERROR, HintController.validate( null, null, "WildCards", "BadValue" ) );
        assertNull( HintController.validate( null, null, "WildCards", "Value" ) );
        assertNull( HintController.validate( "Jose", null, "WildCards", "Value" ) );
        assertNull( HintController.validate( "Jose", "Testy", "WildCards", "Value" ) );

        assertEquals( "1b", "", HintController.validate( "Jose", "Testy", "Once", "Whatever" ) );
        assertNull( HintController.validate( "Jose", "Testy", "Once", "Whatever" ) );

        HintController.add( new MyHintValidator( "GroupWild", "GWs", null ) );

        assertEquals( "2a", PREFIXED_ERROR, HintController.validate( "GWs", null, "GroupWild", "BadValue" ) );
        assertNull( HintController.validate( "GWs", null, "GroupWild", "Value" ) );
        assertNull( HintController.validate( "GWs", "Testy", "GroupWild", "Value" ) );

        assertEquals( "2b", "", HintController.validate( null, null, "GroupWild", "Value" ) );
        // Wild cards NOT auto added
        assertEquals( "2c", "", HintController.validate( null, null, "GroupWild", "Value" ) );

        HintController.add( new MyHintValidator( "CatWild", null, "Cats" ) );

        assertEquals( "3a", PREFIXED_ERROR, HintController.validate( null, "Cats", "CatWild", "BadValue" ) );
        assertNull( HintController.validate( null, "Cats", "CatWild", "Value" ) );
        assertNull( HintController.validate( "Testy", "Cats", "CatWild", "Value" ) );

        assertEquals( "3b", "", HintController.validate( null, null, "CatWild", "Value" ) );
        // Wild cards NOT auto added
        assertEquals( "3c", "", HintController.validate( null, null, "CatWild", "Value" ) );

        HintController.add( new MyHintValidator( "CatGroup", "CG_Cat", "CG_Grp" ) );

        assertEquals( "4a", PREFIXED_ERROR, HintController.validate( "CG_Cat", "CG_Grp", "CatGroup", "BadValue" ) );
        assertNull( HintController.validate( "CG_Cat", "CG_Grp", "CatGroup", "Value" ) );

        assertEquals( "4b", "", HintController.validate( null, null, "CatGroup", "Value" ) );
        // Wild cards NOT auto added
        assertEquals( "4c", "", HintController.validate( null, null, "CatGroup", "Value" ) );

        HintController.add( new MyHintValidator( "T2", null, null ) );
        HintController.add( new My2ndHintValidator( "T2", "Cat", "Group" ) );

        assertNull( HintController.validate( null, null, "T2", "Value" ) );
        assertNull( HintController.validate( null, "Group", "T2", "Value" ) );
        assertNull( HintController.validate( "Cat", null, "T2", "Value" ) );
        assertNull( HintController.validate( "Cat", "Group", "T2", "Value" ) );
        assertNull( HintController.validate( "Jose", null, "T2", "Value" ) );
        assertNull( HintController.validate( "Jose", "Testy", "T2", "Value" ) );

        assertEquals( "5a", PREFIXED_ERROR, HintController.validate( null, null, "T2", "Value2" ) );
        assertEquals( "5b", PREFIXED_ERROR, HintController.validate( null, "Group", "T2", "Value2" ) );
        assertEquals( "5c", PREFIXED_ERROR, HintController.validate( "Cat", null, "T2", "Value2" ) );
        assertNull( HintController.validate( "Cat", "Group", "T2", "Value2" ) );
        assertEquals( "5e", PREFIXED_ERROR, HintController.validate( "Jose", null, "T2", "Value2" ) );
        assertEquals( "5f", PREFIXED_ERROR, HintController.validate( "Jose", "Testy", "T2", "Value2" ) );
        assertEquals( "5g", PREFIXED_ERROR + PREFIXED_ERROR2, //
                      HintController.validate( "Cat", "Group", "T2", "Value3" ) );
    }

    public void assertNull( String pProblem )
    {
        if ( pProblem != null )
        {
            fail( "Expected Null, but got: " + pProblem );
        }
    }

    private static class MyHintValidator implements HintValidator
    {
        private String[] mNames;
        private CategoryGroup[] mCGs;

        public MyHintValidator( String[] pNames, String... pCatGroupPairs )
        {
            mNames = pNames;
            mCGs = new CategoryGroup[pCatGroupPairs.length / 2];
            int zCGndx = 0;
            int zPairndx = 0;
            do
            {
                mCGs[zCGndx++] = new CategoryGroup( pCatGroupPairs[zPairndx], pCatGroupPairs[zPairndx + 1] );
            }
            while ( (zPairndx += 2) < pCatGroupPairs.length );
        }

        public MyHintValidator( String pName, String... pCatGroupPairs )
        {
            this( new String[]{pName}, pCatGroupPairs );
        }

        public CategoryGroup[] getRegisterForCategoryGroups()
        {
            return mCGs;
        }

        public String[] getRegisterForHintNames()
        {
            return mNames;
        }

        public String validate( String pName, String pValue )
        {
            return "Value".equals( pValue ) ? null : ERROR;
        }
    }

    private static class My2ndHintValidator extends MyHintValidator
    {
        public My2ndHintValidator( String pName, String... pCatGroupPairs )
        {
            super( pName, pCatGroupPairs );
        }

        public String validate( String pName, String pValue )
        {
            return "Value2".equals( pValue ) ? null : ERROR2;
        }
    }
}

Commits for litesoft/trunk/Java/core/jvm1.5/src/org/litesoft/util/HintControllerTest.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000