Integrated AddWordController

Fixed null pointer exception in the one or more blanks check.
Created addwordtest
This commit is contained in:
Henry Dugmore 2020-04-28 12:23:12 +01:00
parent 307b0a18b1
commit 25f21ccef3
5 changed files with 91 additions and 8 deletions

View file

@ -0,0 +1,12 @@
<component name="libraryTable">
<library name="com.fasterxml.jackson.core:jackson-databind:2.9.4" type="repository">
<properties maven-id="com.fasterxml.jackson.core:jackson-databind:2.9.4" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.4/jackson-databind-2.9.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.4/jackson-core-2.9.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="junit">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="org.junit.jupiter:junit-jupiter:5.5.2" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.5.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.5.2/junit-jupiter-5.5.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.2/junit-jupiter-api-5.5.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.2/junit-platform-commons-1.5.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.5.2/junit-jupiter-params-5.5.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.5.2/junit-jupiter-engine-5.5.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.5.2/junit-platform-engine-1.5.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -8,6 +8,8 @@ import javafx.scene.control.TextField;
import java.io.IOException;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
/**
* Add Word Controller
@ -32,13 +34,15 @@ public class AddWordController {
wordType.getItems().addAll("Masculine noun", "Feminine noun", "Verb", "Other");
System.out.println("Test");
wordType.setValue("Type");
}
@FXML protected void addButtonClick (ActionEvent actionEvent){
boolean entryFound = false;
if (english.getText().equals("") || welsh.getText().equals("")|| wordType.getValue().equals("Type")){
// one or more blank fields
if (english.getText() == null || welsh.getText() == null|| wordType.getValue().equals("Type")){
Alert error = new Alert(Alert.AlertType.ERROR);
error.setTitle("Error");
error.setHeaderText("Entry Not Saved");
@ -48,9 +52,9 @@ public class AddWordController {
}
else {
for (DictionaryEntry entry : App.dictionary){
for (DictionaryEntry entry : Application.dictionary){
entryFound = false;
DictionaryEntry newEntry = new DictionaryEntry(english.getText(),welsh.getText(),wordType.getValue(),false);
DictionaryEntry newEntry = new DictionaryEntry(english.getText(),welsh.getText(),wordType.getValue());
if(entry.equals(newEntry)){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
@ -72,10 +76,21 @@ public class AddWordController {
alert.setContentText("Entry Added");
alert.showAndWait();
DictionaryEntry dictionaryEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue(), false);
App.dictionary.contains(dictionaryEntry);
App.dictionary.add(dictionaryEntry);
System.out.println(App.dictionary.toString());
DictionaryEntry dictionaryEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue());
Application.dictionary.contains(dictionaryEntry);
Application.dictionary.add(dictionaryEntry);
// output of what was saved for testing
System.out.print(english.getText());
System.out.print(welsh.getText());
System.out.println(wordType.getValue());
// Resets values to blank for next word to be entered
english.clear();
welsh.clear();
wordType.setValue("Type");
}
}
@ -91,7 +106,7 @@ public class AddWordController {
@FXML
private void switchToPrimary() throws IOException {
App.setRoot("Primary");
Application.setRoot("Primary");
}
// add character methods for characters ch, dd, ff, ng, ll, ph, rh, th
public void addCharch(ActionEvent actionEvent) { welsh.appendText("ch"); }

View file

@ -0,0 +1,29 @@
package uk.ac.aber.cs22120.group20.test;
/**
* Class that contains methods to test that the Add Word Screen only saves words to the dictionary when
* all fields are filled and the entry does not already exist in as an entry in the dictionary.
* @Author
* @Version
* @See
*/
public class AddWordText {
/**
* Test to check if the correct error is thrown when there are one or more blank fields and that the entry
* does not save to the dictionary.
*/
@test
public void testBlankFields() {
}
/**
* Test to check if the correct error is thrown when the entry attempting to be added already exists within
* the dictionary and that the entry is not saved.
*/
@test
public void testDuplicateEntry() {
}
}