Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/io/github/trackerforce/PathExclude.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ private Object handleCollectionOrArray(Object value, String path, ExclusionNode
boolean isArray = value.getClass().isArray();

if (isArray) {
if (isPrimitiveArray(value)) {
return value;
}

array = (Object[]) value;
list = Arrays.asList((Object[]) value);
} else {
Expand All @@ -120,6 +124,10 @@ private Object handleCollectionOrArray(Object value, String path, ExclusionNode
return isArray ? array : list;
}

return addElementsToList(path, node, list);
}

private List<Object> addElementsToList(String path, ExclusionNode node, List<?> list) {
List<Object> items = new ArrayList<>();
for (Object element : list) {
if (isSimpleValue(element)) {
Expand All @@ -130,7 +138,6 @@ private Object handleCollectionOrArray(Object value, String path, ExclusionNode
items.add(elementMap);
}
}

return items;
}

Expand All @@ -140,6 +147,12 @@ private boolean isSimpleValue(Object value) {
value.getClass().isPrimitive();
}

private boolean isPrimitiveArray(Object value) {
return value instanceof boolean[] || value instanceof byte[] || value instanceof char[] ||
value instanceof short[] || value instanceof int[] || value instanceof long[] ||
value instanceof float[] || value instanceof double[];
}

private List<String> getPropertyNames(Class<?> clazz) {
List<String> names = new ArrayList<>();
if (clazz.isRecord()) {
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/clazz/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,36 @@ public class Address {
String state;
String zipCode;
String country;
int[] coordinates;

public static Address of123() {
return new Address(
"123 Main St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{40, 90}
);
}

public static Address of456() {
return new Address(
"456 Elm St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{39, 89});
}

public static Address of789() {
return new Address(
"789 Oak St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{39, 89});
}
}
22 changes: 22 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/clazz/Occupation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ public class Occupation {
String department;
int yearsOfExperience;
Address address;

public static Occupation ofSoftwareEngineer() {
return new Occupation(
"Software Engineer",
"Develops software applications",
90000.00,
"Engineering",
5,
new Address("123 Tech St", "Tech City", "CA", "90001", "USA", new int[]{37, 122})
);
}

public static Occupation ofProjectManager() {
return new Occupation(
"Project Manager",
"Manages software projects",
95000.00,
"Management",
7,
new Address("456 Project Ave", "Project City", "CA", "90002", "USA", new int[]{34, 118})
);
}
}
16 changes: 16 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/clazz/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@ public class Order {
List<Product> products;
Date orderDate;
String orderId;

public static Order ofOrder123() {
return new Order(
List.of(Product.ofLaptop(), Product.ofSmartphone()),
new Date(),
"order123"
);
}

public static Order ofOrder456() {
return new Order(
List.of(Product.ofHeadphones()),
new Date(),
"order456"
);
}
}
30 changes: 30 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/clazz/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,34 @@ public class Product {
double price;
String category;
int stockQuantity;

public static Product ofLaptop() {
return new Product(
"1",
"Laptop",
"High-end gaming laptop",
1500.00,
"Electronics",
5);
}

public static Product ofSmartphone() {
return new Product(
"2",
"Smartphone",
"Latest model smartphone",
800.00,
"Electronics",
10);
}

public static Product ofHeadphones() {
return new Product(
"3",
"Headphones",
"Noise-cancelling headphones",
200.00,
"Accessories",
15);
}
}
47 changes: 13 additions & 34 deletions src/test/java/io/github/trackerforce/fixture/clazz/UserDetail.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.trackerforce.fixture.clazz;

import java.util.Date;
import java.util.List;
import java.util.Map;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.FieldDefaults;

import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
Expand All @@ -22,55 +22,34 @@ public class UserDetail {
Occupation[] occupations;
Map<String, String> additionalInfo;
Map<String, Address> locations;
int[] scoresArray;

public static UserDetail of() {
return new UserDetail(
"john_doe",
"jown@email.com",
"John Doe",
"+1234567890",
new Address(
"123 Main St",
"Springfield",
"IL",
"62701",
"USA"
),
Address.of123(),
List.of(
new Order(
List.of(
new Product("1", "Laptop", "High-end gaming laptop", 1500.00, "Electronics", 5),
new Product("2", "Smartphone", "Latest model smartphone", 800.00, "Electronics", 10)
),
new Date(),
"order123"
),
new Order(
List.of(
new Product("3", "Headphones", "Noise-cancelling headphones", 200.00, "Accessories", 15)
),
new Date(),
"order456"
)
Order.ofOrder123(),
Order.ofOrder456()
),
new String[] {"USER", "ADMIN"},
new Occupation[] {
new Occupation("Software Engineer", "Develops software applications", 90000.00, "Engineering", 5,
new Address("123 Tech St", "Tech City", "CA", "90001", "USA")
),
new Occupation("Project Manager", "Manages software projects", 95000.00, "Management", 7,
new Address("456 Project Ave", "Project City", "CA", "90002", "USA")
)
Occupation.ofSoftwareEngineer(),
Occupation.ofProjectManager()
},
Map.of(
"preferredLanguage", "English",
"subscriptionStatus", "Active",
"lastLogin", "2023-10-01T12:00:00Z"
),
Map.of(
"home", new Address("456 Elm St", "Springfield", "IL", "62701", "USA"),
"work", new Address("789 Oak St", "Springfield", "IL", "62701", "USA")
)
"home", Address.of456(),
"work", Address.of789()
),
new int[] {85, 90, 95}
);
}
}
33 changes: 32 additions & 1 deletion src/test/java/io/github/trackerforce/fixture/record/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ public record Address(
String city,
String state,
String zipCode,
String country
String country,
int[] coordinates
) {
public static Address of123() {
return new Address(
"123 Main St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{40, 90}
);
}

public static Address of456() {
return new Address(
"456 Elm St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{39, 89});
}

public static Address of789() {
return new Address(
"789 Oak St",
"Springfield",
"IL",
"62701",
"USA",
new int[]{39, 89});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,25 @@ public record Occupation(
int yearsOfExperience,
Address address
) {
public static Occupation ofSoftwareEngineer() {
return new Occupation(
"Software Engineer",
"Develops software applications",
90000.00,
"Engineering",
5,
new Address("123 Tech St", "Tech City", "CA", "90001", "USA", new int[]{37, 122})
);
}

public static Occupation ofProjectManager() {
return new Occupation(
"Project Manager",
"Manages software projects",
95000.00,
"Management",
7,
new Address("456 Project Ave", "Project City", "CA", "90002", "USA", new int[]{34, 118})
);
}
}
15 changes: 15 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/record/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@ public record Order(
Date orderDate,
String orderId
) {
public static Order ofOrder123() {
return new Order(
List.of(Product.ofLaptop(), Product.ofSmartphone()),
new Date(),
"order123"
);
}

public static Order ofOrder456() {
return new Order(
List.of(Product.ofHeadphones()),
new Date(),
"order456"
);
}
}
29 changes: 29 additions & 0 deletions src/test/java/io/github/trackerforce/fixture/record/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,33 @@ public record Product(
String category,
int stockQuantity
) {
public static Product ofLaptop() {
return new Product(
"1",
"Laptop",
"High-end gaming laptop",
1500.00,
"Electronics",
5);
}

public static Product ofSmartphone() {
return new Product(
"2",
"Smartphone",
"Latest model smartphone",
800.00,
"Electronics",
10);
}

public static Product ofHeadphones() {
return new Product(
"3",
"Headphones",
"Noise-cancelling headphones",
200.00,
"Accessories",
15);
}
}
Loading
Loading