### Question:
PipelineCodeHandler { public List<DocWriteRequest> processGitEvents(final Long id, final List<PipelineEvent> events) throws EntityNotFoundException { return pipelineLoader.loadEntity(id).map(entry -> { final Pipeline pipeline = entry.getEntity().getPipeline(); String indexNameForPipelineCode = String.format( "%s%s-%d", indexPrefix, pipelineCodeIndexName, pipeline.getId()); PermissionsContainer permissions = new PermissionsContainer( cloudPipelineAPIClient.loadPermissionsForEntity(id, AclClass.PIPELINE)); Map<String, List<GitEventDescription>> versionEvents = events .stream() .map(this::mapPipelineEventToGitEvent) .collect(Collectors.groupingBy(event -> event.getEventData().getVersion())); return versionEvents.values().stream() .map(e -> createRequestsForVersionEvents(e, indexNameForPipelineCode, pipeline, permissions)) .flatMap(Collection::stream) .collect(Collectors.toList()); }).orElse(Collections.emptyList()); } PipelineCodeHandler(final @Value("${sync.index.common.prefix}") String indexPrefix,
                               final @Value("${sync.pipeline-code.index.name}") String pipelineCodeIndexName,
                               final CloudPipelineAPIClient cloudPipelineAPIClient,
                               final ElasticIndexService indexService,
                               final @Value("${sync.pipeline-code.index.paths}") String pipelineFileIndexPaths,
                               final ObjectMapper objectMapper,
                               final PipelineLoader pipelineLoader,
                               final PipelineCodeMapper codeMapper,
                               final @Value("${sync.pipeline-code.default-branch}") String defaultBranchName,
                               final @Value("${sync.pipeline-code.max.bytes:10240}") Integer codeLimitBytes); List<DocWriteRequest> processGitEvents(final Long id,
                                                  final List<PipelineEvent> events); @SuppressWarnings("PMD.AvoidCatchingGenericException") List<DocWriteRequest> createPipelineCodeDocuments(final Pipeline pipeline,
                                                             final PermissionsContainer permissions,
                                                             final String revisionName,
                                                             final String indexName,
                                                             final List<String> pipelineFileIndexPaths);  }### Answer:
@Test void shouldProcessGitPushEventTest() throws EntityNotFoundException, IOException { when(pipelineLoader.loadEntity(anyLong())).thenReturn(Optional.ofNullable(container)); when(objectMapper.readValue(anyString(), ArgumentMatchers.eq(GitEventData.class))).thenReturn(gitPushEventData); when(apiClient.getTruncatedPipelineFile(anyLong(), anyString(), anyString(), anyInt())) .thenReturn(TEST_VALUE_BYTE); List<DocWriteRequest> docWriteRequests = pipelineCodeHandler.processGitEvents(1L, Collections.singletonList(expectedPipelineEvent)); assertEquals(1, docWriteRequests.size()); DocWriteRequest request = docWriteRequests.get(0); assertAll("request", () -> assertEquals(INDEX_PREFIX + INDEX_NAME + "-" + VERSION, request.index()), () -> assertEquals(VERSION + "-" + FILE_INDEX_PATHS, request.id()), () -> assertEquals(DOC_TYPE, request.type())); }
@Test void shouldProcessGitTagEventTest() throws EntityNotFoundException, IOException { when(pipelineLoader.loadEntity(anyLong())).thenReturn(Optional.ofNullable(container)); when(objectMapper.readValue(anyString(), ArgumentMatchers.eq(GitEventData.class))).thenReturn(gitTagEventData); when(apiClient.getTruncatedPipelineFile(anyLong(), anyString(), anyString(), anyInt())) .thenReturn(TEST_VALUE_BYTE); List<DocWriteRequest> docWriteRequests = pipelineCodeHandler.processGitEvents(1L, Collections.singletonList(expectedPipelineEvent)); assertEquals(1, docWriteRequests.size()); DocWriteRequest request = docWriteRequests.get(0); assertAll("request", () -> assertEquals(INDEX_PREFIX + INDEX_NAME + "-" + VERSION, request.index()), () -> assertEquals(VERSION + "-" + FILE_INDEX_PATHS, request.id()), () -> assertEquals(DOC_TYPE, request.type())); }