Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Jan 17, 2025
1 parent 1351cd4 commit 9cb6f65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions common/src/main/java/com/google/udmi/util/GeneralUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ public static boolean catchToFalse(Supplier<Boolean> provider) {
return catchToElse(provider, false);
}

public static boolean catchToTrue(Supplier<Boolean> provider) {
return catchToElse(provider, true);
}

public static <T> T catchToNull(Supplier<T> provider) {
return catchToElse(provider, (T) null);
}
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/com/google/udmi/util/SiteModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static com.google.udmi.util.Common.UDMI_VERSION_ENV;
import static com.google.udmi.util.Common.getNamespacePrefix;
import static com.google.udmi.util.GeneralUtils.OBJECT_MAPPER_RAW;
import static com.google.udmi.util.GeneralUtils.catchToTrue;
import static com.google.udmi.util.GeneralUtils.friendlyStackTrace;
import static com.google.udmi.util.GeneralUtils.getFileBytes;
import static com.google.udmi.util.GeneralUtils.ifNotNullGet;
Expand Down Expand Up @@ -377,7 +378,7 @@ public Metadata loadDeviceMetadata(String deviceId, boolean safeLoading,

// Missing arrays are automatically parsed to an empty list, which is not what
// we want, so hacky go through and convert an empty list to null.
if (metadata.gateway != null && metadata.gateway.proxy_ids.isEmpty()) {
if (metadata.gateway != null && catchToTrue(() -> metadata.gateway.proxy_ids.isEmpty())) {
metadata.gateway.proxy_ids = null;
}

Expand Down

0 comments on commit 9cb6f65

Please sign in to comment.