BoxFit: when using box list API behaves the same when suppling a single box

This commit is contained in:
Paul Campbell 2020-05-22 19:56:21 +01:00
parent 935e2b966a
commit 2d58712047

View file

@ -34,14 +34,23 @@ public class BoxFitterTest
fontFactory = size -> font.deriveFont(Font.PLAIN, size);
}
interface FitTests {
int fit(String text);
}
@Nested
@DisplayName("Single Box")
public class SingleBox {
@DisplayName("Single Box API")
public class SingleBoxAPI implements FitTests {
private final int imageSize = 300;
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
private Rectangle2D box = new Rectangle(imageSize, imageSize);
@Override
public int fit(String longText) {
return boxFitter.fit(longText, fontFactory, graphics2D, box);
}
@Test
@DisplayName("Fit single words")
public void fitSingleWord() {
@ -95,22 +104,34 @@ public class BoxFitterTest
assertThatCode(() -> fit(longText))
.doesNotThrowAnyException();
}
private int fit(String longText) {
return boxFitter.fit(longText, fontFactory, graphics2D, box);
}
}
@Nested
@DisplayName("Overflow boxes")
public class OverflowBoxes {
@DisplayName("List of Boxes API")
public class BoxListAPI {
private final int imageSize = 300;
private final Graphics2D graphics2D = graphics(imageSize, imageSize);
private Rectangle2D box = new Rectangle(imageSize, imageSize);
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);
}
@ -125,6 +146,8 @@ public class BoxFitterTest
}
}
private String longStringGenerator(int cycles) {
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.";