Skip to content

Commit 22a8050

Browse files
committed
fix tests
1 parent 8ffccfa commit 22a8050

File tree

9 files changed

+64
-10
lines changed

9 files changed

+64
-10
lines changed

graphviz-java/example/ex7.png

35.1 KB
Loading

graphviz-java/example/ex8.png

33.1 KB
Loading

graphviz-java/example/graphviz.png

26.6 KB
Loading

graphviz-java/src/main/java/guru/nidi/graphviz/engine/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static Options fromJson(String json) {
8989
final Matcher basedir = BASE_DIR.matcher(json);
9090
final boolean hasBasedir = basedir.find();
9191
final Matcher imgs = IMAGES.matcher(json);
92-
final boolean hasImgs = imgs.find();
92+
final boolean hasImgs = imgs.find() && imgs.group(1).length() > 0;
9393
final String[] imgList = hasImgs ? imgs.group(1).split("},\\{") : new String[0];
9494

9595
return new Options(

graphviz-java/src/test/java/guru/nidi/graphviz/engine/AbstractGraphvizEngineTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import org.junit.jupiter.api.Test;
1919

20+
import java.io.File;
21+
2022
import static org.hamcrest.MatcherAssert.assertThat;
2123
import static org.hamcrest.core.Is.is;
2224

@@ -45,7 +47,8 @@ void vizExecWithOptions() {
4547

4648
final String vizResult = engineUnderTest.jsVizExec("digraph{ a -> b}", options);
4749

48-
assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot',totalMemory:'320000',yInvert:true});"));
50+
assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot',totalMemory:'320000',"
51+
+ "yInvert:true,basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
4952
}
5053

5154
@Test
@@ -55,6 +58,7 @@ void vizExecWithoutOptions() {
5558

5659
final String vizResult = engineUnderTest.jsVizExec("digraph{ a -> b}", options);
5760

58-
assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot'});"));
61+
assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot',"
62+
+ "basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
5963
}
6064
}

graphviz-java/src/test/java/guru/nidi/graphviz/engine/GraphvizTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import guru.nidi.graphviz.model.Graph;
1919
import org.junit.jupiter.api.*;
2020

21+
import java.io.File;
22+
2123
import static guru.nidi.graphviz.model.Factory.graph;
2224
import static guru.nidi.graphviz.model.Factory.node;
2325
import static org.hamcrest.CoreMatchers.is;
@@ -63,15 +65,17 @@ void executeWithTotalMemory() {
6365
final Graph graph = graph().with(node("a").link("b"));
6466
final String result = Graphviz.fromGraph(graph).totalMemory(32000).render(Format.SVG).toString();
6567

66-
assertThat(result, is("render('graph { \"a\" -- \"b\" }',{format:'svg',engine:'dot',totalMemory:'32000'});"));
68+
assertThat(result, is("render('graph { \"a\" -- \"b\" }',"
69+
+ "{format:'svg',engine:'dot',totalMemory:'32000',basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
6770
}
6871

6972
@Test
7073
void executeWithoutTotalMemory() {
7174
final Graph graph = graph().with(node("a").link("b"));
7275
final String result = Graphviz.fromGraph(graph).render(Format.SVG).toString();
7376

74-
assertThat(result, is("render('graph { \"a\" -- \"b\" }',{format:'svg',engine:'dot'});"));
77+
assertThat(result, is("render('graph { \"a\" -- \"b\" }',"
78+
+ "{format:'svg',engine:'dot',basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
7579
}
7680

7781
private void assertThatGraphvizHasFields(Graphviz graphviz, int expectedHeight, int expectedWidth, double expectedScale) {

graphviz-java/src/test/java/guru/nidi/graphviz/engine/OptionsTest.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright © 2015 Stefan Niederhauser ([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package guru.nidi.graphviz.engine;
217

318
import org.junit.jupiter.api.Test;
@@ -15,22 +30,32 @@ void fromJsonMinimal() {
1530
}
1631

1732
@Test
18-
void fromJsonEmptyImages() {
33+
void fromJsonNoImage() {
1934
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',totalMemory:'42',yInvert:true,basedir:'hula'}");
2035
final Options expected = Options.create().engine(Engine.DOT).format(Format.PNG).totalMemory(42).yInvert(true).basedir(new File("hula"));
2136
assertEquals(expected, options);
2237
}
2338

39+
@Test
40+
void fromJsonEmptyImages() {
41+
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',totalMemory:'42',yInvert:true,basedir:'hula',images:[]}");
42+
final Options expected = Options.create().engine(Engine.DOT).format(Format.PNG).totalMemory(42).yInvert(true).basedir(new File("hula"));
43+
assertEquals(expected, options);
44+
}
45+
2446
@Test
2547
void fromJsonOneImage() throws IOException {
26-
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',images:[{path:'example/ex1.png',width:'550px',height:'100px'}]}");
48+
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',images:["
49+
+ "{path:'" + new File(".").getAbsolutePath() + "/example/ex1.png',width:'550px',height:'100px'}]}");
2750
final Options expected = Options.create().engine(Engine.DOT).format(Format.PNG).image("example/ex1.png");
2851
assertEquals(expected, options);
2952
}
3053

3154
@Test
3255
void fromJsonTwoImages() throws IOException {
33-
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',images:[{path:'example/ex1.png',width:'550px',height:'100px'},{path:'example/ex2.png',width:'900px',height:'964px']}");
56+
final Options options = Options.fromJson("{engine:'DOT',format:'PNG',images:["
57+
+ "{path:'" + new File(".").getAbsolutePath() + "/example/ex1.png',width:'550px',height:'100px'},"
58+
+ "{path:'" + new File(".").getAbsolutePath() + "/example/ex2.png',width:'900px',height:'964px']}");
3459
final Options expected = Options.create().engine(Engine.DOT).format(Format.PNG).image("example/ex1.png").image("example/ex2.png");
3560
assertEquals(expected, options);
3661
}
@@ -50,7 +75,8 @@ void toJsonEmptyImages() {
5075
@Test
5176
void toJsonOneImage() {
5277
final String s = Options.create().engine(Engine.DOT).format(Format.PNG).basedir(new File("example")).image("ex1.png").toJson(false);
53-
assertEquals("{format:'svg',engine:'dot',basedir:'" + new File("example").getAbsolutePath() + "',images:[{path:'" + new File("example/ex1.png").getAbsolutePath() + "',width:'550px',height:'100px'}]}", s);
78+
assertEquals("{format:'svg',engine:'dot',basedir:'" + new File("example").getAbsolutePath() + "',images:[" +
79+
"{path:'" + new File("example/ex1.png").getAbsolutePath() + "',width:'550px',height:'100px'}]}", s);
5480
}
5581

5682
@Test

graphviz-java/src/test/java/guru/nidi/graphviz/model/ExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package guru.nidi.graphviz.model;
1717

18-
import guru.nidi.graphviz.attribute.*;
1918
import guru.nidi.graphviz.attribute.Color;
2019
import guru.nidi.graphviz.attribute.Font;
2120
import guru.nidi.graphviz.attribute.Label;
2221
import guru.nidi.graphviz.attribute.Shape;
22+
import guru.nidi.graphviz.attribute.*;
2323
import guru.nidi.graphviz.engine.*;
2424
import org.junit.jupiter.api.*;
2525

graphviz-java/src/test/java/guru/nidi/graphviz/model/ReadmeTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,24 @@ void ex6() throws IOException {
170170
g.fontAdjust(.87).render(Format.PNG).toFile(new File("example/ex6a.png"));
171171
//## end
172172
}
173+
174+
@Test
175+
void ex7() throws IOException {
176+
//## img
177+
Graphviz.useEngine(new GraphvizCmdLineEngine());
178+
Graphviz g = Graphviz.fromGraph(graph()
179+
.with(node(Label.html("<table border='0'><tr><td><img src='graphviz.png' /></td></tr></table>"))));
180+
g.basedir(new File("example")).render(Format.PNG).toFile(new File("example/ex7.png"));
181+
//## img
182+
}
183+
184+
@Test
185+
void ex8() throws IOException {
186+
//## image
187+
Graphviz.useEngine(new GraphvizV8Engine());
188+
Graphviz g = Graphviz.fromGraph(graph()
189+
.with(node(" ").with(Size.std().margin(.8, .7), Image.of("graphviz.png"))));
190+
g.basedir(new File("example")).render(Format.PNG).toFile(new File("example/ex8.png"));
191+
//## image
192+
}
173193
}

0 commit comments

Comments
 (0)