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,32 +104,46 @@ 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
|
||||||
return boxFitter.fit(longText, fontFactory, graphics2D, boxes);
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Nested
|
||||||
@DisplayName("Text too long to fit single box - fits into two")
|
@DisplayName("Two Boxes")
|
||||||
public void tooLongThrows() {
|
public class TwoBoxes implements FitTests{
|
||||||
String longText = longStringGenerator(197);
|
@Override
|
||||||
//TODO: should overflow into second box
|
public int fit(String longText) {
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
return boxFitter.fit(longText, fontFactory, graphics2D, boxes);
|
||||||
.isThrownBy(() -> fit(longText));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Text too long to fit single box - fits into two")
|
||||||
|
public void tooLongThrows() {
|
||||||
|
String longText = longStringGenerator(197);
|
||||||
|
//TODO: should overflow into second box
|
||||||
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
|
.isThrownBy(() -> fit(longText));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue