Skip to content
Advertisement

How to abstract away java.time.Clock for testing purposes in Spring

I have a question with regards to the question Time dependent unit tests Let’s say I build Spring application which contains service interface and its implementation If I want to change clock in test, I would have to “pollute” production code and interface with e.g. setClock method as follows: In test, I can invoke, e.g.: How can I abstract away

How to peek on an Optional?

I want to use the fluent api of Optional and apply two Consumers to it. I’m dreaming about something like this: How do I apply several Consumers to an Optional? Answer You can use this syntax:

How to parse JSON String to java object with jackson?

I am currently having trouble trying to parse this VCAP_SERVICES to java objects. I do not quite understand how to structure the POJO to allow it to map the values from the json string. Can someone please help me structure my pojo so that it is aligns with the json string? I want to create objects for both of the

Spring deserializes a LocalDate in a @RequestBody differently from one in a @RequestParam – why, and can they be the same?

QUESTION: Spring appears to use different deserialization methods for LocalDate depending on whether it appears in a @RequestBody or a request @ReqestParam – is this correct, and if so, is there a way to configure them to be the same throughout an application? BACKGROUND: In my @RestController, I have two methods – one GET, and one POST. The GET expects

What is the equivalent way to do Ordering.lexicographical() in Java 8 Comparator?

Is there a way to implement Ordering.lexicographical() with Java 8 Comparator? Comparator.thenCompare seems to be limited in this Answer Seemingly not, no. As a result, Guava still provides this functionality, but in the new class Comparators: https://guava.dev/releases/snapshot/api/docs/com/google/common/collect/Comparators.html#lexicographical(java.util.Comparator). Note that Guava generally does a good job telling you whether and how to migrate off of it to new Java features, so

Spring boot app terminated at startup

I have created a spring boot project using spring initilizer. I use spring-boot-cli version v1.5.3.RELEASE. I just try to run: But my server won’t stay running, it is closing automatically. On port 8080 I have no other connection: LATER EDIT: Still not working. EDIT: here is the pom file: Answer I added in the pom file a tomcat dependency and

Advertisement