Skip to content

Instantly share code, notes, and snippets.

package mypackage;
import mypackage.Identifiable;
import java.util.Objects;
import java.util.Set;
public final class EntitySetUtil {
private EntitySetUtil() {
// not meant to be initialized
@Sam-Kruglov
Sam-Kruglov / AxonIntegrationTest.java
Last active November 21, 2019 17:45
Axon test util for waiting for some events
class AxonIntegrationTest extends AbstractIntegrationTest {
@Test
void create_document_in_google_docs__propagate_to_ms_word_online(@Autowired EventBus eventBus){
AxonTestUtil.executeAndWaitForEvents(
() -> documentService.createGoogleDocument(...),
eventBus, 2, DocumentSavedEvent.class
);
//instead of this:
//documentService.createGoogleDocument(...);
@Sam-Kruglov
Sam-Kruglov / BookingServiceTest.java
Created April 30, 2019 19:13
Defining the sample code
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Sam-Kruglov
Sam-Kruglov / FileTimeChecker.java
Created July 2, 2018 13:07
Check reading the last modified time from a file
class FileTimeChecker{
public static void main(String[] args) throws IOException, URISyntaxException {
Path path = Files.write(Paths.get("/hey.txt"), "hey".getBytes());
File file = new File("/hey.txt");
Instant fileInstant = Instant.ofEpochMilli(file.lastModified());
System.out.println("fileInstant: " + fileInstant);
@Sam-Kruglov
Sam-Kruglov / RepeatedWordFinder.java
Created June 7, 2018 05:47
Finds the most repeated word in a text
public class RepeatedWordFinder {
public static void main(String[] args) {
System.out.println(findTheMostRepeatedWord("House, House, House, Dog, Dog, Dog, Dog, cat,cat"));
}
public static String findTheMostRepeatedWord(String s) {
return Arrays.stream(s.toLowerCase().trim().split("[\\n\\t\\r.,;:!?()]"))
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 13, 2018 12:24
JsonFilter without links
@RepositoryRestController
public class UserController {
private final UserRepository userRepository;
public UserController(final UserRepository userRepository) {
this.userRepository = userRepository;
}
@Sam-Kruglov
Sam-Kruglov / RestConfig.java
Created January 13, 2018 12:21
JsonFilter
@Component
public class RestConfig extends RepositoryRestConfigurerAdapter {
@Override
public void configureJacksonObjectMapper(final ObjectMapper objectMapper) {
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
}
}
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Created January 13, 2018 12:06
JsonFilter without links username,firstName
{
"username": "jsmith",
"firstName": "John"
}
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 13, 2018 12:05
JsonFilter without links username
{
"username": "jsmith"
}
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 13, 2018 12:16
JsonFilter without links simple
@RestController
public class UserController {
private final UserRepository userRepository;
public UserController(final UserRepository userRepository) {
this.userRepository = userRepository;
}