Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gunther-bachmann committed May 30, 2018
1 parent 5e4b895 commit 6582a2a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.math.BigDecimal
import java.util.Optional
import java.util.regex.Pattern
import javax.inject.Singleton
import org.eclipse.xtext.xbase.lib.Functions.Function1
import org.junit.Assert
import org.junit.ComparisonFailure

Expand Down Expand Up @@ -375,6 +376,22 @@ class AssertionHelper {
condition.assertTrue(null)
}

def <T> void assertExists(Iterable<T> collection, Function1<T, Boolean> predicate, String message) {
collection.exists(predicate).assertTrue(message)
}

def <T> void assertExists(Iterable<T> collection, Function1<T, Boolean> predicate) {
assertExists(collection, predicate, "Predicate not matching on any of the given.")
}

def <T> void assertNotExists(Iterable<T> collection, Function1<T, Boolean> predicate, String message) {
collection.exists(predicate).assertFalse(message)
}

def <T> void assertNotExists(Iterable<T> collection, Function1<T, Boolean> predicate) {
assertNotExists(collection, predicate, "Found unexpected matching for predicate.")
}

/** Calls {@link Assert#assertFalse(String, boolean)} */
def void assertFalse(boolean condition, String message) {
Assert.assertFalse(message, condition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TclMissingFixtureValidatorTest extends AbstractMockedTclValidatorTest {
// then
messageAcceptor.verify.acceptInfo(message.capture, anyObject, anyObject, anyInt, anyString)
assertMatches(message.value, ".*does not provide additional information on failures.*")
assertMatches(message.value, ".*FixtureException.*")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ package org.testeditor.tcl.dsl.validation
import javax.inject.Inject
import org.eclipse.xtext.diagnostics.Severity
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.eclipse.xtext.validation.Issue
import org.eclipse.xtext.xbase.lib.Functions.Function1
import org.junit.Test
import org.testeditor.tcl.TclModel
import org.testeditor.tcl.dsl.tests.parser.AbstractParserTest

class TclValidatorTest extends AbstractParserTest {
Expand All @@ -26,85 +29,81 @@ class TclValidatorTest extends AbstractParserTest {
@Test
def void validateStringArray() {
// given
val aml = getAMLWithValueSpace('''#[ "New", "Open" ]''')
var tcl = getTCLWithValue("Test", "New")
val Function1<Issue, Boolean> warningPredicate = [
message.matches(".*Allowed values: '\\[New, Open\\]'.*") && severity == Severity.WARNING
]
getAMLWithValueSpace('''#[ "New", "Open" ]''').parseAml

parseAml(aml)
var tclError = getTCLWithValue("Test2", "Save")
var tcl = getTCLWithValue("Test", "New")
var tclExpectingWarning = getTCLWithValue("Test2", "Save")

// when
var model = parseTcl(tcl.toString, "Test.tcl")
var modelError = parseTcl(tclError.toString, "Test2.tcl")
var modelExpectingWarning = parseTcl(tclExpectingWarning.toString, "Test2.tcl")

// then
validator.validate(model).assertSingleElement => [
code.assertEquals(TclValidator.FIXTURE_MISSING_EXCEPTION)
severity.assertEquals(Severity.INFO)
]
assertFalse(validator.validate(modelError).isEmpty)
validator.validate(model).assertNotExists(warningPredicate, model.reportableValidations)
validator.validate(modelExpectingWarning).assertExists(warningPredicate, modelExpectingWarning.reportableValidations)
}

@Test
def void validateNumberRange() {
// given
val aml = getAMLWithValueSpace("2 ... 5")
var tcl = getTCLWithValue("Test", "4")
val Function1<Issue, Boolean> warningPredicate = [
message.matches(".*Allowed values: '2 <= x <= 5'.*") && severity == Severity.WARNING
]
getAMLWithValueSpace("2 ... 5").parseAml

parseAml(aml)
var tclError = getTCLWithValue("Test2", "1")
var tcl = getTCLWithValue("Test", "4")
var tclExpectingWarning = getTCLWithValue("Test2", "1")

// when
var model = parseTcl(tcl.toString, "Test.tcl")
var modelError = parseTcl(tclError.toString, "Test2.tcl")
var modelExpectingWarning = parseTcl(tclExpectingWarning.toString, "Test2.tcl")

// then
validator.validate(model).assertSingleElement => [
code.assertEquals(TclValidator.FIXTURE_MISSING_EXCEPTION)
severity.assertEquals(Severity.INFO)
]
assertFalse(validator.validate(modelError).isEmpty)
validator.validate(model).assertNotExists(warningPredicate, model.reportableValidations)
validator.validate(modelExpectingWarning).assertExists(warningPredicate, modelExpectingWarning.reportableValidations)
}

@Test
def void validateRegEx() {
// given
val aml = getAMLWithValueSpace('''"^[a-zA-Z_0-9]"''')
var tcl = getTCLWithValue("Test", "h")
val Function1<Issue, Boolean> warningPredicate = [
message.matches(".*Allowed values: 'Regular expression: \\^\\[a-zA-Z_0-9\\]'.*") && severity == Severity.WARNING
]
getAMLWithValueSpace('''"^[a-zA-Z_0-9]"''').parseAml

parseAml(aml)
var tclError = getTCLWithValue("Test2", "!!hello")
var tcl = getTCLWithValue("Test", "h")
var tclExpectingWarning = getTCLWithValue("Test2", "!!hello")

// when
var model = parseTcl(tcl.toString, "Test.tcl")
var modelError = parseTcl(tclError.toString, "Test2.tcl")
var modelExpectingWarning = parseTcl(tclExpectingWarning.toString, "Test2.tcl")

// then
validator.validate(model).assertSingleElement => [
code.assertEquals(TclValidator.FIXTURE_MISSING_EXCEPTION)
severity.assertEquals(Severity.INFO)
]
assertFalse(validator.validate(modelError).isEmpty)
validator.validate(model).assertNotExists(warningPredicate, model.reportableValidations)
validator.validate(modelExpectingWarning).assertExists(warningPredicate, modelExpectingWarning.reportableValidations)
}

@Test
def void testValidateFieldsWithManyValueSpaces() {
// given
val aml = getAMLWithValueSpace('''#["foo", "bar"]''')
var tcl = getTCLWithTwoValueSpaces("Test", "foo", "Mask")
parseAml(aml)
val Function1<Issue, Boolean> warningPredicate = [
message.matches(".*Allowed values: '\\[foo, bar\\]'.*") && severity == Severity.WARNING
]
getAMLWithValueSpace('''#["foo", "bar"]''').parseAml

var tclError = getTCLWithTwoValueSpaces("Test2", "fooHello", "Mask")
var tcl = getTCLWithTwoValueSpaces("Test", "foo", "Mask")
var tclExpectingWarning = getTCLWithTwoValueSpaces("Test2", "fooHello", "Mask")

// when
var model = parseTcl(tcl.toString, "Test.tcl")
var modelError = parseTcl(tclError.toString, "Test2.tcl")
var modelExpectingWarning = parseTcl(tclExpectingWarning.toString, "Test2.tcl")

// then
validator.validate(model).assertSize(2).forEach [
code.assertEquals(TclValidator.FIXTURE_MISSING_EXCEPTION)
severity.assertEquals(Severity.INFO)
]
assertFalse(validator.validate(modelError).isEmpty)
validator.validate(model).assertNotExists(warningPredicate, model.reportableValidations)
validator.validate(modelExpectingWarning).assertExists(warningPredicate, modelExpectingWarning.reportableValidations)
}

def getTCLWithTwoValueSpaces(String testName, String value1, String value2) {
Expand All @@ -131,7 +130,7 @@ class TclValidatorTest extends AbstractParserTest {
interaction type executeContextMenuEntry {
label = " execute context menu entry"
template = "execute menu item " ${item} " in tree" ${element}
method = SWTFixture.executeContextMenuEntry(element,item)
method = AnyFixture.executeContextMenuEntry(element,item)
}
element type TreeView {
Expand Down Expand Up @@ -160,4 +159,8 @@ class TclValidatorTest extends AbstractParserTest {
'''
}

private def String reportableValidations(TclModel model) {
return '''got: «validator.validate(model).map[toString].join('\n''''
}

}

0 comments on commit 6582a2a

Please sign in to comment.