3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.filemove;
22 import java.util.HashSet;
23 import java.util.Optional;
25 import javax.annotation.CheckForNull;
26 import org.junit.rules.ExternalResource;
27 import org.sonar.ce.task.projectanalysis.component.Component;
29 public class MutableMovedFilesRepositoryRule extends ExternalResource implements MutableMovedFilesRepository {
31 private MutableMovedFilesRepository delegate;
32 private final Set<Component> componentsWithOriginal = new HashSet<>();
35 protected void before() {
36 this.delegate = new MutableMovedFilesRepositoryImpl();
37 this.componentsWithOriginal.clear();
41 protected void after() {
43 this.componentsWithOriginal.clear();
47 public void setOriginalFile(Component file, OriginalFile originalFile) {
48 this.delegate.setOriginalFile(file, originalFile);
49 this.componentsWithOriginal.add(file);
53 public void setOriginalPullRequestFile(Component file, OriginalFile originalFile) {
54 this.delegate.setOriginalPullRequestFile(file, originalFile);
55 this.componentsWithOriginal.add(file);
59 public Optional<OriginalFile> getOriginalFile(Component file) {
60 return this.delegate.getOriginalFile(file);
64 public Optional<OriginalFile> getOriginalPullRequestFile(Component file) {
65 return this.delegate.getOriginalPullRequestFile(file);
68 public Set<Component> getComponentsWithOriginal() {
69 return componentsWithOriginal;