{
12 | /**
13 | * The abstract method of the {@link FunctionalInterface}.
14 | *
15 | * @param p the parameter
16 | */
17 | void invoke(P p);
18 | }
19 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | Copyright 2016 Adam Ruka
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'specnaz-all'
2 |
3 | include 'src:main:specnaz',
4 | 'src:main:specnaz-junit',
5 | 'src:main:specnaz-kotlin',
6 | 'src:main:specnaz-kotlin-junit',
7 | 'src:main:specnaz-testng',
8 | 'src:main:specnaz-kotlin-testng',
9 | 'src:examples:specnaz-java-examples',
10 | 'src:examples:specnaz-junit-rules-examples',
11 | 'src:examples:specnaz-kotlin-examples',
12 | 'src:examples:specnaz-groovy-examples',
13 | 'src:examples:specnaz-testng-examples',
14 | 'src:examples:specnaz-custom-dsl-example'
15 |
--------------------------------------------------------------------------------
/src/main/specnaz-junit/src/main/java/org/specnaz/junit/SpecnazJUnit.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.junit;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runner.Runner;
5 | import org.specnaz.Specnaz;
6 |
7 | /**
8 | * A utility class that implements the {@link Specnaz} interface
9 | * and declares {@link SpecnazJUnitRunner} as the JUnit test {@link Runner}
10 | * with the {@link RunWith} annotation.
11 | * Useful in cases where your test class doesn't have to extend any particular class.
12 | */
13 | @RunWith(SpecnazJUnitRunner.class)
14 | public abstract class SpecnazJUnit implements Specnaz {
15 | }
16 |
--------------------------------------------------------------------------------
/src/examples/specnaz-custom-dsl-example/src/main/java/org/specnaz/examples/custom_dsl/given_when_then/GivenBuilder.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.examples.custom_dsl.given_when_then;
2 |
3 | import org.specnaz.utils.TestClosure;
4 |
5 | import java.util.function.Consumer;
6 |
7 | public interface GivenBuilder {
8 | default void given(String description, Runnable closure) {
9 | given(description, () -> {}, closure);
10 | }
11 |
12 | void given(String description, TestClosure action, Runnable closure);
13 |
14 | void when(String description, TestClosure action, Consumer {
14 | /**
15 | * The abstract method of the {@link FunctionalInterface}.
16 | *
17 | * @param p the parameter
18 | * @throws Exception can safely throw any Exception
19 | */
20 | void invoke(P p) throws Exception;
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/specnaz/src/main/java/org/specnaz/params/impl/ParametrizedSubgroup1.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.params.impl;
2 |
3 | import org.specnaz.impl.TestCaseType;
4 | import org.specnaz.params.RunnableParams1;
5 |
6 | import java.util.List;
7 |
8 | public final class ParametrizedSubgroup1 extends AbstractParametrizedSubgroup {
9 | private final RunnableParams1 specClosure;
10 |
11 | public ParametrizedSubgroup1(String description, RunnableParams1 specClosure, TestCaseType testCaseType) {
12 | super(description, testCaseType);
13 | this.specClosure = specClosure;
14 | }
15 |
16 | @Override
17 | protected Runnable toSpecClosure(List> paramsSet) {
18 | return () -> specClosure.invoke((P) paramsSet.get(0));
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/specnaz/src/main/java/org/specnaz/params/RunnableParams5.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.params;
2 |
3 | /**
4 | * The equivalent of {@link Runnable} for parametrized
5 | * sub-specifications taking 5 parameters.
6 | *
7 | * @see #invoke(P1, P2, P3, P4, P5)
8 | * @see ParamsSpecBuilder#describes(String, RunnableParams5)
9 | */
10 | @FunctionalInterface
11 | public interface RunnableParams5 extends
11 | AbstractParametrizedPositiveTest {
12 | private final TestClosureParams1 testBody;
13 |
14 | public ParametrizedPositiveTest1(TestSettings testSettings,
15 | String description, TestClosureParams1 testBody, TestCaseType testCaseType) {
16 | super(testSettings, description, testCaseType);
17 | this.testBody = testBody;
18 | }
19 |
20 | @Override
21 | protected TestClosure toTestClosure(List> params) {
22 | return Conversions.toTestClosure1(testBody, params);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/specnaz/src/main/java/org/specnaz/params/impl/AbstractParametrizedPositiveTest.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.params.impl;
2 |
3 | import org.specnaz.TestSettings;
4 | import org.specnaz.impl.SinglePositiveTestCase;
5 | import org.specnaz.impl.SingleTestCase;
6 | import org.specnaz.impl.TestCaseType;
7 |
8 | import java.util.List;
9 |
10 | public abstract class AbstractParametrizedPositiveTest extends AbstractParametrizedTest {
11 | public final TestSettings testSettings;
12 |
13 | AbstractParametrizedPositiveTest(TestSettings testSettings, String description, TestCaseType testCaseType) {
14 | super(description, testCaseType);
15 | this.testSettings = testSettings;
16 | }
17 |
18 | @Override
19 | protected SingleTestCase testCase(List> params) {
20 | return new SinglePositiveTestCase(testSettings,
21 | formatDesc(params), toTestClosure(params), testCaseType);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/specnaz/src/main/java/org/specnaz/params/impl/ParametrizedPositiveTest2.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.params.impl;
2 |
3 | import org.specnaz.TestSettings;
4 | import org.specnaz.impl.TestCaseType;
5 | import org.specnaz.params.TestClosureParams2;
6 | import org.specnaz.utils.TestClosure;
7 |
8 | import java.util.List;
9 |
10 | public final class ParametrizedPositiveTest2 testBody;
13 |
14 | public ParametrizedExceptionTest1(ThrowableExpectations testBody, TestCaseType testCaseType) {
16 | super(throwableExpectations, description, testCaseType);
17 | this.testBody = testBody;
18 | }
19 |
20 | @Override
21 | protected TestClosure toTestClosure(List> params) {
22 | return Conversions.toTestClosure1(testBody, params);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/examples/specnaz-custom-dsl-example/src/main/java/org/specnaz/examples/custom_dsl/given_when_then/SpecnazGivenWhenThen.java:
--------------------------------------------------------------------------------
1 | package org.specnaz.examples.custom_dsl.given_when_then;
2 |
3 | import org.specnaz.core.CoreDslBuilder;
4 | import org.specnaz.core.SpecnazCoreDsl;
5 |
6 | import java.util.function.Consumer;
7 |
8 | public interface SpecnazGivenWhenThen extends SpecnazCoreDsl {
9 | default void given(String description, Consumer