1010import java .lang .reflect .InvocationTargetException ;
1111import java .lang .reflect .Method ;
1212import java .sql .PreparedStatement ;
13+ import java .sql .ResultSet ;
14+ import java .sql .SQLException ;
1315import java .util .List ;
1416import java .util .Set ;
15-
1617import static org .airpenthouse .GoTel .util .PropertiesUtilManager .*;
1718import static org .junit .jupiter .api .Assertions .*;
1819
20+
1921@ ExtendWith (MockitoExtension .class )
2022public class TestCountriesEntity {
2123
24+
25+ @ Mock
26+ private ResultSet set ;
2227 @ Mock
2328 private PreparedStatement ps ;
2429 @ InjectMocks
@@ -35,15 +40,16 @@ public void initAfterEach() {
3540 }
3641
3742 @ AfterAll
38- public static void clean (){
43+ public static void clean () {
3944
4045 }
4146
4247 @ Test
43- public void TestPrivateMethod_GetCountryByName () throws NoSuchMethodException , InvocationTargetException , IllegalAccessException {
48+ public void TestPrivateMethod_GetCountryByName () throws NoSuchMethodException , InvocationTargetException , IllegalAccessException , SQLException {
4449 setProperties ("countryName" , "South Africa" );
4550 var list = reflectPrivateMethod ("getCountryByName" );
46- assertTrue (list .get (0 ).getCountryName ().equals (getPropertiesValue ("countryName" )));
51+
52+ assertEquals (getPropertiesValue ("countryName" ), list .get (0 ).getCountryName ());
4753 }
4854
4955 /*
@@ -63,7 +69,7 @@ public void TestPrivateMethod_GetCountryByNameEmptyCountryName() throws NoSuchMe
6369 @ Test
6470 public void TestPrivateMethod_GetCountryByNameWhenServerIsDown () throws NoSuchMethodException , InvocationTargetException , IllegalAccessException {
6571 setProperties ("countryName" , "" );
66- assertThrows (NullPointerException .class ,() -> reflectPrivateMethod ("getCountryByName" ));
72+ assertThrows (NullPointerException .class , () -> reflectPrivateMethod ("getCountryByName" ));
6773 }
6874
6975 /*
@@ -76,6 +82,33 @@ public void TestPrivateMethod_GetCountryByNameEmptyIsInvalid() throws NoSuchMeth
7682 assertTrue (list .isEmpty ());
7783 }
7884
85+ /*
86+ Here testing we getting all countries
87+ Countries Size : 239
88+ */
89+
90+ @ Test
91+ public void TestPrivateMethod_GetAllCountries () throws NoSuchMethodException , InvocationTargetException , IllegalAccessException {
92+ var list = reflectPrivateMethod ("getAllCountries" );
93+ assertEquals (239 , list .size ());
94+ }
95+
96+ @ Test
97+ public void TestPrivateMethod_GetAllCountriesThrowsNullPointerException () throws NoSuchMethodException , InvocationTargetException , IllegalAccessException {
98+ assertThrows (NullPointerException .class , () -> reflectPrivateMethod ("getAllCountries" ));
99+ }
100+
101+ @ Test
102+ public void TestPrivateMethod_addDataToSet () throws InvocationTargetException , IllegalAccessException , NoSuchMethodException {
103+ Method reflectedMethodName = CountriesEntity .class .getDeclaredMethod ("addDataFromDbToSet" ,ResultSet .class );
104+ reflectedMethodName .setAccessible (true );
105+ var sets = (Set <CountriesEntity >)reflectedMethodName .invoke (countriesEntity ,set );
106+
107+ assertTrue (sets .isEmpty ());
108+ }
109+
110+
111+
79112 private List <CountriesEntity > reflectPrivateMethod (String methodName ) throws InvocationTargetException , IllegalAccessException , NoSuchMethodException {
80113 Method reflectedMethodName = CountriesEntity .class .getDeclaredMethod (methodName );
81114 reflectedMethodName .setAccessible (true );
0 commit comments