-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: AbstractPlugin supports all features #191
Merged
kaklakariada
merged 6 commits into
develop
from
bugfix/abstract-plugin-supports-all-features
Jun 27, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf0e06d
Add missing plugin feature
kaklakariada 2bfd6e5
Fix supports() method of AbstractPlugin always returning true
kaklakariada c5e71fe
Add changelog entry
kaklakariada d61381f
Format sources, reduce visibility
kaklakariada 340fc3c
Bugfix: use correct feature type
kaklakariada 49db282
Log CSV exporter target file
kaklakariada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
api/src/test/java/org/itsallcode/whiterabbit/api/AbstractPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.itsallcode.whiterabbit.api; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.itsallcode.whiterabbit.api.features.PluginFeature; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AbstractPluginTest | ||
{ | ||
private static final String PLUGIN_ID = "testing-plugin"; | ||
|
||
@Mock | ||
SupportedFeature supportedFeatureMock; | ||
|
||
private TestingAbstractPlugin plugin; | ||
|
||
@BeforeEach | ||
void setUp() | ||
{ | ||
plugin = new TestingAbstractPlugin(); | ||
} | ||
|
||
@Test | ||
void supportsReturnsTrueForSupportedFeature() | ||
{ | ||
assertThat(plugin.supports(SupportedFeature.class)).isTrue(); | ||
} | ||
|
||
@Test | ||
void supportsReturnsFalseForUnsupportedFeature() | ||
{ | ||
assertThat(plugin.supports(UnsupportedFeature.class)).isFalse(); | ||
} | ||
|
||
@Test | ||
void gettingUnsupportedFeatureThrowsException() | ||
{ | ||
assertThatThrownBy(() -> plugin.getFeature(UnsupportedFeature.class)) | ||
.isInstanceOf(IllegalArgumentException.class).hasMessage( | ||
"Feature " + UnsupportedFeature.class.getName() + " not supported by plugin " + PLUGIN_ID); | ||
} | ||
|
||
@Test | ||
void gettingSupportedFeatureWorks() | ||
{ | ||
assertThat(plugin.getFeature(SupportedFeature.class)).isSameAs(supportedFeatureMock); | ||
} | ||
|
||
@Test | ||
void getPluginId() | ||
{ | ||
assertThat(plugin.getId()).isEqualTo(PLUGIN_ID); | ||
} | ||
|
||
private interface SupportedFeature extends PluginFeature | ||
{ | ||
|
||
} | ||
|
||
private interface UnsupportedFeature extends PluginFeature | ||
{ | ||
|
||
} | ||
|
||
private class TestingAbstractPlugin extends AbstractPlugin<SupportedFeature> | ||
{ | ||
protected TestingAbstractPlugin() | ||
{ | ||
super(PLUGIN_ID, SupportedFeature.class); | ||
} | ||
|
||
@Override | ||
protected SupportedFeature createInstance() | ||
{ | ||
return supportedFeatureMock; | ||
} | ||
} | ||
} |
24 changes: 14 additions & 10 deletions
24
plugins/csv/src/main/java/org/itsallcode/whiterabbit/plugin/csv/CSVConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
package org.itsallcode.whiterabbit.plugin.csv; | ||
|
||
import org.itsallcode.whiterabbit.api.PluginConfiguration; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class CSVConfig { | ||
import org.itsallcode.whiterabbit.api.PluginConfiguration; | ||
|
||
class CSVConfig | ||
{ | ||
private final boolean filterForWeekDays; | ||
private final Path outPath; | ||
private final String separator; | ||
|
||
public boolean getFilterForWeekDays() { | ||
boolean getFilterForWeekDays() | ||
{ | ||
return filterForWeekDays; | ||
} | ||
|
||
public Path getOutPath() { | ||
Path getOutPath() | ||
{ | ||
return outPath; | ||
} | ||
|
||
public String getSeparator() { | ||
String getSeparator() | ||
{ | ||
return separator; | ||
} | ||
|
||
public CSVConfig(PluginConfiguration config) { | ||
CSVConfig(PluginConfiguration config) | ||
{ | ||
final String defaultPath = System.getProperty("user.home"); | ||
this.outPath = Paths.get(config.getOptionalValue("destination").orElse(defaultPath)); | ||
this.separator = config.getOptionalValue("separator").orElse(","); | ||
this.filterForWeekDays = | ||
config.getOptionalValue("filter_for_weekdays") | ||
.orElse("false").equalsIgnoreCase("true"); | ||
this.filterForWeekDays = config.getOptionalValue("filter_for_weekdays") | ||
.orElse("false").equalsIgnoreCase("true"); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
plugins/csv/src/main/java/org/itsallcode/whiterabbit/plugin/csv/CSVExporterPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package org.itsallcode.whiterabbit.plugin.csv; | ||
|
||
import org.itsallcode.whiterabbit.api.AbstractPlugin; | ||
import org.itsallcode.whiterabbit.api.features.ProjectReportExporter; | ||
|
||
public class CSVExporterPlugin extends AbstractPlugin<CSVProjectReportExporter> | ||
public class CSVExporterPlugin extends AbstractPlugin<ProjectReportExporter> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrong class was used here. |
||
{ | ||
public CSVExporterPlugin() | ||
{ | ||
super("csv", CSVProjectReportExporter.class); | ||
super("csv", ProjectReportExporter.class); | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
plugins/csv/src/test/java/org/itsallcode/whiterabbit/plugin/csv/CSVExporterPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.itsallcode.whiterabbit.plugin.csv; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.itsallcode.whiterabbit.api.PluginConfiguration; | ||
import org.itsallcode.whiterabbit.api.features.Holidays; | ||
import org.itsallcode.whiterabbit.api.features.ProjectReportExporter; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CSVExporterPluginTest | ||
{ | ||
@Mock | ||
private PluginConfiguration configMock; | ||
|
||
private CSVExporterPlugin plugin; | ||
|
||
@BeforeEach | ||
void setUp() | ||
{ | ||
plugin = new CSVExporterPlugin(); | ||
} | ||
|
||
@Test | ||
void pluginSupportsProjectReportExporterFeature() | ||
{ | ||
assertThat(plugin.supports(ProjectReportExporter.class)).isTrue(); | ||
} | ||
|
||
@Test | ||
void pluginDoesNotSupportHolidaysFeature() | ||
{ | ||
assertThat(plugin.supports(Holidays.class)).isFalse(); | ||
} | ||
|
||
@Test | ||
void getFeature() | ||
{ | ||
plugin.init(configMock); | ||
assertThat(plugin.getFeature(ProjectReportExporter.class)).isNotNull(); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...ain/java/org/itsallcode/whiterabbit/plugin/holidaycalculator/HolidayCalculatorPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the root cause of the bug ;)