RandomFontFactory { public Font getRandomFont() { Font randomFont; int fontSize; String fontName; int fontStyle; if (this.fontName.isPresent()) { fontName = this.fontName.get(); } else { fontName = FONTS_SUPPORTED.get(rand.nextInt(FONTS_SUPPORTED.size())); } fontSize = this.minFontSize.get() + rand.nextInt(this.maxFontSize.get() - this.minFontSize.get() + 1); fontStyle = getFontStyle(); randomFont = new Font(fontName, fontStyle, fontSize); return randomFont; } private  RandomFontFactory(Builder builder); Font getRandomFont(); static final int MIN_SUPPORTED_FONT_SIZE; static final int MAX_SUPPORTED_FONT_SIZE; static final int DEFAULT_MIN_FONT_SIZE; static final int DEFAULT_MAX_FONT_SIZE; static final List<String> FONTS_SUPPORTED; }
@Test public void testGetRandomFont() throws Exception { }
@Test public void testEnforceCheckFontSize() throws Exception { RandomFontFactory rff = new RandomFontFactory.Builder() .minFontSize(RandomFontFactory.MIN_SUPPORTED_FONT_SIZE) .maxFontSize(RandomFontFactory.MAX_SUPPORTED_FONT_SIZE / 2) .build(); for (int i = 0; i < 50; i++) { assertTrue(rff.getRandomFont().getSize() >= RandomFontFactory.MIN_SUPPORTED_FONT_SIZE); assertTrue(rff.getRandomFont().getSize() <= RandomFontFactory.MAX_SUPPORTED_FONT_SIZE / 2); } }
@Test public void testRandomFontIsNotNull() throws Exception { RandomFontFactory rff = new RandomFontFactory.Builder() .minFontSize(RandomFontFactory.MIN_SUPPORTED_FONT_SIZE) .maxFontSize(RandomFontFactory.MAX_SUPPORTED_FONT_SIZE / 2) .build(); assertNotNull(rff.getRandomFont()); }