Skip to content

Commit

Permalink
Merge pull request #10 from agorapulse/chore/rule-no-more
Browse files Browse the repository at this point in the history
fixt is no longer a rule, updated license headers
  • Loading branch information
musketyr authored Mar 16, 2021
2 parents 92e54c4 + 929bed7 commit 0c2a70f
Show file tree
Hide file tree
Showing 43 changed files with 67 additions and 76 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/guide.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 2 additions & 3 deletions docs/guide/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ test {
}
----

Fixt can be use directly or as a JUnit rule which will guarantee that the directories are created before
the test run so adding new fixture files will be easier.
Fixt guarantee that the directories are created before the test run so adding new fixture files will be easier.

=== Installation

Expand Down Expand Up @@ -67,7 +66,7 @@ dependencies {
----
include::{root-dir}/libs/fixt/src/test/groovy/com/agorapulse/testing/fixt/FixtSpec.groovy[lines=18..-1]
----
<1> Declare `Fixt` rule for the specification
<1> Declare `Fixt` for the specification
<2> Read the content of the file as stream
<3> Read the content of the file as text
<4> Create `Fixt` for the specific class (`ReferenceClass`)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2018-2020 Agorapulse.
# Copyright 2018-2021 Agorapulse.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions libs/fixt/fixt.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,6 @@ dependencies {
// required by Groovy plugin
compileOnly "org.codehaus.groovy:groovy:${groovyVersion}"

implementation "junit:junit:${junitVersion}"
testImplementation "org.spockframework:spock-core:${spockVersion}"
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
}
49 changes: 24 additions & 25 deletions libs/fixt/src/main/groovy/com/agorapulse/testing/fixt/Fixt.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,21 +17,27 @@
*/
package com.agorapulse.testing.fixt;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
* Simple tool for managing test fixtures in folders which corresponds the package and the name of the specification class.
*/
public class Fixt implements TestRule {
public class Fixt {

private static final String TEST_RESOURCES_FOLDER_PROPERTY_NAME = "testresourcesfolder";
private static final String IGNORED_CHARACTERS = "[\\W_]";
Expand All @@ -42,21 +48,25 @@ public class Fixt implements TestRule {
* @return new Fixt for the given object
*/
public static Fixt create(Object object) {
return new Fixt(object instanceof Class ? (Class) object : object.getClass());
Fixt fixt = new Fixt(object instanceof Class ? (Class<?>) object : object.getClass());
fixt.mkdirs();
return fixt;
}

/**
* Creates new Fixt for the given class.
* @param clazz the given class
* @return new Fixt for the given class
*/
public static Fixt create(Class clazz) {
return new Fixt(clazz);
public static Fixt create(Class<?> clazz) {
Fixt fixt = new Fixt(clazz);
fixt.mkdirs();
return fixt;
}

private final Class clazz;
private final Class<?> clazz;

private Fixt(Class clazz) {
private Fixt(Class<?> clazz) {
this.clazz = clazz;
}

Expand Down Expand Up @@ -135,7 +145,7 @@ public InputStream readStream(String fileName) {
* @param fileName the relative file name
* @return the text stored in the given file
*/
public String readText(String fileName) throws IOException {
public String readText(String fileName) {
InputStream stream = readStream(fileName);
if (stream == null) {
return null;
Expand Down Expand Up @@ -168,17 +178,6 @@ private String getFixtureLocation(String fileName) {
return FileSystems.getDefault().getPath("", pathParams).toString();
}

@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
mkdirs();
base.evaluate();
}
};
}

private static String streamToText(InputStream stream) {
try (Scanner scanner = new Scanner(stream, StandardCharsets.UTF_8.name()).useDelimiter("\\A")) {
if (scanner.hasNext()) {
Expand Down
4 changes: 1 addition & 3 deletions libs/fixt/src/test/groovy/FixtSpecNoPackageSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
*/
import com.agorapulse.testing.fixt.Fixt
import org.junit.ClassRule
import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables
import org.junit.rules.TemporaryFolder
import spock.lang.Shared
Expand All @@ -39,7 +38,6 @@ class FixtSpecNoPackageSpec extends Specification {
@ClassRule @Shared
EnvironmentVariables environmentVariables = new EnvironmentVariables()

@Rule
Fixt fixt = Fixt.create(FixtSpecNoPackageSpec)

void setupSpec() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,6 @@ class FixtSpec extends Specification {
@Rule
TemporaryFolder tmp = new TemporaryFolder()

@Rule
Fixt fixt = Fixt.create(this) // <1>

void 'reading existing files'() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

config {
bintray {
enabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions libs/office-unit/office-unit.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

config {
bintray {
enabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Agorapulse.
* Copyright 2018-2021 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 0c2a70f

Please sign in to comment.