Skip to content

Commit

Permalink
[#538] Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoding7 authored and prmr committed Jul 2, 2024
1 parent cea62a7 commit fdd4081
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
29 changes: 10 additions & 19 deletions src/org/jetuml/gui/tips/TipDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,12 @@
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

/**
Expand Down Expand Up @@ -225,7 +217,7 @@ private VBox getTipAsVBox(Tip pTip)

List<TipElement> tipElements = pTip.getElements();

Node titleNode = getTipTitleAsTextNode(pTip);
Node titleNode = getTipTitleAsLabel(pTip);
tipVBox.getChildren().add(titleNode);

for(TipElement tipElement : tipElements)
Expand All @@ -242,7 +234,7 @@ private VBox getTipAsVBox(Tip pTip)
* @return Formatted Node containing the tip's title
* @pre pTip!= null
*/
private static Label getTipTitleAsTextNode(Tip pTip)
private static Label getTipTitleAsLabel(Tip pTip)
{
assert pTip != null;

Expand Down Expand Up @@ -273,11 +265,14 @@ private Node getTipElementAsNode(TipElement pTipElement, VBox pParent)
Media media = pTipElement.getMedia();
if(media.equals(Media.TEXT))
{
return this.getTextTipElementAsTextNode(pTipElement);
return this.getTextTipElementAsLabel(pTipElement);
}
else // media.equals(Media.IMAGE) by @pre
{
return getImageTipElementAsImageView(pTipElement);
HBox imageContainer = new HBox(getImageTipElementAsImageView(pTipElement));
imageContainer.setAlignment(Pos.CENTER);
VBox.setMargin(imageContainer, IMAGE_PADDING);
return imageContainer;
}
}

Expand All @@ -286,7 +281,7 @@ private Node getTipElementAsNode(TipElement pTipElement, VBox pParent)
* @pre pTipElement != null
* @pre pTipElement.getMedia().equals(Media.TEXT);
*/
private Label getTextTipElementAsTextNode(TipElement pTipElement)
private Label getTextTipElementAsLabel(TipElement pTipElement)
{
assert pTipElement != null;
assert pTipElement.getMedia().equals(Media.TEXT);
Expand All @@ -308,7 +303,7 @@ private Label getTextTipElementAsTextNode(TipElement pTipElement)
* @pre pTipElement != null
* @pre pTipElement.getMedia().equals(Media.IMAGE)
*/
private static HBox getImageTipElementAsImageView(TipElement pTipElement)
private static ImageView getImageTipElementAsImageView(TipElement pTipElement)
{
assert pTipElement != null;
assert pTipElement.getMedia().equals(Media.IMAGE);
Expand All @@ -326,11 +321,7 @@ private static HBox getImageTipElementAsImageView(TipElement pTipElement)
// two times the padding because of the VBox padding, and a bit extra to make up for
// other default spacing added between nodes
}
HBox imageContainer = new HBox(imageNode);
imageContainer.setAlignment(Pos.CENTER);
VBox.setMargin(imageContainer, IMAGE_PADDING);
return imageContainer;
//return imageNode;
return imageNode;
}
catch( IOException e )
{
Expand Down
25 changes: 13 additions & 12 deletions test/org/jetuml/gui/tips/TestTipDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void testGetTipElementAsNodeHandlesAllMedia()
public void testGetTipTitleAsTextNodeGivesExpectedContent()
{
String title = aTip1.getTitle();
Text titleNode = getTipTitleAsTextNode(aTip1);
Label titleNode = getTipTitleAsLabel(aTip1);
assertEquals(title, titleNode.getText());
}

Expand All @@ -127,7 +128,7 @@ public void testGetTipTitleAsTextNodeHasExpectedFontSize()
}

Tip tip = TipLoader.loadTip(1);
Text titleNode = getTipTitleAsTextNode(tip);
Label titleNode = getTipTitleAsLabel(tip);
Font titleFont = titleNode.getFont();
assertEquals(fontSize, titleFont.getSize());
}
Expand Down Expand Up @@ -199,7 +200,7 @@ public void testGetTextTipElementAsTextNodeReturnsValidTextNode()
String content = "sample content";
TipElement tipElement = new TipElement(Media.TEXT, content);

Text node = getTextTipElementAsTextNode(aTipDialog, tipElement);
Label node = getTextTipElementAsLabel(aTipDialog, tipElement);

assertNotNull(node);
}
Expand All @@ -210,9 +211,9 @@ public void testGetTextTipElementAsTextNodeReturnsNodeWithTextWrapAround()
String content = "sample content";
TipElement tipElement = new TipElement(Media.TEXT, content);

Text node = getTextTipElementAsTextNode(aTipDialog, tipElement);
Label node = getTextTipElementAsLabel(aTipDialog, tipElement);

assertTrue(node.wrappingWidthProperty().isBound());
assertTrue(node.isWrapText());
}

@Test
Expand All @@ -221,7 +222,7 @@ public void testGetTextTipElementAsTextNodeHasRightContent()
String content = "sample content";
TipElement tipElement = new TipElement(Media.TEXT, content);

Text node = getTextTipElementAsTextNode(aTipDialog, tipElement);
Label node = getTextTipElementAsLabel(aTipDialog, tipElement);

assertEquals(node.getText(), content);
}
Expand Down Expand Up @@ -329,13 +330,13 @@ private static Node getTipElementAsNode(TipDialog pImplicitTipDialog, TipElement
}
}

private static Text getTipTitleAsTextNode(Tip pTip)
private static Label getTipTitleAsLabel(Tip pTip)
{
try
{
Method method = TipDialog.class.getDeclaredMethod("getTipTitleAsTextNode", Tip.class);
Method method = TipDialog.class.getDeclaredMethod("getTipTitleAsLabel", Tip.class);
method.setAccessible(true);
return (Text) method.invoke(null, pTip);
return (Label) method.invoke(null, pTip);
}
catch(ReflectiveOperationException e)
{
Expand Down Expand Up @@ -418,13 +419,13 @@ private static void setupNewTip(TipDialog pImplicitTipDialog, Tip pTip)
}
}

private static Text getTextTipElementAsTextNode(TipDialog pImplicitTipDialog, TipElement pTipElement)
private static Label getTextTipElementAsLabel(TipDialog pImplicitTipDialog, TipElement pTipElement)
{
try
{
Method method = TipDialog.class.getDeclaredMethod("getTextTipElementAsTextNode", TipElement.class);
Method method = TipDialog.class.getDeclaredMethod("getTextTipElementAsLabel", TipElement.class);
method.setAccessible(true);
return (Text) method.invoke(pImplicitTipDialog, pTipElement);
return (Label) method.invoke(pImplicitTipDialog, pTipElement);
}
catch(ReflectiveOperationException e)
{
Expand Down

0 comments on commit fdd4081

Please sign in to comment.