Skip to content

Commit

Permalink
Fix compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
srozange committed Sep 2, 2023
1 parent dea38ae commit a895e58
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 40 deletions.
12 changes: 1 addition & 11 deletions src/main/java/io/github/yupd/business/YamlRepoUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,7 @@ private static String computePathEntryDescription(YamlPathEntry entry) {
return "- [yamlpath] " + entry.getPath() + "=" + entry.getReplacement();
}

public static class YamlUpdateResult {

public final boolean updated;
public final String originalContent;
public final String newContent;

public YamlUpdateResult(boolean updated, String originalContent, String newContent) {
this.updated = updated;
this.originalContent = originalContent;
this.newContent = newContent;
}
public record YamlUpdateResult(boolean updated, String originalContent, String newContent) {

public static YamlUpdateResult updated(String originalContent, String newContent) {
return new YamlUpdateResult(true, originalContent, newContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class GithubConnector implements GitConnector {

private GHRepository githubRepository;
private final GHRepository githubRepository;

public GithubConnector(GitRepository gitRepository) {
GitHubBuilder gitHubBuilder = new GitHubBuilder().withOAuthToken(gitRepository.getToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class GitlabConnector implements GitConnector {

private GitlabAPI gitlabAPI;
private GitlabProject gitlabProject;
private final GitlabAPI gitlabAPI;
private final GitlabProject gitlabProject;

public GitlabConnector(GitRepository gitRepository) {
this.gitlabAPI = computeGitlabApi(gitRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static String readFile(String resource) {

public static void writeFile(Path path, String content) {
try {
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
Files.writeString(path, content);
} catch (IOException e) {
throw new RuntimeException("Could not write file " + path, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public boolean needToQuoteValue(String value) {
}

public static class Parameter {
Set<YAMLGenerator.Feature> withYamlGeneratorFeatures = EnumSet.noneOf(YAMLGenerator.Feature.class);
Set<YAMLGenerator.Feature> withoutYamlGeneratorFeatures = EnumSet.noneOf(YAMLGenerator.Feature.class);
Set<SerializationFeature> withSerializationFeature = EnumSet.noneOf(SerializationFeature.class);
Set<SerializationFeature> withoutSerializationFeature = EnumSet.noneOf(SerializationFeature.class);
final Set<YAMLGenerator.Feature> withYamlGeneratorFeatures = EnumSet.noneOf(YAMLGenerator.Feature.class);
final Set<YAMLGenerator.Feature> withoutYamlGeneratorFeatures = EnumSet.noneOf(YAMLGenerator.Feature.class);
final Set<SerializationFeature> withSerializationFeature = EnumSet.noneOf(SerializationFeature.class);
final Set<SerializationFeature> withoutSerializationFeature = EnumSet.noneOf(SerializationFeature.class);

public Parameter with(YAMLGenerator.Feature feature) {
withYamlGeneratorFeatures.add(feature);
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/io/github/yupd/business/YamlRepoUpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ void should_update_file_when_contents_are_different() {

// Assert
verify(connector).updateFile(parameter.getGitFile(), COMMIT_MESSAGE, NEW_CONTENT);
assertThat(result.updated).isTrue();
assertThat(result.originalContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent).isEqualTo(NEW_CONTENT);
assertThat(result.updated()).isTrue();
assertThat(result.originalContent()).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent()).isEqualTo(NEW_CONTENT);
}

@Test
Expand All @@ -97,9 +97,9 @@ void should_update_file_and_create_merge_request_when_contents_are_different() {
verify(connector).updateFile(parameter.getGitFile().builderFrom().withBranch(MR_SOURCE_BRANCH).build(), COMMIT_MESSAGE, NEW_CONTENT);
verify(connector).createMergeRequest(COMMIT_MESSAGE, MR_SOURCE_BRANCH, TARGET_BRANCH, "Proposed update in " + FILE_PATH + ":\n- [yamlpath] path=replacement\n");

assertThat(result.updated).isTrue();
assertThat(result.originalContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent).isEqualTo(NEW_CONTENT);
assertThat(result.updated()).isTrue();
assertThat(result.originalContent()).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent()).isEqualTo(NEW_CONTENT);
}

@Test
Expand All @@ -117,9 +117,9 @@ void should_update_file_when_contents_are_different_and_template_is_provided(@Te

// Assert
verify(connector).updateFile(parameter.getGitFile(), COMMIT_MESSAGE, NEW_CONTENT);
assertThat(result.updated).isTrue();
assertThat(result.originalContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent).isEqualTo(NEW_CONTENT);
assertThat(result.updated()).isTrue();
assertThat(result.originalContent()).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent()).isEqualTo(NEW_CONTENT);
}

@Test
Expand All @@ -134,9 +134,9 @@ void should_not_update_file_when_contents_are_different_and_dry_mode_is_activate

// Assert
verify(connector, never()).updateFile(parameter.getGitFile(), COMMIT_MESSAGE, NEW_CONTENT);
assertThat(result.updated).isTrue();
assertThat(result.originalContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent).isEqualTo(NEW_CONTENT);
assertThat(result.updated()).isTrue();
assertThat(result.originalContent()).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent()).isEqualTo(NEW_CONTENT);
}


Expand All @@ -152,9 +152,9 @@ void should_not_update_file_when_contents_are_the_same() {

// Assert
verify(connector, times(0)).updateFile(eq(parameter.getGitFile()), eq(COMMIT_MESSAGE), anyString());
assertThat(result.updated).isFalse();
assertThat(result.originalContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.updated()).isFalse();
assertThat(result.originalContent()).isEqualTo(ORIGINAL_CONTENT);
assertThat(result.newContent()).isEqualTo(ORIGINAL_CONTENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class YamlPathUpdatorTest {

@Test
public void testMonoDocument() throws Exception{
public void testMonoDocument() {
String content = IOUtils.readFile("YamlPathUpdator/deployment.yml");
String newContent = new YamlPathUpdator().update(content, new YamlPathEntry("*.containers[0].image", "nginx:newversion"));
String expected = IOUtils.readFile("YamlPathUpdator/deployment_expected.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void setup() {
doAnswer(yamlRepoUpdaterResultCaptor).when(yamlRepoUpdater).update(Mockito.any());
}

public class ResultCaptor<T> implements Answer {
public static class ResultCaptor<T> implements Answer {
private T result = null;
public T getResult() {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void repo_file_is_updated() {
int exitCode = yupd.run(args);

assertThat(exitCode).isEqualTo(0);
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated).isTrue();
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated()).isTrue();
}

@Test
Expand All @@ -49,7 +49,7 @@ void repo_file_is_updated_with_pull_request() {
int exitCode = yupd.run(args);

assertThat(exitCode).isEqualTo(0);
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated).isTrue();
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated()).isTrue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void repo_file_is_updated() {
int exitCode = yupd.run(args);

assertThat(exitCode).isEqualTo(0);
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated).isTrue();
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated()).isTrue();
}

@Test
Expand All @@ -49,7 +49,7 @@ void repo_file_is_updated_with_merge_request() {
int exitCode = yupd.run(args);

assertThat(exitCode).isEqualTo(0);
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated).isTrue();
assertThat(yamlRepoUpdaterResultCaptor.getResult().updated()).isTrue();
}

@Override
Expand Down

0 comments on commit a895e58

Please sign in to comment.