mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-28 15:56:31 +00:00
test: improve [unit] testing
Update and refresh this old PR: - plantuml/plantuml#277 Add on test dependencies: - [x] [`io.github.glytching:junit-extensions`](https://github.com/glytching/junit-extensions) - [x] [`Mockito`](https://github.com/mockito/mockito) - `org.mockito:mockito-core` - `org.mockito:mockito-junit-jupiter` Add a first test on: - `test/utils/LineLocationImplTest.java`
This commit is contained in:
parent
1deedf8a65
commit
a34f13873c
@ -28,9 +28,14 @@ java {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.apache.ant:ant:1.10.13")
|
compileOnly("org.apache.ant:ant:1.10.13")
|
||||||
|
|
||||||
|
testImplementation("io.github.glytching:junit-extensions:2.6.0")
|
||||||
testImplementation("org.assertj:assertj-core:3.24.2")
|
testImplementation("org.assertj:assertj-core:3.24.2")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
|
||||||
|
testImplementation("org.mockito:mockito-core:4.+")
|
||||||
|
testImplementation("org.mockito:mockito-junit-jupiter:4.+")
|
||||||
testImplementation("org.scilab.forge:jlatexmath:1.0.7")
|
testImplementation("org.scilab.forge:jlatexmath:1.0.7")
|
||||||
|
|
||||||
"pdfRuntimeOnly"("org.apache.xmlgraphics:fop:2.8")
|
"pdfRuntimeOnly"("org.apache.xmlgraphics:fop:2.8")
|
||||||
"pdfRuntimeOnly"("org.apache.xmlgraphics:batik-all:1.16")
|
"pdfRuntimeOnly"("org.apache.xmlgraphics:batik-all:1.16")
|
||||||
}
|
}
|
||||||
|
122
test/net/sourceforge/plantuml/utils/LineLocationImplTest.java
Normal file
122
test/net/sourceforge/plantuml/utils/LineLocationImplTest.java
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package net.sourceforge.plantuml.utils;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import io.github.glytching.junit.extension.random.Random;
|
||||||
|
import io.github.glytching.junit.extension.random.RandomBeansExtension;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.api.extension.Extensions;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
@Extensions({
|
||||||
|
@ExtendWith(MockitoExtension.class),
|
||||||
|
@ExtendWith(RandomBeansExtension.class)
|
||||||
|
})
|
||||||
|
|
||||||
|
class LineLocationImplTest {
|
||||||
|
@Mock
|
||||||
|
private LineLocation parent;
|
||||||
|
@Mock
|
||||||
|
private LineLocation parent2;
|
||||||
|
|
||||||
|
@Random
|
||||||
|
private String desc;
|
||||||
|
@Random
|
||||||
|
private String desc2;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ctorDestArgMustNotBeNull() {
|
||||||
|
assertDoesNotThrow(() -> new LineLocationImpl(desc, null));
|
||||||
|
assertThrows(NullPointerException.class, () -> new LineLocationImpl(null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void initialPositionIsNegativeOne() {
|
||||||
|
LineLocation loc = new LineLocationImpl(desc, null);
|
||||||
|
assertEquals(-1, loc.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parentSameAsProvided() {
|
||||||
|
LineLocation loc = new LineLocationImpl(desc, parent);
|
||||||
|
assertSame(parent, loc.getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void descriptionSameAsProvided() {
|
||||||
|
LineLocation loc = new LineLocationImpl(desc, parent);
|
||||||
|
assertEquals(desc, loc.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toStringIsAConcatenationofDescAndPosition() {
|
||||||
|
LineLocationImpl loc = new LineLocationImpl(desc, parent);
|
||||||
|
assertEquals(desc + " : -1", loc.toString());
|
||||||
|
assertEquals(desc + " : 0", loc.oneLineRead().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void oneLineReadMovesToNextLine() {
|
||||||
|
LineLocationImpl loc = new LineLocationImpl(desc, parent);
|
||||||
|
|
||||||
|
for (int i = 1; i < 5; ++i) {
|
||||||
|
LineLocationImpl next = loc.oneLineRead();
|
||||||
|
assertEquals(desc, next.getDescription());
|
||||||
|
assertSame(parent, next.getParent());
|
||||||
|
assertEquals(-1 + i, next.getPosition());
|
||||||
|
loc = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void comparisonStandardLibraryAlwaysDifferent() {
|
||||||
|
LineLocationImpl loc1 = new LineLocationImpl(desc, parent);
|
||||||
|
LineLocationImpl loc2 = new LineLocationImpl("<" + desc2, parent);
|
||||||
|
|
||||||
|
assertEquals(1, loc1.compareTo(loc2));
|
||||||
|
assertEquals(-1, loc2.compareTo(loc1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"", "<"})
|
||||||
|
void comparisonDisregardsDescription(String prefix) {
|
||||||
|
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
|
||||||
|
LineLocationImpl loc2 = new LineLocationImpl(prefix + desc2, parent);
|
||||||
|
|
||||||
|
assertEquals(0, loc1.compareTo(loc2));
|
||||||
|
assertEquals(0, loc2.compareTo(loc1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"", "<"})
|
||||||
|
void comparisonDisregardsParent(String prefix) {
|
||||||
|
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
|
||||||
|
LineLocationImpl loc2 = new LineLocationImpl(prefix + desc, parent2);
|
||||||
|
|
||||||
|
assertEquals(0, loc1.compareTo(loc2));
|
||||||
|
assertEquals(0, loc2.compareTo(loc1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"", "<"})
|
||||||
|
void comparisonLooksAtPositionOnly(String prefix) {
|
||||||
|
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
|
||||||
|
LineLocationImpl loc2 = loc1.oneLineRead();
|
||||||
|
LineLocationImpl loc3 = loc2.oneLineRead();
|
||||||
|
|
||||||
|
assertEquals(-1, loc1.compareTo(loc2));
|
||||||
|
assertEquals(1, loc2.compareTo(loc1));
|
||||||
|
|
||||||
|
assertEquals(-2, loc1.compareTo(loc3));
|
||||||
|
assertEquals(2, loc3.compareTo(loc1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user