-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d458e4f
commit 4510ce7
Showing
2 changed files
with
136 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
barcode4j/src/test/java/org/krysalis/barcode4j/impl/DrawingUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.krysalis.barcode4j.impl; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.krysalis.barcode4j.TextAlignment; | ||
import org.krysalis.barcode4j.output.Canvas; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class DrawingUtilTest { | ||
|
||
@Test | ||
void drawCenteredChar() { | ||
final Canvas mockCanvas = mock(Canvas.class); | ||
final AbstractBarcodeBean mockBean = mock(AbstractBarcodeBean.class); | ||
when(mockBean.getFontName()).thenReturn("TestingFontName"); | ||
when(mockBean.getFontSize()).thenReturn(1.2); | ||
|
||
DrawingUtil.drawCenteredChar( | ||
mockCanvas, | ||
mockBean, | ||
'A', | ||
1.0, | ||
1.0, | ||
1.0 | ||
); | ||
|
||
verify(mockCanvas, times(1)).drawCenteredChar( | ||
eq('A'), | ||
eq(1.0), | ||
eq(1.0), | ||
anyDouble(), | ||
eq("TestingFontName"), | ||
eq(1.2) | ||
); | ||
} | ||
|
||
@Test | ||
void drawJustifiedText() { | ||
final Canvas mockCanvas = mock(Canvas.class); | ||
final AbstractBarcodeBean mockBean = mock(AbstractBarcodeBean.class); | ||
when(mockBean.getFontName()).thenReturn("TestingFontName"); | ||
when(mockBean.getFontSize()).thenReturn(1.2); | ||
|
||
DrawingUtil.drawJustifiedText( | ||
mockCanvas, | ||
mockBean, | ||
"Hello World", | ||
1.0, | ||
1.0, | ||
1.0 | ||
); | ||
|
||
verify(mockCanvas, times(1)).drawText( | ||
eq("Hello World"), | ||
eq(1.0), | ||
eq(1.0), | ||
anyDouble(), | ||
eq("TestingFontName"), | ||
eq(1.2), | ||
eq(TextAlignment.TA_JUSTIFY) | ||
); | ||
} | ||
|
||
@Test | ||
void drawCenteredText() { | ||
final Canvas mockCanvas = mock(Canvas.class); | ||
final AbstractBarcodeBean mockBean = mock(AbstractBarcodeBean.class); | ||
when(mockBean.getFontName()).thenReturn("TestingFontName"); | ||
when(mockBean.getFontSize()).thenReturn(1.2); | ||
|
||
DrawingUtil.drawCenteredText( | ||
mockCanvas, | ||
mockBean, | ||
"Hello World", | ||
1.0, | ||
1.0, | ||
1.0 | ||
); | ||
|
||
verify(mockCanvas, times(1)).drawText( | ||
eq("Hello World"), | ||
eq(1.0), | ||
eq(1.0), | ||
anyDouble(), | ||
eq("TestingFontName"), | ||
eq(1.2), | ||
eq(TextAlignment.TA_CENTER) | ||
); | ||
} | ||
|
||
@Test | ||
void drawText() { | ||
final Canvas mockCanvas = mock(Canvas.class); | ||
final AbstractBarcodeBean mockBean = mock(AbstractBarcodeBean.class); | ||
when(mockBean.getFontName()).thenReturn("TestingFontName"); | ||
when(mockBean.getFontSize()).thenReturn(1.2); | ||
|
||
DrawingUtil.drawText( | ||
mockCanvas, | ||
mockBean, | ||
"Hello World", | ||
1.0, | ||
1.0, | ||
1.0, | ||
TextAlignment.TA_RIGHT | ||
); | ||
|
||
verify(mockCanvas, times(1)).drawText( | ||
eq("Hello World"), | ||
eq(1.0), | ||
eq(1.0), | ||
anyDouble(), | ||
eq("TestingFontName"), | ||
eq(1.2), | ||
eq(TextAlignment.TA_RIGHT) | ||
); | ||
} | ||
} |