Skip to content

Commit

Permalink
provided Unit Test for Getter and Setter Entities + DAOMessage test
Browse files Browse the repository at this point in the history
  • Loading branch information
panuozzo77 committed Jan 2, 2024
1 parent 6f955c8 commit a17ff4e
Show file tree
Hide file tree
Showing 14 changed files with 706 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/model/DAO/DAOConnectionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package model.DAO;

import model.service.encryption.Encryption;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.SQLException;

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

public class DAOConnectionTest {

private static Connection connection;

@BeforeAll
static void setUp() {
try {
// Set up any necessary configurations or preparations before the tests
connection = DAOConnection.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}

@Test
void testGetConnection() {
assertNotNull(connection, "Connection should not be null");
}

// Add more tests as needed for your specific use cases

@AfterAll
static void tearDown() {
try {
// Release any resources or perform cleanup after the tests
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
102 changes: 102 additions & 0 deletions src/test/java/model/DAO/DAOMessageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package model.DAO;

import model.entity.Message;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;
import java.util.List;

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

class DAOMessageTest {

private DAOMessage daoMessage;

@BeforeEach
void setup() {
daoMessage = new DAOMessage();
}

@Test
void retrieveUsersFromNoPatientsAssigned() {
// Mock the therapist ID
int therapistId = 8; //this therapist have NO patients.

// Call the method to test
List<Integer> userIds = daoMessage.retrieveUserIdsByTherapist(therapistId);

// Check the returned list
assertNotNull(userIds, "Returned list should not be null");
assertTrue(userIds.isEmpty(), "Returned list should be empty");
assertEquals(0, userIds.size());
}

@Test
void retrieveUsersFromPatientsAssigned() {
// Mock the therapist ID
int therapistId = 11; //this therapist have 2 patients.

// Call the method to test
List<Integer> userIds = daoMessage.retrieveUserIdsByTherapist(therapistId);

// Check the returned list
assertNotNull(userIds, "Returned list should not be null");
assertFalse(userIds.isEmpty(), "Returned list should not be empty");
assertEquals(2, userIds.size());
}

@Test
void testRetrieveMessages() {
// Mock the user ID and contact
int userId = 9;
int contact = 12;

// Call the method to test
List<Message> messages = daoMessage.retrieveMessages(userId, contact);

// Check the returned list
assertNotNull(messages, "Returned list should not be null");
assertFalse(messages.isEmpty(), "Returned list should not be empty");
assertNotEquals(0, messages.size()); // Assuming there are 2 messages between these users
}

@Test
void testMarkMessagesAsRead() {
// Mock the sender ID and recipient ID
int senderId = 9;
int recipientId = 12;

// Call the method to test
daoMessage.markMessagesAsRead(senderId, recipientId);

// Since the method doesn't return anything, we can't really verify its correctness
// However, we can assume it worked correctly if no exceptions were thrown
}

@Test
void testSendMessage() {
// Mock the sender ID, recipient ID and message text
int senderId = 9;
int recipientId = 12;
String text = "Test message";

// Call the method to test
daoMessage.sendMessage(senderId, recipientId, text);

// Since the method doesn't return anything, we can't really verify its correctness
// However, we can assume it worked correctly if no exceptions were thrown
}

@Test
void testCountReceivedMessages() {
// Mock the recipient ID
int recipientId = 9;

// Call the method to test
int count = daoMessage.countReceivedMessages(recipientId);

// Check the returned count
assertNotEquals(0, count); // Assuming the recipient has received
}
}
64 changes: 64 additions & 0 deletions src/test/java/model/entity/AnalyticsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package model.entity;

import org.junit.jupiter.api.Test;

import java.sql.Timestamp;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class AnalyticsTest {

@Test
void testGetterAndSetterMethods() {
// Create an instance of the Analytics class
Analytics analytics = new Analytics();

// Set values using setter methods
int userId = 1;
Timestamp timestamp = Timestamp.valueOf("2022-01-01 12:00:00");
String description = "Test Description";
String type = "Test Type";

analytics.setIdUser(userId);
analytics.setTimestamp(timestamp);
analytics.setDescription(description);
analytics.setType(type);

// Test getter methods
assertEquals(userId, analytics.getIdUser(), "getIdUser() should return the correct value");
assertEquals(timestamp, analytics.getTimestamp(), "getTimestamp() should return the correct value");
assertEquals(description, analytics.getDescription(), "getDescription() should return the correct value");
assertEquals(type, analytics.getType(), "getType() should return the correct value");
}

@Test
void testConstructor() {
// Create an instance of the Analytics class using the constructor
int userId = 1;
Timestamp timestamp = Timestamp.valueOf("2022-01-01 12:00:00");
String description = "Test Description";
String type = "Test Type";

Analytics analytics = new Analytics();
analytics.setIdUser(userId);
analytics.setTimestamp(timestamp);
analytics.setDescription(description);
analytics.setType(type);

// Test getter methods
assertEquals(userId, analytics.getIdUser(), "getIdUser() should return the correct value");
assertEquals(timestamp, analytics.getTimestamp(), "getTimestamp() should return the correct value");
assertEquals(description, analytics.getDescription(), "getDescription() should return the correct value");
assertEquals(type, analytics.getType(), "getType() should return the correct value");
}

@Test
void testNotNull() {
// Create an instance of the Analytics class
Analytics analytics = new Analytics();

// Test that the object is not null
assertNotNull(analytics, "Analytics object should not be null");
}
}
38 changes: 38 additions & 0 deletions src/test/java/model/entity/ConditionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package model.entity;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class ConditionTest {

@Test
void testGetterAndSetterMethods() {
// Create an instance of the Condition class
Condition condition = new Condition();

// Set values using setter methods
int idCondition = 1;
String disorderDescription = "Test Disorder Description";
String disorderName = "Test Disorder Name";

condition.setIdCondition(idCondition);
condition.setDisorderDescription(disorderDescription);
condition.setDisorderName(disorderName);

// Test getter methods
assertEquals(idCondition, condition.getIdCondition(), "getIdCondition() should return the correct value");
assertEquals(disorderDescription, condition.getDisorderDescription(), "getDisorderDescription() should return the correct value");
assertEquals(disorderName, condition.getDisorderName(), "getDisorderName() should return the correct value");
}

@Test
void testNotNull() {
// Create an instance of the Condition class
Condition condition = new Condition();

// Test that the object is not null
assertNotNull(condition, "Condition object should not be null");
}
}
54 changes: 54 additions & 0 deletions src/test/java/model/entity/ExerciseGlossaryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package model.entity;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class ExerciseGlossaryTest {

@Test
void testGetterAndSetterMethods() {
// Create an instance of the ExerciseGlossary class
ExerciseGlossary exerciseGlossary = new ExerciseGlossary();

// Set values using setter methods
int idExercise = 1;
String exerciseName = "Test Exercise Name";
String exerciseDescription = "Test Exercise Description";
String type = "Test Type";
int difficulty = 3;
byte[] initialState = "Test Initial State".getBytes();
byte[] solution = "Test Solution".getBytes();
String target = "Test Target";

exerciseGlossary.setIdExercise(idExercise);
exerciseGlossary.setExerciseName(exerciseName);
exerciseGlossary.setExerciseDescription(exerciseDescription);
exerciseGlossary.setType(type);
exerciseGlossary.setDifficulty(difficulty);
exerciseGlossary.setInitialState(initialState);
exerciseGlossary.setSolution(solution);
exerciseGlossary.setTarget(target);

// Test getter methods
assertEquals(idExercise, exerciseGlossary.getIdExercise(), "getIdExercise() should return the correct value");
assertEquals(exerciseName, exerciseGlossary.getExerciseName(), "getExerciseName() should return the correct value");
assertEquals(exerciseDescription, exerciseGlossary.getExerciseDescription(), "getExerciseDescription() should return the correct value");
assertEquals(type, exerciseGlossary.getType(), "getType() should return the correct value");
assertEquals(difficulty, exerciseGlossary.getDifficulty(), "getDifficulty() should return the correct value");
assertEquals(initialState, exerciseGlossary.getInitialState(), "getInitialState() should return the correct value");
assertEquals(solution, exerciseGlossary.getSolution(), "getSolution() should return the correct value");
assertEquals(target, exerciseGlossary.getTarget(), "getTarget() should return the correct value");
}

@Test
void testNotNull() {
// Create an instance of the ExerciseGlossary class
ExerciseGlossary exerciseGlossary = new ExerciseGlossary();

// Test that the object is not null
assertNotNull(exerciseGlossary, "ExerciseGlossary object should not be null");
}
}

56 changes: 56 additions & 0 deletions src/test/java/model/entity/ExerciseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package model.entity;

import org.junit.jupiter.api.Test;

import java.sql.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class ExerciseTest {

@Test
void testGetterAndSetterMethods() {
// Create an instance of the Exercise class
Exercise exercise = new Exercise();

// Set values using setter methods
int idUser = 1;
int idExercise = 2;
Date insertionDate = Date.valueOf("2022-01-01");
Date completionDate = Date.valueOf("2022-01-02");
byte[] execution = "Test Execution".getBytes();
int evaluation = 5;
int recommended = 1;
int feedback = 3;

exercise.setIdUser(idUser);
exercise.setIdExercise(idExercise);
exercise.setInsertionDate(insertionDate);
exercise.setCompletionDate(completionDate);
exercise.setExecution(execution);
exercise.setEvaluation(evaluation);
exercise.setRecommended(recommended);
exercise.setFeedback(feedback);

// Test getter methods
assertEquals(idUser, exercise.getIdUser(), "getIdUser() should return the correct value");
assertEquals(idExercise, exercise.getIdExercise(), "getIdExercise() should return the correct value");
assertEquals(insertionDate, exercise.getInsertionDate(), "getInsertionDate() should return the correct value");
assertEquals(completionDate, exercise.getCompletionDate(), "getCompletionDate() should return the correct value");
assertEquals(execution, exercise.getExecution(), "getExecution() should return the correct value");
assertEquals(evaluation, exercise.getEvaluation(), "getEvaluation() should return the correct value");
assertEquals(recommended, exercise.getRecommended(), "getRecommended() should return the correct value");
assertEquals(feedback, exercise.getFeedback(), "getFeedback() should return the correct value");
}

@Test
void testNotNull() {
// Create an instance of the Exercise class
Exercise exercise = new Exercise();

// Test that the object is not null
assertNotNull(exercise, "Exercise object should not be null");
}
}

Loading

0 comments on commit a17ff4e

Please sign in to comment.