You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by "Ralph Jocham (JIRA)" <ji...@apache.org> on 2008/05/10 01:07:55 UTC

[jira] Created: (SHINDIG-262) Added Tests for BidiSubstituter

Added Tests for BidiSubstituter
-------------------------------

                 Key: SHINDIG-262
                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
             Project: Shindig
          Issue Type: Improvement
          Components: Common Components (Java)
         Environment: Place in test folder in org.apache.shindig.gadgets package
            Reporter: Ralph Jocham


/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.apache.shindig.gadgets;

import junit.framework.TestCase;

public class BidiSubstituterTest extends TestCase {

  private static final String REVERSE_DIR = "REVERSE_DIR";
  private static final String START_EDGE = "START_EDGE";
  private static final String END_EDGE = "END_EDGE";
  private static final String DIR = "DIR";
  private static final String LTR = "ltr";
  private static final String RIGHT = "right";
  private static final String LEFT = "left";
  private static final String RTL = "rtl";

  private Substitutions substitions;

  @Override
  public void setUp() {
    substitions = new Substitutions();
  }

  public void testBidiWithRtl() {
    BidiSubstituter.addSubstitutions(substitions, RTL);

    assertSubstitutions(substitions,
                        new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
                                        {LEFT, END_EDGE}, {RTL, DIR}});
  }

  public void testBidiWithLtr() {
    BidiSubstituter.addSubstitutions(substitions, LTR);

    assertSubstitutions(substitions,
                        new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
                                        {RIGHT, END_EDGE}, {LTR, DIR}});
  }

  public void testBidiWithEmpty() {
    BidiSubstituter.addSubstitutions(substitions, "");

    assertSubstitutions(substitions,
                        new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
                                        {LEFT, END_EDGE}, {RTL, DIR}});
  }

  public void testBidiWithNull() {
    BidiSubstituter.addSubstitutions(substitions, null);

    assertSubstitutions(substitions,
                        new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
                                        {LEFT, END_EDGE}, {RTL, DIR}});
  }

  private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
    for (String[] mapping : mappings) {
      assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
    }
  }
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SHINDIG-262) Added Tests for BidiSubstituter

Posted by "Ralph Jocham (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SHINDIG-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597981#action_12597981 ] 

Ralph Jocham commented on SHINDIG-262:
--------------------------------------

Cassie,
thanks for the in depth explanation. I was not aware of most and will adhere to them from now on.

/ralph

