-
Notifications
You must be signed in to change notification settings - Fork 124
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
cbd44fc
commit 1d8d45c
Showing
1 changed file
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ca.mcgill.cs.jetuml.views; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static ca.mcgill.cs.jetuml.views.StringViewer.FONT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import ca.mcgill.cs.jetuml.geom.Dimension; | ||
|
||
public class TestFontMetrics { | ||
|
||
private static final FontMetrics aMetrics = new FontMetrics(FONT); | ||
// Ensures there is no caching of sorts when reusing the same Text object | ||
@ParameterizedTest | ||
@MethodSource("stringPairParameters") | ||
public void testStateNotPreserved(String firstString, String secondString) | ||
{ | ||
|
||
assertNotEquals(aMetrics.getDimension(firstString), aMetrics.getDimension(secondString)); | ||
} | ||
|
||
private static Stream<Arguments> stringPairParameters() { | ||
return Stream.of( | ||
Arguments.of("X", "XX"), | ||
Arguments.of("XX", "XXX"), | ||
Arguments.of("XXX", "XXXX"), | ||
Arguments.of("XXXX", "XXXXX"), | ||
Arguments.of("XXXXX", "XXXXXX") | ||
); | ||
} | ||
|
||
@Test | ||
public void testGetDimensions() | ||
{ | ||
assertEquals(new Dimension(0, 11), aMetrics.getDimension("")); | ||
assertEquals(new Dimension(92, 11), aMetrics.getDimension("Single-Line-String")); | ||
assertEquals(new Dimension(29, 39), aMetrics.getDimension("Multi\nLine\nString")); | ||
} | ||
|
||
@Test | ||
public void testGetLogicalHeight() | ||
{ | ||
assertEquals(14, aMetrics.getLogicalHeight("")); | ||
assertEquals(14, aMetrics.getLogicalHeight("Single-Line-String")); | ||
assertEquals(42, aMetrics.getLogicalHeight("Multi\nLine\nString")); | ||
} | ||
} |