java - String condition check failing for test -


i have method validate grouper string:

public string validategrouper(string grouper)     {         if(grouper!=null)             grouper = grouper.trim();         if(grouper==null || grouper.equals("") || !grouper.equalsignorecase("and") || !grouper.equalsignorecase("or"))         {             system.out.println("trap grouper validation triggered grouper: "+grouper);             grouper="and";         }         else             grouper = grouper.touppercase();         return grouper;     } 

i running against test:

@test public void testvalidategrouper(){     dbutils dbutils = new dbutils();     assertequals("expect empty string replaced and","and",dbutils.validategrouper(""));     assertequals("expect spaced out string replaced and","and",dbutils.validategrouper("   "));     assertequals("expect lower case , used and","and",dbutils.validategrouper("and"));     assertequals("expect upper case , used and","and",dbutils.validategrouper("and"));     assertequals("expect word cart ignored , replaced and","and",dbutils.validategrouper("cart"));     assertequals("expect , used grouper if no grouper provided","and",dbutils.validategrouper(null));     assertequals("expect lower case or used or","or",dbutils.validategrouper("or"));     assertequals("expect upper case or used or","or",dbutils.validategrouper("or")); } 

i find condition triggered despite using and , or. not understand why condition failing.

if either , or or allowed, need

if(grouper==null || !(grouper.equalsignorecase("and") || grouper.equalsignorecase("or"))) 

otherwise, if grouper "or", it's not equal "and" , condition true, , if grouper "and", it's not equal "or" , condition true.

also, can remove grouper.equals("") check.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -