Skip to content

Commit

Permalink
Added null tests to class constructors and getters.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbanks716napier committed Nov 19, 2024
1 parent df6c158 commit a47a654
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/test/java/com/napier/sem/CityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class CityTest {
// Initialising City object and variables that will be used to create City object.
static private City city;
static private City cityNull;
static private int id = 64;
static private String name = "Dubai";
static private String countryCode = "ARE";
Expand All @@ -28,6 +29,7 @@ class CityTest {
@BeforeAll
static void setUpBeforeClass(){
city = new City(id, name, countryCode, district, population);
cityNull = new City(0, null, null, null, 0);
}

/**
Expand All @@ -42,11 +44,21 @@ void testCityConstructor() {
assertEquals(population, city.Population);
}

/**
* Tests the City class constructor with null values.
*/
@Test
void testCityConstructorNull() {
assertNull(cityNull.Name);
assertNull(cityNull.CountryCode);
assertNull(cityNull.District);
}

/**
* Tests the getID method.
*/
@Test
void testGetId() {
void testGetID() {
assertEquals(id, city.getID());
}

Expand All @@ -58,6 +70,14 @@ void testGetName() {
assertEquals(name, city.getName());
}

/**
* Tests the getName method with a null value.
*/
@Test
void testGetNameNull(){
assertNull(cityNull.getName());
}

/**
* Tests the getCountryCode method.
*/
Expand All @@ -66,6 +86,14 @@ void testGetCountryCode() {
assertEquals(countryCode, city.getCountryCode());
}

/**
* Tests the getCountryCode method with a null value.
*/
@Test
void testGetCountryCodeNull(){
assertNull(cityNull.getCountryCode());
}

/**
* Tests the getDistrict method.
*/
Expand All @@ -74,6 +102,14 @@ void testGetDistrict() {
assertEquals(district, city.getDistrict());
}

/**
* Tests the getDistrict method with a null value.
*/
@Test
void testGetDistrictNull(){
assertNull(cityNull.getDistrict());
}

/**
* Tests the getPopulation method.
*/
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/napier/sem/CountryLanguageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class CountryLanguageTest {
// Initialising CountryLanguage object and variables that will be used to create CountryLanguage object.
static private CountryLanguage cl;
static private CountryLanguage clNull;
static private String countryCode = "ALB";
static private String language = "Macedonian";
static private String isOfficial = "F";
Expand All @@ -27,6 +28,7 @@ class CountryLanguageTest {
@BeforeAll
static void setUpBeforeClass(){
cl = new CountryLanguage(countryCode, language, isOfficial, percentage);
clNull = new CountryLanguage(null, null, null, 0);
}

/**
Expand All @@ -40,6 +42,16 @@ void testCountryLanguageConstructor() {
assertEquals(percentage, cl.Percentage);
}

/**
* Tests the CountryLanguage constructor with null values.
*/
@Test
void testCountryLanguageConstructorNull() {
assertNull(clNull.CountryCode);
assertNull(clNull.Language);
assertNull(clNull.IsOfficial);
}

/**
* Tests the getCountryCode method.
*/
Expand All @@ -48,6 +60,14 @@ void testGetCountryCode() {
assertEquals(countryCode, cl.getCountryCode());
}

/**
* Tests the getCountryCode method with a null value.
*/
@Test
void testGetCountryCodeNull() {
assertNull(clNull.getCountryCode());
}

/**
* Tests the getLanguage method.
*/
Expand All @@ -56,6 +76,14 @@ void testGetLanguage() {
assertEquals(language, cl.getLanguage());
}

/**
* Tests the getLanguage method with a null value.
*/
@Test
void testGetLanguageNull() {
assertNull(clNull.getLanguage());
}

/**
* Tests the getIsOfficial method.
*/
Expand All @@ -64,6 +92,14 @@ void testGetIsOfficial() {
assertEquals(isOfficial, cl.getIsOfficial());
}

/**
* Tests the getIsOfficial method with a null value.
*/
@Test
void testGetIsOfficialNull() {
assertNull(clNull.getIsOfficial());
}

/**
* Tests the getPercentage method.
*/
Expand Down
Loading

0 comments on commit a47a654

Please sign in to comment.