Skip to content

Commit

Permalink
A few jUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shqtech committed Jun 15, 2018
1 parent 4efbaeb commit a674d61
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="lib" path="lib/ini4j-0.5.4.jar"/>
<classpathentry kind="lib" path="lib/commons-net-3.6.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.7.jar"/><classpathentry kind="lib" path="lib/commons-io-2.6.jar"/><classpathentry kind="output" path="bin"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.7.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 0 additions & 3 deletions src/application/EditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ private void loadEditFile() {
Recipe rec = Model.recipe;
titleText.setText(rec.getTitle());
titleText.setEditable(false);
//filenameText.setText(EditRecipeController.selectedName);
sourceText.setText(rec.getSource());
startdateText.setText(rec.getStartdate());
fatText.setText(""+rec.getFat());
Expand Down Expand Up @@ -198,8 +197,6 @@ public void saveToXMLFile() throws Exception {
taskStringList.add(taskString);
Recipe.Tasks.Task task = new Recipe.Tasks.Task();
boolean att = ui.getAttention().getSelectionModel().selectedIndexProperty().get()== 0 ? true : false;
//timerButton.setVisible(false);
//timerButton.setManaged(false);
task.setTaskTitle(ui.getTaskTitle().getText());
task.setAttentionRequired(att);
task.setTaskString(taskString);
Expand Down
23 changes: 0 additions & 23 deletions src/application/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,6 @@ public static String getTime() {
}


public static String formatSeconds(String timeInSeconds) {
int hours = Integer.parseInt(timeInSeconds) / 3600;
int secondsLeft = Integer.parseInt(timeInSeconds) - hours * 3600;
int minutes = secondsLeft / 60;
int seconds = secondsLeft - minutes * 60;

String formattedTime = "";
if (hours < 10)
formattedTime += "0";
formattedTime += hours + ":";

if (minutes < 10)
formattedTime += "0";
formattedTime += minutes + ":";

if (seconds < 10)
formattedTime += "0";
formattedTime += seconds ;

return formattedTime;
}


public static String secondsToHHMMSS(int seconds) {
String string = "";
if (Integer.toString(seconds/3600).length() >= 2) {
Expand Down
4 changes: 4 additions & 0 deletions src/application/ObjectFactory.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @author Saadman Haq s160081
*/

package application;

import javax.xml.bind.JAXBElement;
Expand Down
2 changes: 1 addition & 1 deletion src/application/PieChartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private float calculateCalTotal() {
}

//temporary hack
private float calculateExcessCarbs() {
public float calculateExcessCarbs() {
float cals = (float) (Integer.parseInt(Model.recipe.getCalories()));
float calD = cals - calculateCalTotal();
float exCarbsCal = 4*Model.recipe.getCarbohydrates() + calD;
Expand Down
4 changes: 4 additions & 0 deletions src/application/Util.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @author Saadman Haq s160081
*/

package application;


Expand Down
55 changes: 55 additions & 0 deletions src/jUnitTests/ModelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package jUnitTests;

import static org.junit.jupiter.api.Assertions.*;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.jupiter.api.Test;

import application.Model;
import application.Recipe;
import application.Recipe.Ingredients;
import application.Recipe.Ingredients.Ingredient;

class ModelTest {
private Recipe.Ingredients.Ingredient ingredient = new Recipe.Ingredients.Ingredient();
private Recipe rec;

@Test
void testSecondsToHHMMSS() {
Model testTime = new Model();
String test1 = testTime.secondsToHHMMSS(2000);
String test2 = "00:33:20";
assertEquals(test2,test1);
}

@Test
void testSecondsToCollapsingHHMMSS() {
Model test = new Model();
String test1 = test.secondsToCollapsingHHMMSS(120);
String test2 = "2:00";
assertEquals(test2, test1);
}

@Test
void testGetTime() { //works if you comment line 60-70 in Model, NPE otherwise
Model test = new Model();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String str = sdf.format(new Date());
String test1 = test.getTime();
assertEquals(str, test1);
}

// @Test
// void testIngredientQuantityMultiplier() {
// ingredient.setIname("bread");
// ingredient.setQuantity("100");
// ingredient.setUnit("g");
// Model.ingredientsQuantityMultiplier(2);
// assertEquals("200",Model.recipe.getIngredients().getIngredient());
// }



}
53 changes: 53 additions & 0 deletions src/jUnitTests/RecipeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package jUnitTests;

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import application.Recipe;
import application.Recipe.Ingredients.Ingredient;

class RecipeTest {
private Recipe rec;
private Ingredient ing;

@BeforeEach
void setUp() throws Exception {
rec = new Recipe();
ing = new Recipe.Ingredients.Ingredient();
rec.setTitle("asciuta");
rec.setID(Byte.parseByte("1"));
rec.setStartdate("12.04.2014");
rec.setChangedate("14.06.2018");
rec.setTarget("For 4-5 people");

rec.setIngredients(new Recipe.Ingredients());
ing.setIname("spaghetti");
ing.setQuantity("300");
ing.setUnit("g");



}

@Test
void test() {
String title = "asciuta";
String ID = "1";
String sd = "12.04.2014";
String cd = "14.06.2018";
String tar = "For 4-5 people";

assertEquals(title, rec.getTitle());
assertEquals(Byte.parseByte(ID), rec.getID());
assertEquals(sd, rec.getStartdate());
assertEquals(cd, rec.getChangedate());
assertEquals(tar, rec.getTarget());


}

}

0 comments on commit a674d61

Please sign in to comment.