Skip to content

Commit 74aa390

Browse files
feat(java): ✨ boolean values handled as test data in excel s… (#912)
1 parent 3f3f55e commit 74aa390

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

core-java/src/main/java/io/github/boykaframework/actions/data/DataRow.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Objects;
2525

2626
import io.github.boykaframework.actions.interfaces.data.IDataRow;
27+
import lombok.ToString;
2728
import org.apache.logging.log4j.Logger;
2829

2930
/**
@@ -32,6 +33,7 @@
3233
* @author Wasiq Bhamla
3334
* @since 28-Nov-2023
3435
*/
36+
@ToString
3537
class DataRow implements IDataRow {
3638
private static final Logger LOGGER = getLogger ();
3739

core-java/src/main/java/io/github/boykaframework/enums/Message.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ public enum Message {
278278
* Test Error.
279279
*/
280280
TEST_ERROR ("Test error..."),
281+
/**
282+
* Unsupported Excel value format.
283+
*/
284+
UNSUPPORTED_EXCEL_VALUE_FORMAT (
285+
"The Excel value format of ({0}) is not supported. Please create a GitHub issue " + "with details to handle the same."),
281286
/**
282287
* User name required for cloud execution
283288
*/

core-java/src/main/java/io/github/boykaframework/parser/ExcelParser.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static io.github.boykaframework.enums.Message.ERROR_READING_FILE;
2323
import static io.github.boykaframework.enums.Message.ERROR_SETTER_NOT_FOUND;
2424
import static io.github.boykaframework.enums.Message.PATH_NOT_DIRECTORY;
25+
import static io.github.boykaframework.enums.Message.UNSUPPORTED_EXCEL_VALUE_FORMAT;
2526
import static io.github.boykaframework.manager.ParallelSession.getSession;
2627
import static io.github.boykaframework.utils.ErrorHandler.handleAndThrow;
2728
import static io.github.boykaframework.utils.ErrorHandler.throwError;
@@ -42,7 +43,6 @@
4243
import java.util.List;
4344
import java.util.Objects;
4445

45-
import io.github.boykaframework.utils.ErrorHandler;
4646
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
4747
import org.apache.poi.xssf.usermodel.XSSFCell;
4848
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -142,7 +142,7 @@ private <T> List<T> getDataFromFile (final List<Object[]> data, final Constructo
142142
}
143143
result.add (dataObject);
144144
} catch (final InstantiationException | IllegalAccessException | InvocationTargetException e) {
145-
ErrorHandler.handleAndThrow (ERROR_CALLING_SETTER, e, format ("set{0}", capitalize (header)), dataCtor.getClass ()
145+
handleAndThrow (ERROR_CALLING_SETTER, e, format ("set{0}", capitalize (header)), dataCtor.getClass ()
146146
.getSimpleName ());
147147
}
148148
}
@@ -162,11 +162,17 @@ private <T> void setFieldValue (final T dataObject, final Object value, final St
162162
} else if (value instanceof Double) {
163163
method = dataClass.getMethod (methodName, Double.class);
164164
method.invoke (dataObject, Double.parseDouble (value.toString ()));
165+
} else if (value instanceof Boolean) {
166+
method = dataClass.getMethod (methodName, Boolean.class);
167+
method.invoke (dataObject, Boolean.parseBoolean (value.toString ()));
168+
} else {
169+
throwError (UNSUPPORTED_EXCEL_VALUE_FORMAT, value.getClass ()
170+
.getSimpleName ());
165171
}
166172
} catch (final IllegalAccessException | InvocationTargetException e) {
167-
ErrorHandler.handleAndThrow (ERROR_CALLING_SETTER, e, methodName, dataClass.getSimpleName ());
173+
handleAndThrow (ERROR_CALLING_SETTER, e, methodName, dataClass.getSimpleName ());
168174
} catch (final NoSuchMethodException e) {
169-
ErrorHandler.handleAndThrow (ERROR_SETTER_NOT_FOUND, e, methodName, dataClass.getSimpleName (), value.getClass ()
175+
handleAndThrow (ERROR_SETTER_NOT_FOUND, e, methodName, dataClass.getSimpleName (), value.getClass ()
170176
.getSimpleName ());
171177
}
172178
}

core-java/src/test/java/io/github/boykaframework/testng/api/restful/data/BookingDataProviders.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static Iterator<Object[]> getBookingData () {
5050
public static Iterator<Object[]> getBookingDataObject () {
5151
final var rows = DATA.get (BookingTestData.class);
5252
return rows.stream ()
53+
.filter (BookingTestData::getEnabled)
5354
.map (d -> new Object[] { d })
5455
.toList ()
5556
.iterator ();

core-java/src/test/java/io/github/boykaframework/testng/api/restful/pojo/BookingTestData.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
@ToString
2323
@Data
2424
public class BookingTestData {
25-
private String additionalNeeds;
26-
private String checkInDate;
27-
private String checkOutDate;
28-
private String depositPaid;
29-
private String firstName;
30-
private String lastName;
31-
private Double srNo;
32-
private Double totalPrice;
25+
private String additionalNeeds;
26+
private String checkInDate;
27+
private String checkOutDate;
28+
private String depositPaid;
29+
private Boolean enabled;
30+
private String firstName;
31+
private String lastName;
32+
private Double srNo;
33+
private Double totalPrice;
3334
}
996 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)