Skip to content

Commit

Permalink
enhance the condition interface a bit to no longer need to cast in Ht…
Browse files Browse the repository at this point in the history
…mlUnit
  • Loading branch information
rbri committed Dec 24, 2018
1 parent fa37068 commit 43ffb67
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}


/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return null;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ enum ConditionType {
* @return the associated condition type
*/
ConditionType getConditionType();

/**
* @return the value
*/
public String getValue();

/**
* @return the local name
*/
public String getLocalName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ public IdCondition(final String value, final Locator locator) {
setLocator(locator);
}

/**
* {@inheritDoc}
*/
@Override
public ConditionType getConditionType() {
return ConditionType.ID_CONDITION;
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return null;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ public ConditionType getConditionType() {
return ConditionType.LANG_CONDITION;
}

/**
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return null;
}

/**
* @return the language
*/
public String getLang() {
@Override
public String getValue() {
return lang_;
}

Expand All @@ -54,7 +63,7 @@ public String toString() {
final StringBuilder result = new StringBuilder();
result.append(":lang(");

final String lang = getLang();
final String lang = getValue();
if (null != lang) {
result.append(lang);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class OneOfAttributeCondition extends AbstractLocatable implements Condit

/**
* Ctor.
* @param localName the local value
* @param localName the local name
* @param value the value
*/
public OneOfAttributeCondition(final String localName, final String value) {
Expand All @@ -42,15 +42,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return null;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public ConditionType getConditionType() {
}

/**
* @return the local name
* {@inheritDoc}
*/
@Override
public String getLocalName() {
return localName_;
}

/**
* @return the value
* {@inheritDoc}
*/
@Override
public String getValue() {
return value_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,27 @@ public void selectorLang() throws Exception {
Assert.assertEquals("html:lang(fr-ca) { }", rule.getCssText());
ElementSelector selector = (ElementSelector) ((CSSStyleRuleImpl) rule).getSelectors().get(0);
Assert.assertEquals(ConditionType.LANG_CONDITION, selector.getConditions().get(0).getConditionType());
Assert.assertEquals("fr-ca", ((LangCondition) selector.getConditions().get(0)).getLang());
Assert.assertEquals("fr-ca", ((LangCondition) selector.getConditions().get(0)).getValue());

rule = rules.getRules().get(1);
Assert.assertEquals("html:lang(de) { }", rule.getCssText());
selector = (ElementSelector) ((CSSStyleRuleImpl) rule).getSelectors().get(0);
Assert.assertEquals(ConditionType.LANG_CONDITION, selector.getConditions().get(0).getConditionType());
Assert.assertEquals("de", ((LangCondition) selector.getConditions().get(0)).getLang());
Assert.assertEquals("de", ((LangCondition) selector.getConditions().get(0)).getValue());

rule = rules.getRules().get(2);
Assert.assertEquals("*:lang(fr) > Q { }", rule.getCssText());
ChildSelector childSelector = (ChildSelector) ((CSSStyleRuleImpl) rule).getSelectors().get(0);
selector = (ElementSelector) childSelector.getAncestorSelector();
Assert.assertEquals(ConditionType.LANG_CONDITION, selector.getConditions().get(0).getConditionType());
Assert.assertEquals("fr", ((LangCondition) selector.getConditions().get(0)).getLang());
Assert.assertEquals("fr", ((LangCondition) selector.getConditions().get(0)).getValue());

rule = rules.getRules().get(3);
Assert.assertEquals("*:lang(de) > Q { }", rule.getCssText());
childSelector = (ChildSelector) ((CSSStyleRuleImpl) rule).getSelectors().get(0);
selector = (ElementSelector) childSelector.getAncestorSelector();
Assert.assertEquals(ConditionType.LANG_CONDITION, selector.getConditions().get(0).getConditionType());
Assert.assertEquals("de", ((LangCondition) selector.getConditions().get(0)).getLang());
Assert.assertEquals("de", ((LangCondition) selector.getConditions().get(0)).getValue());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class LangConditionTest {
public void withoutValue() throws Exception {
final LangCondition c = new LangCondition(null, null);
Assert.assertEquals(ConditionType.LANG_CONDITION, c.getConditionType());
Assert.assertNull(c.getLang());
Assert.assertNull(c.getValue());

Assert.assertEquals(":lang()", c.toString());
}
Expand All @@ -44,7 +44,7 @@ public void withoutValue() throws Exception {
public void emptyValue() throws Exception {
final LangCondition c = new LangCondition("", null);
Assert.assertEquals(ConditionType.LANG_CONDITION, c.getConditionType());
Assert.assertEquals("", c.getLang());
Assert.assertEquals("", c.getValue());

Assert.assertEquals(":lang()", c.toString());
}
Expand All @@ -56,7 +56,7 @@ public void emptyValue() throws Exception {
public void withValue() throws Exception {
final LangCondition c = new LangCondition("value", null);
Assert.assertEquals(ConditionType.LANG_CONDITION, c.getConditionType());
Assert.assertEquals("value", c.getLang());
Assert.assertEquals("value", c.getValue());

Assert.assertEquals(":lang(value)", c.toString());
}
Expand Down

0 comments on commit 43ffb67

Please sign in to comment.