Skip to content

Commit

Permalink
Unit test for verifying field values
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdcc committed Jul 31, 2014
1 parent e42b8e8 commit 5660e8c
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.jdev.geb.cucumber.core.util

import geb.content.SimplePageContent
import geb.navigator.Navigator
import io.jdev.geb.cucumber.core.CheckedDecoder
import org.openqa.selenium.WebElement
import spock.lang.Specification
import spock.lang.Unroll
Expand Down Expand Up @@ -135,4 +136,68 @@ class ValueUtilSpec extends Specification {
getValue(null) == null
}

void "hasValue gives correct values for simple string equality"() {
when:
hasValue('foo', 'foo')

then:
notThrown(Throwable)

when:
hasValue(1, '1')

then:
notThrown(Throwable)

when:
hasValue('foo', 'bar')

then:
thrown(AssertionError)
}

void "hasValue gives correct values for checkbox state matching"() {
given:
Navigator field = Mock(Navigator)

// field and expectation both checked
when:
hasValue(field, CheckedDecoder.CheckedState.checked)

then:
1 * field.value() >> 'not false'

and:
notThrown(Throwable)

// field and expectation both unchecked
when:
hasValue(field, CheckedDecoder.CheckedState.unchecked)

then:
1 * field.value() >> false

and:
notThrown(Throwable)

// field checked, expectation unchecked
when:
hasValue(field, CheckedDecoder.CheckedState.unchecked)

then:
1 * field.value() >> 'not false'

and:
thrown(AssertionError)

// field unchecked, expectation checked
when:
hasValue(field, CheckedDecoder.CheckedState.checked)

then:
1 * field.value() >> false

and:
thrown(AssertionError)
}
}

0 comments on commit 5660e8c

Please sign in to comment.