SteemJUtils { public static <T> T setIfNotNull(T objectToSet, String message) { return setIfNotNull(objectToSet, message, null); } private  SteemJUtils(); static boolean verifyJsonString(String customJsonString); static byte[] transformShortToByteArray(int shortValue); static byte[] transformLongToByteArray(long longValue); static byte transformByteToLittleEndian(byte byteValue); static byte[] transformStringToVarIntByteArray(String string); static byte[] transformIntToVarIntByteArray(int intValue); static byte[] transformShortToByteArray(short shortValue); static byte[] transformIntToByteArray(int intValue); static byte[] transformBooleanToByteArray(boolean boolValue); static byte[] transformLongToVarIntByteArray(long longValue); static String transformDateToString(Date date); static long transformStringToTimestamp(String dateTime); static String privateKeyToWIF(ECKey privateKey); static T setIfNotNull(T objectToSet, String message); static T setIfNotNull(T objectToSet, String message, @Nullable T defaultValue); static T setIfNotNull(T objectToSet, @Nullable T defaultValue); static List<T> setIfNotNullAndNotEmpty(List<T> collectionToSet, String message);  }
@Test public void testSetIfNotNull() { Object objectToSet = new Object(); Object nullObject = null; Object defaultValue = new Object(); String exampleMessage = "TestMessage"; assertThat(SteemJUtils.setIfNotNull(objectToSet, exampleMessage), equalTo(objectToSet)); try { SteemJUtils.setIfNotNull(nullObject, exampleMessage); fail(); } catch (InvalidParameterException e) { assertThat(e.getMessage(), equalTo(exampleMessage)); } assertThat(SteemJUtils.setIfNotNull(objectToSet, defaultValue), equalTo(objectToSet)); assertThat(SteemJUtils.setIfNotNull(nullObject, defaultValue), equalTo(defaultValue)); try { SteemJUtils.setIfNotNull(nullObject, nullObject); fail(); } catch (InvalidParameterException e) { assertThat(e.getMessage(), equalTo("Both, the objectToSet and the default value are null.")); } }