BoxFitterTest: put existing tests inside a nest

This commit is contained in:
Paul Campbell 2020-05-21 07:53:59 +01:00
parent b215021eee
commit 9f9797dcbd

View file

@ -2,6 +2,7 @@ package net.kemitix.text.fit;
import org.assertj.core.api.WithAssertions; import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.awt.*; import java.awt.*;
@ -22,20 +23,25 @@ public class BoxFitterTest
implements WithAssertions { implements WithAssertions {
private final BoxFitter boxFitter = TextFit.fitter(); private final BoxFitter boxFitter = TextFit.fitter();
private final int imageSize = 300;
private final int fontSize = 20;
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
private final Font font; private final Font font;
private Function<Integer, Font> fontFactory; private Function<Integer, Font> fontFactory;
private Rectangle2D box = new Rectangle(imageSize, imageSize);
public BoxFitterTest() throws URISyntaxException, IOException, FontFormatException { public BoxFitterTest() throws URISyntaxException, IOException, FontFormatException {
URL resource = this.getClass().getResource("alice/Alice-Regular.ttf"); URL resource = this.getClass().getResource("alice/Alice-Regular.ttf");
int initialFontSize = 20;
font = Font.createFont(Font.TRUETYPE_FONT, new File(resource.toURI())) font = Font.createFont(Font.TRUETYPE_FONT, new File(resource.toURI()))
.deriveFont(Font.PLAIN, fontSize); .deriveFont(Font.PLAIN, initialFontSize);
fontFactory = size -> font.deriveFont(Font.PLAIN, size); fontFactory = size -> font.deriveFont(Font.PLAIN, size);
} }
@Nested
@DisplayName("Single Box")
public class SingleBox {
private final int imageSize = 300;
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
private Rectangle2D box = new Rectangle(imageSize, imageSize);
@Test @Test
@DisplayName("Fit single words") @DisplayName("Fit single words")
public void fitSingleWord() { public void fitSingleWord() {
@ -93,6 +99,7 @@ public class BoxFitterTest
private int invoke(String longText) { private int invoke(String longText) {
return boxFitter.fit(longText, fontFactory, graphics2D, box); return boxFitter.fit(longText, fontFactory, graphics2D, box);
} }
}
private String longStringGenerator(int cycles) { private String longStringGenerator(int cycles) {
String text = "This is a long piece of text that should result in an " + String text = "This is a long piece of text that should result in an " +