[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
created JUnit test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
velnias75 committed Aug 9, 2021
1 parent 17fb2c3 commit ccd1b3f
Show file tree
Hide file tree
Showing 5 changed files with 557 additions and 23 deletions.
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,20 @@ dependencies {

compileOnly "com.google.code.findbugs:annotations:${project.findbugs_version}"
annotationProcessor "com.google.code.findbugs:annotations:${project.findbugs_version}"

testImplementation "org.spigotmc:spigot-api:${project.spigot_version}"
testImplementation "junit:junit:${project.junit_version}"
}

test {
testLogging {
events "failed"

showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true

showStandardStreams = false
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spigot_version=1.17.1-R0.1-SNAPSHOT
plugins_annotation_version=1.2.3-SNAPSHOT
findbugs_version=3.0.1
junit_version=4.13.2
28 changes: 5 additions & 23 deletions src/main/java/de/rangun/luegenpresse/spew/Spew.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ public final class Spew {
private int Classes;
private byte[] InLine = new byte[MAXLINE];

/*-
public static void main(String[] args) throws IOException, SpewException {
Spew spew = new Spew();
System.out.println(spew.getHeadline());
public Spew(final File in) throws IOException, SpewException {
InFile = new BufferedReader(new FileReader(in));
readtext();
}
*/

public Spew(File in) throws IOException, SpewException {

// InFile = new BufferedReader(
// new InputStreamReader(this.getClass().getResourceAsStream("/headline"),
// StandardCharsets.UTF_8));
public Spew(final File in, final long seed) throws IOException, SpewException {
InFile = new BufferedReader(new FileReader(in));
rnd.setSeed(seed);
readtext();
}

Expand Down Expand Up @@ -392,7 +387,6 @@ private void display(StringBuilder sb, final byte[] s, int deftag) {
if ((c = dp.string[p++]) == '\0')
return;
else if (c == '!') {
// System.out.print('\n');
sb.append('\n');
} else if (isalnum((byte) c)) {

Expand All @@ -407,7 +401,6 @@ else if (c == '!') {

} else {
if (writing == 1)
// System.out.print((char) c);
sb.append((char) c);
}
}
Expand All @@ -421,7 +414,6 @@ else if (c == '!') {
writing = variant == 0 ? 1 : 0;
} else {
if (writing == 1)
// System.out.print('{');
sb.append('{');
}

Expand All @@ -433,7 +425,6 @@ else if (c == '!') {
writing = (variant == incurly++) ? 1 : 0;
} else {
if (writing == 1)
// System.out.print(VBAR);
sb.append((char) VBAR);
}

Expand All @@ -445,15 +436,13 @@ else if (c == '!') {
writing = 1;
incurly = 0;
} else {
// System.out.print('}');
sb.append('}');
}

break;

default:
if (writing == 1)
// System.out.print((char) c);
sb.append((char) c);
}
}
Expand All @@ -471,13 +460,6 @@ private Class lookup(final byte[] str) {
int first = 0;
int last = Classes - 1;

/*-
for (int i = 0; i < Classes - 1; ++i) {
if (namecomp(str, Class[i].name) == 0)
return Class[i];
}
*/

while (first <= last) {

tryy = (first + last) >> 1;
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/de/rangun/luegenpresse/test/SpewTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2021 by Heiko Schäfer <heiko@rangun.de>
*
* This file is part of Luegenpresse.
*
* Luegenpresse is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Luegenpresse is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Luegenpresse. If not, see <http://www.gnu.org/licenses/>.
*/

package de.rangun.luegenpresse.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.File;

import org.junit.Before;
import org.junit.Test;

import de.rangun.luegenpresse.spew.Spew;

public class SpewTest {

private Spew spew;

@Before
public void setUp() throws Exception {

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("headline").getFile());

spew = new Spew(new File(file.getAbsolutePath()), 1L);
}

@Test
public void test() {
assertEquals(
"Cindi Lauper Tells Of Night Of Terror With Muammar Quadaffi. \"He Threatened Me With a Hatchet\".\n",
spew.getHeadline());
}

}
Loading

0 comments on commit ccd1b3f

Please sign in to comment.