Trouble creating tests for ListFields #678
nightm4re94
started this conversation in
Old Forum
Replies: 0 comments
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2019-07-20 18:52:00
User: CalvinMT [] (age: 1451 days 🔥; posts: 114)
Hi!
I'm making ListField tests for the pull request ~~~~#282 and I'm encountering two problems.
1.When creating a new ~~~~ListField()
, an error occured showing that*~~null**. To "solve" it, I called ~~~~Input.mouse()
returned *~~Game.init()
. Is this ok or is there another safer way?2.I need to make click tests. I tried the same method than in ~~*~~GuiComponentTest.java* with a```~~public class ListFieldTest {~~createTestEvent()
method, but it isn't working. Any ideas?Here's the code that I currently have to test list fields: (I'll rearrange things arround once finished)
`
private final String[] content_1D = new String[] {
"A", "B", "C", "D", "E", "F", "G"
};
private final String[][] content_2D = new String[][] {
{"A", "B", "C", "D", "E", "F", "G"},
{"H", "I", "J", "K", "L", "M", "N", "O"},
{"P", "Q", "R", "S", "T", "U", "V"},
{"W", "X", "Y", "Z"}
};
@test
public void testInitialization() {
/**
/
Game.init(Game.COMMADLINE_ARG_NOGUI);
ListField listField_1D = new ListField(0, 0, 100, 50, this.content_1D, 4, null, null);
ListField listField_2D = new ListField(0, 0, 100, 50, this.content_2D, 7, null, null);
assertNotNull(listField_1D);
assertNotNull(listField_2D);
assertEquals(this.content_1D, listField_1D.getContent()[0]);
assertEquals(this.content_2D, listField_2D.getContent());
for (int i = 0; i < listField_1D.getListEntry(0).size(); i++) {
assertEquals(this.content_1D[i], listField_1D.getListEntry(0).get(i).getText());
}
for (int i = 0; i < listField_2D.getContent().length; i++) {
for (int j = 0; j < listField_2D.getListEntry(i).size(); j++) {
assertEquals(this.content_2D[i][j], listField_2D.getListEntry(i).get(j).getText());
}
}
assertEquals(7, listField_1D.getMaxRows());
assertEquals(8, listField_2D.getMaxRows());
listField_1D.prepare();
listField_2D.prepare();
assertTrue(listField_1D.isVisible());
assertTrue(listField_2D.isVisible());
assertTrue(listField_1D.isEnabled());
assertTrue(listField_2D.isEnabled());
assertFalse(listField_1D.isArrowKeyNavigation());
assertFalse(listField_2D.isArrowKeyNavigation());
listField_1D.mouseClicked(createTestEvent(50, 50));
listField_1D.refresh();
/*
*/
assertEquals(this.content_1D[0], listField_1D.getSelectedObject());
assertEquals(this.content_1D[0], listField_1D.getSelectedComponent().getText());
}
private static MouseEvent createTestEvent(int x, int y) {
return new MouseEvent(new JLabel(), 0, 0, 0, x, y, 0, false);
}
}````
Beta Was this translation helpful? Give feedback.
All reactions