Skip to content
Permalink
Browse files

Matchers as a separate class. Ddjt->WebTauCore. deprecate beGreater/L…

…ess (#449)

* Matchers as a separate class. Ddjt->WebTauCore. deprecate beGreater/Less

* review feedback
  • Loading branch information...
MykolaGolubyev committed Nov 6, 2019
1 parent 7ff4986 commit 72cd44246209a61d1f44e367b1414a47afafebbb
Showing with 405 additions and 280 deletions.
  1. +1 −1 ...u-browser/src/main/java/com/twosigma/webtau/browser/expectation/ElementValueCompareToHandler.java
  2. +1 −1 ...au-browser/src/main/java/com/twosigma/webtau/browser/expectation/PageElementCompareToHandler.java
  3. +1 −2 webtau-browser/src/test/groovy/com/twosigma/webtau/browser/page/PageUrlTest.groovy
  4. +1 −1 webtau-cli-groovy/src/test/groovy/com/twosigma/webtau/cli/CliGroovyTest.groovy
  5. +1 −1 webtau-cli/src/test/java/com/twosigma/webtau/cli/CliJavaTest.java
  6. +1 −4 ...oovy/com/twosigma/webtau/data/expectation/equality/handlers/GroovyNullCompareToHandlerTest.groovy
  7. +1 −1 webtau-core-groovy/src/test/groovy/com/twosigma/webtau/data/render/TableDataRenderTest.groovy
  8. +1 −1 webtau-core-groovy/src/test/groovy/com/twosigma/webtau/data/table/TableDataGroovyTest.groovy
  9. +1 −2 webtau-core-groovy/src/test/groovy/com/twosigma/webtau/groovy/ast/ShouldAstTransformationTest.groovy
  10. +269 −0 webtau-core/src/main/java/com/twosigma/webtau/Matchers.java
  11. +2 −80 webtau-core/src/main/java/com/twosigma/webtau/{Ddjt.java → WebTauCore.java}
  12. +3 −1 webtau-core/src/main/java/com/twosigma/webtau/data/table/autogen/TableDataCellValueGenFunctions.java
  13. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/data/table/comparison/TableDataComparison.java
  14. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/expectation/ActualValue.java
  15. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/expectation/code/ThrowExceptionMatcher.java
  16. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/reporter/ValueMatcherExpectationSteps.java
  17. +1 −1 webtau-core/src/test/groovy/com/twosigma/webtau/data/table/RecordTest.groovy
  18. +1 −2 webtau-core/src/test/groovy/com/twosigma/webtau/expectation/ActualValueTest.groovy
  19. +1 −2 ...-core/src/test/groovy/com/twosigma/webtau/expectation/code/ThrowExceptionMatcherGroovyTest.groovy
  20. +1 −4 webtau-core/src/test/groovy/com/twosigma/webtau/expectation/contain/ContainMatcherTest.groovy
  21. +1 −5 ...rc/test/groovy/com/twosigma/webtau/expectation/contain/handlers/IterableContainHandlerTest.groovy
  22. +1 −1 .../src/test/groovy/com/twosigma/webtau/expectation/contain/handlers/StringContainHandlerTest.groovy
  23. +1 −1 webtau-core/src/test/groovy/com/twosigma/webtau/expectation/equality/ActualPathMessageTest.groovy
  24. +23 −27 .../src/test/groovy/com/twosigma/webtau/expectation/equality/handlers/AnyCompareToHandlerTest.groovy
  25. +1 −2 ...ovy/com/twosigma/webtau/expectation/equality/handlers/ArrayAndIterableCompareToHandlerTest.groovy
  26. +1 −1 ...est/groovy/com/twosigma/webtau/expectation/equality/handlers/ByteArrayCompareToHandlerTest.groovy
  27. +6 −10 ...groovy/com/twosigma/webtau/expectation/equality/handlers/DateAndStringCompareToHandlerTest.groovy
  28. +1 −5 ...core/src/test/groovy/com/twosigma/webtau/expectation/equality/handlers/HandlerMessagesTest.groovy
  29. +1 −4 ...com/twosigma/webtau/expectation/equality/handlers/IterableAndTableDataCompareToHandlerTest.groovy
  30. +1 −3 ...test/groovy/com/twosigma/webtau/expectation/equality/handlers/IterableCompareToHandlerTest.groovy
  31. +1 −2 ...est/groovy/com/twosigma/webtau/expectation/equality/handlers/LiveValueCompareToHandlerTest.groovy
  32. +1 −1 ...st/groovy/com/twosigma/webtau/expectation/equality/handlers/MapAndBeanCompareToHandlerTest.groovy
  33. +1 −1 ...src/test/groovy/com/twosigma/webtau/expectation/equality/handlers/MapsCompareToHandlerTest.groovy
  34. +11 −11 ...src/test/groovy/com/twosigma/webtau/expectation/equality/handlers/NullCompareToHandlerTest.groovy
  35. +6 −6 ...oovy/com/twosigma/webtau/expectation/equality/handlers/NumberAndStringCompareToHandlerTest.groovy
  36. +3 −8 .../test/groovy/com/twosigma/webtau/expectation/equality/handlers/NumbersCompareToHandlerTest.groovy
  37. +1 −2 ...t/groovy/com/twosigma/webtau/expectation/equality/handlers/RegexpEqualCompareToHandlerTest.groovy
  38. +1 −1 .../src/test/groovy/com/twosigma/webtau/expectation/equality/handlers/SetCompareToHandlerTest.groovy
  39. +1 −3 ...c/test/groovy/com/twosigma/webtau/expectation/equality/handlers/StringCompareToHandlerTest.groovy
  40. +11 −18 ...roovy/com/twosigma/webtau/expectation/equality/handlers/TraceableValueCompareToHandlerTest.groovy
  41. +2 −9 .../groovy/com/twosigma/webtau/expectation/equality/handlers/ValueMatcherCompareToHandlerTest.groovy
  42. +1 −2 webtau-core/src/test/groovy/com/twosigma/webtau/reporter/ConsoleStepReporterTest.groovy
  43. +1 −1 webtau-core/src/test/java/com/twosigma/webtau/data/table/TableDataJavaTest.java
  44. +1 −3 webtau-core/src/test/java/com/twosigma/webtau/data/table/TableDataJavaTestValidations.java
  45. +1 −1 webtau-core/src/test/java/com/twosigma/webtau/documentation/MarginCalculatorWithTableDataTest.java
  46. +1 −3 webtau-core/src/test/java/com/twosigma/webtau/documentation/PeopleDaoTest.java
  47. +1 −3 webtau-core/src/test/java/com/twosigma/webtau/documentation/PeopleManagementTest.java
  48. +6 −2 webtau-core/src/test/java/com/twosigma/webtau/expectation/code/ThrowExceptionMatcherTest.java
  49. +2 −1 webtau-docs/webtau/reference/table-data.md
  50. +3 −4 webtau-feature-testing/examples/scenarios/ui/greaterThan.groovy
  51. +2 −2 webtau-groovy-ast/src/main/groovy/com/twosigma/webtau/groovy/ast/ShouldAstCodeTransformer.groovy
  52. +1 −2 webtau-groovy/src/test/groovy/com/twosigma/webtau/cfg/WebTauGroovyFileConfigHandlerTest.groovy
  53. +1 −1 webtau-http-groovy/src/test/groovy/com/twosigma/webtau/http/HttpGroovyTest.groovy
  54. +1 −1 webtau-http/src/main/java/com/twosigma/webtau/http/Http.java
  55. +1 −1 webtau-http/src/main/java/com/twosigma/webtau/http/datanode/DataNode.java
  56. +1 −3 webtau-http/src/test/groovy/com/twosigma/webtau/http/datanode/DataNodeListContainHandlerTest.groovy
  57. +1 −3 webtau-http/src/test/groovy/com/twosigma/webtau/http/datanode/StructuredDataNodeTest.groovy
  58. +1 −1 webtau-http/src/test/groovy/com/twosigma/webtau/http/render/DataNodeAnsiPrinterTest.groovy
  59. +1 −2 webtau-http/src/test/java/com/twosigma/webtau/http/HttpJavaOverloadsTest.java
  60. +1 −1 webtau-http/src/test/java/com/twosigma/webtau/http/HttpJavaTest.java
  61. +1 −1 webtau-http/src/test/java/com/twosigma/webtau/http/HttpOverloadsTestCommon.java
  62. +1 −3 webtau-json-schema/src/test/groovy/com/twosigma/webtau/expectation/schema/SchemaMatcherTest.groovy
  63. +1 −1 webtau-junit5/src/test/java/com/twosigma/webtau/junit5/DynamicTestsTest.groovy
  64. +1 −1 webtau-open-api/src/test/groovy/com/twosigma/webtau/openapi/OpenApiResponseValidatorTest.groovy
  65. +1 −1 webtau-open-api/src/test/groovy/com/twosigma/webtau/openapi/OpenApiSpecValidatorTest.groovy
  66. +1 −1 webtau-pdf/src/test/groovy/com/twosigma/webtau/pdf/PdfHttpTest.groovy
  67. +1 −3 webtau-pdf/src/test/groovy/com/twosigma/webtau/pdf/PdfTest.groovy
  68. +1 −1 ...nner-groovy/src/test/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestRunnerTest.groovy
  69. +1 −1 ...one-runner-groovy/src/test/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestTest.groovy
  70. +1 −1 webtau/src/main/java/com/twosigma/webtau/WebTauDsl.java
@@ -21,7 +21,7 @@
import com.twosigma.webtau.expectation.equality.CompareToComparator;
import com.twosigma.webtau.expectation.equality.CompareToHandler;

import static com.twosigma.webtau.Ddjt.createActualPath;
import static com.twosigma.webtau.WebTauCore.createActualPath;

public class ElementValueCompareToHandler implements CompareToHandler {
@Override
@@ -24,7 +24,7 @@

import java.util.List;

import static com.twosigma.webtau.Ddjt.createActualPath;
import static com.twosigma.webtau.WebTauCore.createActualPath;

public class PageElementCompareToHandler implements CompareToHandler {
@Override
@@ -19,8 +19,7 @@ package com.twosigma.webtau.browser.page
import com.twosigma.webtau.utils.ResourceUtils
import org.junit.Test

import static com.twosigma.webtau.Ddjt.code
import static com.twosigma.webtau.Ddjt.throwException
import static com.twosigma.webtau.WebTauCore.*

class PageUrlTest {
private static def browser = [
@@ -18,7 +18,7 @@ package com.twosigma.webtau.cli

import org.junit.Test

import static com.twosigma.webtau.Ddjt.*
import static com.twosigma.webtau.WebTauCore.*
import static com.twosigma.webtau.cli.Cli.cli
import static com.twosigma.webtau.cli.CliTestUtils.supportedPlatformOnly

@@ -26,7 +26,7 @@
import java.nio.file.Path;
import java.util.regex.Pattern;

import static com.twosigma.webtau.Ddjt.*;
import static com.twosigma.webtau.WebTauCore.*;
import static com.twosigma.webtau.cli.Cli.cli;
import static com.twosigma.webtau.cli.CliTestUtils.supportedPlatformOnly;

@@ -19,10 +19,7 @@ package com.twosigma.webtau.data.expectation.equality.handlers
import org.codehaus.groovy.runtime.NullObject
import org.junit.Test

import static com.twosigma.webtau.Ddjt.actual
import static com.twosigma.webtau.Ddjt.code
import static com.twosigma.webtau.Ddjt.equal
import static com.twosigma.webtau.Ddjt.throwException
import static com.twosigma.webtau.WebTauCore.*

class GroovyNullCompareToHandlerTest {
@Test
@@ -18,7 +18,7 @@ package com.twosigma.webtau.data.render

import org.junit.Test

import static com.twosigma.webtau.Ddjt.table
import static com.twosigma.webtau.WebTauCore.table
import static org.junit.Assert.assertEquals

class TableDataRenderTest {
@@ -20,7 +20,7 @@ import org.junit.Test

import java.time.LocalDate

import static com.twosigma.webtau.Ddjt.*
import static com.twosigma.webtau.WebTauCore.*
import static com.twosigma.webtau.data.table.TableDataJavaTestValidations.validateAboveValue
import static com.twosigma.webtau.data.table.TableDataJavaTestValidations.validateAboveValueWithMath
import static com.twosigma.webtau.data.table.TableDataJavaTestValidations.validatePermute
@@ -27,8 +27,7 @@ import com.twosigma.webtau.expectation.equality.LessThanMatcher
import com.twosigma.webtau.expectation.equality.LessThanOrEqualMatcher
import com.twosigma.webtau.expectation.equality.NotEqualMatcher

import static com.twosigma.webtau.Ddjt.code
import static com.twosigma.webtau.Ddjt.throwException
import static com.twosigma.webtau.WebTauCore.*

class ShouldAstTransformationTest extends GroovyTestCase {
void testShouldNotTransformationOnNull() {
@@ -0,0 +1,269 @@
package com.twosigma.webtau;

import com.twosigma.webtau.expectation.*;
import com.twosigma.webtau.expectation.code.ThrowExceptionMatcher;
import com.twosigma.webtau.expectation.contain.ContainMatcher;
import com.twosigma.webtau.expectation.equality.*;

import java.util.regex.Pattern;

/**
* Convenient place to discover all the available matchers
*/
public class Matchers {
/**
* Starting point of a value matcher
* <pre>
* actual(value).should(beGreaterThan(10));
* actual(value).shouldNot(beGreaterThan(10));
* </pre>
* Note: In Groovy you can just do <code>value.should beGreaterThan(10)</code>
* @param actual value to assert against
* @return Object to chain a matcher against
*/
public static ActualValueExpectations actual(Object actual) {
return new ActualValue(actual);
}

/**
* Starting point of a code matcher
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException(IllegalArgumentException.class, "negative are not allowed"));
* </pre>
*
* @param codeBlock code to match against
* @return Object to chain a matcher against
*/
public static ActualCodeExpectations code(CodeBlock codeBlock) {
return new ActualCode(codeBlock);
}

/**
* Equal matcher
* <pre>
* actual(value).should(equal(10));
* </pre>
* @param expected value to be equal to
* @return matcher instance
*/
public static EqualMatcher equal(Object expected) {
return new EqualMatcher(expected);
}

/**
* Not equal matcher
* <pre>
* actual(value).should(notEqual(10));
* </pre>
* @param expected value to not be equal to
* @return matcher instance
*/
public static NotEqualMatcher notEqual(Object expected) {
return new NotEqualMatcher(expected);
}

/**
* Contain matcher
* <pre>
* actual(collection).should(contain(10));
* actual(text).should(contain("hello"));
* </pre>
* @param expected value to be contained
* @return matcher instance
*/
public static ContainMatcher contain(Object expected) {
return new ContainMatcher(expected);
}

/**
* Containing matcher. Alias to contain
* <pre>
* actual(collectionWithText).should(contain(containing("hello")));
* </pre>
* @param expected value to be contained
* @return matcher instance
*/
public static ContainMatcher containing(Object expected) {
return new ContainMatcher(expected);
}

/**
* Greater than matcher
* <pre>
* actual(value).shouldBe(greaterThan(10));
* </pre>
* @param expected value to be greater than
* @return matcher instance
*/
public static GreaterThanMatcher greaterThan(Object expected) {
return new GreaterThanMatcher(expected);
}

/**
* Greater than or equal matcher
* <pre>
* actual(value).shouldBe(greaterThanOrEqual(10));
* </pre>
* @param expected value to be greater than or equal
* @return matcher instance
*/
public static GreaterThanOrEqualMatcher greaterThanOrEqual(Object expected) {
return new GreaterThanOrEqualMatcher(expected);
}

/**
* Less than matcher
* <pre>
* actual(value).shouldBe(lessThan(10));
* </pre>
* @param expected value to be less than
* @return matcher instance
*/
public static LessThanMatcher lessThan(Object expected) {
return new LessThanMatcher(expected);
}

/**
* Less than or equal matcher
* <pre>
* actual(value).shouldBe(lessThanOrEqual(10));
* </pre>
* @param expected value to be less than
* @return matcher instance
*/
public static LessThanOrEqualMatcher lessThanOrEqual(Object expected) {
return new LessThanOrEqualMatcher(expected);
}

/**
* Throw exception <code>code</code> matcher.
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException("negative are not allowed"));
* </pre>
* @see #code(CodeBlock)
*
* @param expectedMessage expected exception message
* @return matcher instance
*/
public static ThrowExceptionMatcher throwException(String expectedMessage) {
return new ThrowExceptionMatcher(expectedMessage);
}

/**
* Throw exception <code>code</code> matcher.
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException(Pattern.compile("negative .* not allowed")));
* </pre>
* @see #code(CodeBlock)
*
* @param expectedMessageRegexp regular pattern to match expected exception message
* @return matcher instance
*/
public static ThrowExceptionMatcher throwException(Pattern expectedMessageRegexp) {
return new ThrowExceptionMatcher(expectedMessageRegexp);
}

/**
* Throw exception <code>code</code> matcher.
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException(IllegalArgumentException.class));
* </pre>
* @see #code(CodeBlock)
*
* @param expectedClass expected exception class
* @return matcher instance
*/
public static ThrowExceptionMatcher throwException(Class expectedClass) {
return new ThrowExceptionMatcher(expectedClass);
}

/**
* Throw exception <code>code</code> matcher.
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException(IllegalArgumentException.class, Pattern.compile("negative .* not allowed")));
* </pre>
* @see #code(CodeBlock)
*
* @param expectedClass expected exception class
* @param expectedMessageRegexp regular pattern to match expected exception message
* @return matcher instance
*/
public static ThrowExceptionMatcher throwException(Class expectedClass, Pattern expectedMessageRegexp) {
return new ThrowExceptionMatcher(expectedClass, expectedMessageRegexp);
}

/**
* Throw exception <code>code</code> matcher.
* <pre>
* code(() -> {
* businessLogic(-10);
* }).should(throwException(IllegalArgumentException.class, "negative are not allowed"));
* </pre>
* @see #code(CodeBlock)
*
* @param expectedClass expected exception class
* @param expectedMessage expected exception message
* @return matcher instance
*/
public static ThrowExceptionMatcher throwException(Class expectedClass, String expectedMessage) {
return new ThrowExceptionMatcher(expectedClass, expectedMessage);
}

/**
* Deprecated. Instead use
* <pre>
* actual(value).shouldBe(greaterThan(10));
* </pre>
* @see #greaterThan(Object)
*/
@Deprecated
public static GreaterThanMatcher beGreaterThan(Object expected) {
return greaterThan(expected);
}

/**
* Deprecated. Instead use
* <pre>
* actual(value).shouldBe(greaterThanOrEqual(10));
* </pre>
* @see #greaterThanOrEqual(Object)
*/
@Deprecated
public static GreaterThanOrEqualMatcher beGreaterThanOrEqual(Object expected) {
return greaterThanOrEqual(expected);
}

/**
* Deprecated. Instead use
* <pre>
* actual(value).shouldBe(lessThan(10));
* </pre>
* @see #lessThan(Object)
*/
@Deprecated
public static LessThanMatcher beLessThan(Object expected) {
return lessThan(expected);
}

/**
* Deprecated. Instead use
* <pre>
* actual(value).shouldBe(lessThanOrEqual(10));
* </pre>
* @see #lessThanOrEqual(Object)
*/
@Deprecated
public static LessThanOrEqualMatcher beLessThanOrEqual(Object expected) {
return lessThanOrEqual(expected);
}
}

0 comments on commit 72cd442

Please sign in to comment.
You can’t perform that action at this time.