> Added Tests for BidiSubstituter
> -------------------------------
>
>                 Key: SHINDIG-262
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
>             Project: Shindig
>          Issue Type: Improvement
>          Components: Common Components (Java)
>         Environment: Place in test folder in org.apache.shindig.gadgets package
>            Reporter: Ralph Jocham
>            Assignee: Cassie Doll
>         Attachments: bidi-substituter-test.patch
>
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements. See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership. The ASF licenses this file
>  * to you 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.apache.shindig.gadgets;
> import junit.framework.TestCase;
> public class BidiSubstituterTest extends TestCase {
>   private static final String REVERSE_DIR = "REVERSE_DIR";
>   private static final String START_EDGE = "START_EDGE";
>   private static final String END_EDGE = "END_EDGE";
>   private static final String DIR = "DIR";
>   private static final String LTR = "ltr";
>   private static final String RIGHT = "right";
>   private static final String LEFT = "left";
>   private static final String RTL = "rtl";
>   private Substitutions substitions;
>   @Override
>   public void setUp() {
>     substitions = new Substitutions();
>   }
>   public void testBidiWithRtl() {
>     BidiSubstituter.addSubstitutions(substitions, RTL);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithLtr() {
>     BidiSubstituter.addSubstitutions(substitions, LTR);
>     assertSubstitutions(substitions,
>                         new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
>                                         {RIGHT, END_EDGE}, {LTR, DIR}});
>   }
>   public void testBidiWithEmpty() {
>     BidiSubstituter.addSubstitutions(substitions, "");
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithNull() {
>     BidiSubstituter.addSubstitutions(substitions, null);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
>     for (String[] mapping : mappings) {
>       assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
>     }
>   }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (SHINDIG-262) Added Tests for BidiSubstituter

Posted by "Cassie Doll (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SHINDIG-262?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cassie Doll resolved SHINDIG-262.
---------------------------------

    Resolution: Fixed
      Assignee: Cassie Doll

> Added Tests for BidiSubstituter
> -------------------------------
>
>                 Key: SHINDIG-262
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
>             Project: Shindig
>          Issue Type: Improvement
>          Components: Common Components (Java)
>         Environment: Place in test folder in org.apache.shindig.gadgets package
>            Reporter: Ralph Jocham
>            Assignee: Cassie Doll
>         Attachments: bidi-substituter-test.patch
>
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements. See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership. The ASF licenses this file
>  * to you 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.apache.shindig.gadgets;
> import junit.framework.TestCase;
> public class BidiSubstituterTest extends TestCase {
>   private static final String REVERSE_DIR = "REVERSE_DIR";
>   private static final String START_EDGE = "START_EDGE";
>   private static final String END_EDGE = "END_EDGE";
>   private static final String DIR = "DIR";
>   private static final String LTR = "ltr";
>   private static final String RIGHT = "right";
>   private static final String LEFT = "left";
>   private static final String RTL = "rtl";
>   private Substitutions substitions;
>   @Override
>   public void setUp() {
>     substitions = new Substitutions();
>   }
>   public void testBidiWithRtl() {
>     BidiSubstituter.addSubstitutions(substitions, RTL);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithLtr() {
>     BidiSubstituter.addSubstitutions(substitions, LTR);
>     assertSubstitutions(substitions,
>                         new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
>                                         {RIGHT, END_EDGE}, {LTR, DIR}});
>   }
>   public void testBidiWithEmpty() {
>     BidiSubstituter.addSubstitutions(substitions, "");
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithNull() {
>     BidiSubstituter.addSubstitutions(substitions, null);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
>     for (String[] mapping : mappings) {
>       assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
>     }
>   }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SHINDIG-262) Added Tests for BidiSubstituter

Posted by "Cassie Doll (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SHINDIG-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12596366#action_12596366 ] 

Cassie Doll commented on SHINDIG-262:
-------------------------------------

Ralph - this jira issue should really have that code attached in a patch (instead of pasted inline). As you have already written everything, this is fairly easy to do. 
You can just follow the instructions here: http://incubator.apache.org/shindig/#creatingPatches

Thanks!

> Added Tests for BidiSubstituter
> -------------------------------
>
>                 Key: SHINDIG-262
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
>             Project: Shindig
>          Issue Type: Improvement
>          Components: Common Components (Java)
>         Environment: Place in test folder in org.apache.shindig.gadgets package
>            Reporter: Ralph Jocham
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements. See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership. The ASF licenses this file
>  * to you 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.apache.shindig.gadgets;
> import junit.framework.TestCase;
> public class BidiSubstituterTest extends TestCase {
>   private static final String REVERSE_DIR = "REVERSE_DIR";
>   private static final String START_EDGE = "START_EDGE";
>   private static final String END_EDGE = "END_EDGE";
>   private static final String DIR = "DIR";
>   private static final String LTR = "ltr";
>   private static final String RIGHT = "right";
>   private static final String LEFT = "left";
>   private static final String RTL = "rtl";
>   private Substitutions substitions;
>   @Override
>   public void setUp() {
>     substitions = new Substitutions();
>   }
>   public void testBidiWithRtl() {
>     BidiSubstituter.addSubstitutions(substitions, RTL);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithLtr() {
>     BidiSubstituter.addSubstitutions(substitions, LTR);
>     assertSubstitutions(substitions,
>                         new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
>                                         {RIGHT, END_EDGE}, {LTR, DIR}});
>   }
>   public void testBidiWithEmpty() {
>     BidiSubstituter.addSubstitutions(substitions, "");
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithNull() {
>     BidiSubstituter.addSubstitutions(substitions, null);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
>     for (String[] mapping : mappings) {
>       assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
>     }
>   }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SHINDIG-262) Added Tests for BidiSubstituter

Posted by "Cassie Doll (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SHINDIG-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12596424#action_12596424 ] 

Cassie Doll commented on SHINDIG-262:
-------------------------------------

thanks for the patch!
there were several things i had to fix or change in your patch

style issues:
- watch your indents. line continuations should be indented by 4 spaces
- all lines must be less than 80 chars
- you had some double spaces between some vars like {RIGHT,<space><space> START_EDGE} which should be just single spaces
- the substitution field had a spelling typo

code changes:
- i noticed the addSubstitutions line was being repeated so i moved that into the helper method
- i changed from using a String[][] which seemed easy to mix up to using 4 String variables with two more helper vars. this makes the tests a little easier to read.
- your last two tests were failing (w/null and empty string) because the default behavior is ltr not rtl
- you forgot super.setUp() in your overridden method, but i inlined the var away anyway


now that you are aware of some of our code practices i'm sure there will be less revisions to a patch next time.
thanks again for your help!

- cassie

> Added Tests for BidiSubstituter
> -------------------------------
>
>                 Key: SHINDIG-262
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
>             Project: Shindig
>          Issue Type: Improvement
>          Components: Common Components (Java)
>         Environment: Place in test folder in org.apache.shindig.gadgets package
>            Reporter: Ralph Jocham
>         Attachments: bidi-substituter-test.patch
>
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements. See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership. The ASF licenses this file
>  * to you 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.apache.shindig.gadgets;
> import junit.framework.TestCase;
> public class BidiSubstituterTest extends TestCase {
>   private static final String REVERSE_DIR = "REVERSE_DIR";
>   private static final String START_EDGE = "START_EDGE";
>   private static final String END_EDGE = "END_EDGE";
>   private static final String DIR = "DIR";
>   private static final String LTR = "ltr";
>   private static final String RIGHT = "right";
>   private static final String LEFT = "left";
>   private static final String RTL = "rtl";
>   private Substitutions substitions;
>   @Override
>   public void setUp() {
>     substitions = new Substitutions();
>   }
>   public void testBidiWithRtl() {
>     BidiSubstituter.addSubstitutions(substitions, RTL);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithLtr() {
>     BidiSubstituter.addSubstitutions(substitions, LTR);
>     assertSubstitutions(substitions,
>                         new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
>                                         {RIGHT, END_EDGE}, {LTR, DIR}});
>   }
>   public void testBidiWithEmpty() {
>     BidiSubstituter.addSubstitutions(substitions, "");
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithNull() {
>     BidiSubstituter.addSubstitutions(substitions, null);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
>     for (String[] mapping : mappings) {
>       assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
>     }
>   }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SHINDIG-262) Added Tests for BidiSubstituter

Posted by "Ralph Jocham (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SHINDIG-262?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Jocham updated SHINDIG-262:
---------------------------------

    Attachment: bidi-substituter-test.patch

Diff of shown source code for newly added tests

> Added Tests for BidiSubstituter
> -------------------------------
>
>                 Key: SHINDIG-262
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-262
>             Project: Shindig
>          Issue Type: Improvement
>          Components: Common Components (Java)
>         Environment: Place in test folder in org.apache.shindig.gadgets package
>            Reporter: Ralph Jocham
>         Attachments: bidi-substituter-test.patch
>
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements. See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership. The ASF licenses this file
>  * to you 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.apache.shindig.gadgets;
> import junit.framework.TestCase;
> public class BidiSubstituterTest extends TestCase {
>   private static final String REVERSE_DIR = "REVERSE_DIR";
>   private static final String START_EDGE = "START_EDGE";
>   private static final String END_EDGE = "END_EDGE";
>   private static final String DIR = "DIR";
>   private static final String LTR = "ltr";
>   private static final String RIGHT = "right";
>   private static final String LEFT = "left";
>   private static final String RTL = "rtl";
>   private Substitutions substitions;
>   @Override
>   public void setUp() {
>     substitions = new Substitutions();
>   }
>   public void testBidiWithRtl() {
>     BidiSubstituter.addSubstitutions(substitions, RTL);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithLtr() {
>     BidiSubstituter.addSubstitutions(substitions, LTR);
>     assertSubstitutions(substitions,
>                         new String[][] {{RTL, REVERSE_DIR}, {LEFT,  START_EDGE},
>                                         {RIGHT, END_EDGE}, {LTR, DIR}});
>   }
>   public void testBidiWithEmpty() {
>     BidiSubstituter.addSubstitutions(substitions, "");
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   public void testBidiWithNull() {
>     BidiSubstituter.addSubstitutions(substitions, null);
>     assertSubstitutions(substitions,
>                         new String[][] {{LTR, REVERSE_DIR}, {RIGHT,  START_EDGE},
>                                         {LEFT, END_EDGE}, {RTL, DIR}});
>   }
>   private void assertSubstitutions(Substitutions substitutions, String[][] mappings) {
>     for (String[] mapping : mappings) {
>       assertEquals(mapping[0], substitutions.getSubstitution(Substitutions.Type.BIDI, mapping[1]));
>     }
>   }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.