BoxFit: when using box list API behaves the same when suppling a single box
This commit is contained in:
parent
935e2b966a
commit
2d58712047
1 changed files with 40 additions and 17 deletions
|
@ -34,14 +34,23 @@ public class BoxFitterTest
|
||||||
fontFactory = size -> font.deriveFont(Font.PLAIN, size);
|
fontFactory = size -> font.deriveFont(Font.PLAIN, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FitTests {
|
||||||
|
int fit(String text);
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Single Box")
|
@DisplayName("Single Box API")
|
||||||
public class SingleBox {
|
public class SingleBoxAPI implements FitTests {
|
||||||
|
|
||||||
private final int imageSize = 300;
|
private final int imageSize = 300;
|
||||||
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
|
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
|
||||||
private Rectangle2D box = new Rectangle(imageSize, imageSize);
|
private Rectangle2D box = new Rectangle(imageSize, imageSize);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int fit(String longText) {
|
||||||
|
return boxFitter.fit(longText, fontFactory, graphics2D, box);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Fit single words")
|
@DisplayName("Fit single words")
|
||||||
public void fitSingleWord() {
|
public void fitSingleWord() {
|
||||||
|
@ -95,22 +104,34 @@ public class BoxFitterTest
|
||||||
assertThatCode(() -> fit(longText))
|
assertThatCode(() -> fit(longText))
|
||||||
.doesNotThrowAnyException();
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fit(String longText) {
|
|
||||||
return boxFitter.fit(longText, fontFactory, graphics2D, box);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Overflow boxes")
|
@DisplayName("List of Boxes API")
|
||||||
public class OverflowBoxes {
|
public class BoxListAPI {
|
||||||
|
|
||||||
private final int imageSize = 300;
|
private final int imageSize = 300;
|
||||||
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
|
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
|
||||||
private Rectangle2D box = new Rectangle(imageSize, imageSize);
|
private Rectangle2D box = new Rectangle(imageSize, imageSize);
|
||||||
private List<Rectangle2D> boxes = Arrays.asList(box, box);
|
private List<Rectangle2D> boxes = Arrays.asList(box, box);
|
||||||
|
|
||||||
private int fit(String longText) {
|
@Nested
|
||||||
|
@DisplayName("Single Box")
|
||||||
|
// different API, but should have same behaviour as using single box API
|
||||||
|
public class SingleBox extends SingleBoxAPI {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int fit(String longText) {
|
||||||
|
return boxFitter.fit(longText, fontFactory, graphics2D, boxes);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Two Boxes")
|
||||||
|
public class TwoBoxes implements FitTests{
|
||||||
|
@Override
|
||||||
|
public int fit(String longText) {
|
||||||
return boxFitter.fit(longText, fontFactory, graphics2D, boxes);
|
return boxFitter.fit(longText, fontFactory, graphics2D, boxes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +146,8 @@ public class BoxFitterTest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
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 " +
|
||||||
"attempt to render it at a font size on less than 2.";
|
"attempt to render it at a font size on less than 2.";
|
||||||
|
|
Loading…
Reference in a new issue