Question: I'm using helm charts to deploy several REST services with into k8s with spring boot inside deployed container.

However, to be able to do final stage testing I need to introduce some sort of smart liveness probe - i.e. that the target application is actually running properly inside given container.

This can be easily justified by successful return code of simple `curl` command, however, here's the trick - command needs to be executed with some delay after particular release deployment to give application time to bootstrap.

Here's what I've figured for a test suite:

```
apiVersion: v1
kind: Pod
metadata:
  name: "{{ include "chart.fullname" . }}-test"
  labels:
  {{- include "chart.fullname" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test-success
spec:
  containers:
    - name: test-curl
      image: curl
      command: ['curl']
      args: [' -X POST -i -H "Accept: application/json" -H "Content-Type:application/json" -d ''{"foo":["bar"]}'' {{ include "chart.fullname" . }}:{{ .Values.service.port }}']
  restartPolicy: Never

```

The key problem is that this test will be executed when service is not really started yet and thus fail anyway.

Is there some mechanism or workaround to introduce delay of execution for this test?

Setting some sleep step in separate test container comes to mind but i'm not sure if this will work properly for this case

Answer: 
As mentioned in [deHaar's answer](https://stackoverflow.com/a/68297607/5221149), the code can be improved by using `if-return` combinations.

You should however generalize your code a bit more, e.g. support all array types, not just string arrays, and support all collection types, not just lists.

Similarly, `String` implements an interface named `CharSequence`, so support that instead. That way the code will support classes like `StringBuilder` and `StringBuffer` too.

```java
public static boolean isEmpty(Object value) {
    if (value == null)
        return true;
    if (value instanceof CharSequence) // String, StringBuilder, StringBuffer, ...
        return ((CharSequence) value).isEmpty();
    if (value instanceof Collection) // List, Set, Queue, Deque, ...
        return ((Collection<?>) value).isEmpty();
    if (value instanceof Map)
        return ((Map<?,?>) value).isEmpty();
    if (value.getClass().isArray()) // All array types
        return (Array.getLength(value) == 0);
    return false;
}

```

Code was modified to to use pure built-in methods, i.e. to not rely on `ArrayUtils`.

***UPDATED:** Added support for primitive arrays.*

The above implementation is a close match to the JSP EL `empty` operator:

> 
> The `empty` operator is a prefix operator that can be used to determine if a value is null or empty.
> 
> 
> To evaluate `empty A`
> 
> 
> * If `A` is `null`, return `true`
> * Otherwise, if `A` is the empty string, then return `true`
> * Otherwise, if `A` is an empty array, then return `true`
> * Otherwise, if `A` is an empty `Map`, return `true`
> * Otherwise, if `A` is an empty `Collection`, return `true`
> * Otherwise return `false`
> 
> 
>
Java native utils gives you the abaility to check if `Objects.isNull(value)` which is **not** equivalent to empty. If you want to stick with native Java you are doing it right just beautify your code and that's it.
However this method exists in springFramework `ObjectUtils` class regardless of the type of object :

```
import org.springframework.util.ObjectUtils;

public static boolean isEmpty(Object value) {
    boolean empty = false;
if (ObjectUtils.isEmpty(value)) {
empty= true
}
return empty;
}

```

Spring Framework doc : [Class ObjectUtils](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/ObjectUtils.html)