Showing posts from February, 2020

How to convert UTC Date Time String to Java object and compare it ?

Use java.time.Instant;
import java.time.Instant; Instant instantStart = Instant.parse("20200229T12:00:00Z"); Instant instantEnd = Instant.parse("20200329T12:00:00Z"); Instant instantNow =; return instantNow.isAfter(instantStart) && instantNow.isBefore(instantEnd);

Favourite VIM plugin, Mark : Highlight several words in different colours simultaneously.

my favourite best best best vim pluginmarkinstallvim mark *.vmb.gz :so % dependenceingoinstallvim ingo-library*.vmb.gz :so % Usage\m

How to convert json array to java Object

Use com.amazonaws.util.json.Jackson
import com.amazonaws.util.json.Jackson; import java.util.ArrayList; import lombok.Data; @Data class DeviceList { private ArrayList<String> devices; } DeviceList deviceList = Jackson.fromJsonString( "{\"devices\":[\"Mobile\", \"Desktop\"]}", DeviceList.class);

Java Spring Bean constructor how to get call stack, backtrace

Easy wasy to print Java call stack or backtrace:
Implement a function and throw an Exception.
Call the function in the place you want to know its backtrace or callstack
And Catch the Exception then
Call Exception.getStackTrace
class MyService { public static void f() throws Exception { throw new Exception(); } void forTest() { try { f(); } catch (Exception e) { e.printStackTrace(); } } }Via this solution, we can get Bean constructor call stack easily.[tomcat:launchProperties] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [tomcat:launchProperties] at sun.reflect.NativeMethodAccessorImpl.invoke( [tomcat:launchProperties] at sun.reflect.DelegatingMethodAccessorImpl.invoke( [tomcat:launchProperties] at java.lang.reflect.Method.invoke( [tomcat:launchProperties] at…

How to use @Mock @InjectMocks

class MyService { private UserDao userDao; } import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; public class MyServiceTest { @InjectMocks private MyService myService; @Mock private UserDao userDao; @Before public void setUp() { myService = new MyService(); } }Cannot mock/spy class java.lang.String Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.lang.String Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores( at org.mockito.internal.runners.JUnit45AndHigherRunn…

How to increase terminal window buffer in IntelliJ

Command + Shift + A or Ctrl + Shift + A
Type registry, click "Registry..."
Increase the "terminal.buffer.max.lines.count" to 100000 or any number you want, the default is 1000.