Skip to content

Commit

Permalink
post-review: move factory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Sep 25, 2024
1 parent 2d24b22 commit bb74e6e
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ class JmxScraperTest {
void shouldThrowExceptionWhenInvalidCommandLineArgsProvided() {
// Given
List<String> emptyArgs = Collections.singletonList("-nonExistentOption");
JmxScraperConfigFactory configFactoryMock = mock(JmxScraperConfigFactory.class);

// When and Then
assertThatThrownBy(() -> JmxScraper.createConfigFromArgs(emptyArgs, configFactoryMock))
assertThatThrownBy(() -> JmxScraper.createConfigFromArgs(emptyArgs))
.isInstanceOf(ArgumentsParsingException.class);
}

@Test
void shouldThrowExceptionWhenTooManyCommandLineArgsProvided() {
// Given
List<String> args = Arrays.asList("-config", "path", "-nonExistentOption");
JmxScraperConfigFactory configFactoryMock = mock(JmxScraperConfigFactory.class);

// When and Then
assertThatThrownBy(() -> JmxScraper.createConfigFromArgs(args, configFactoryMock))
assertThatThrownBy(() -> JmxScraper.createConfigFromArgs(args))
.isInstanceOf(ArgumentsParsingException.class);
}

Expand All @@ -49,10 +47,9 @@ void shouldCreateConfig_propertiesLoadedFromFile()
String filePath =
ClassLoader.getSystemClassLoader().getResource("validConfig.properties").getPath();
List<String> args = Arrays.asList("-config", filePath);
JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory();

// When
JmxScraperConfig config = JmxScraper.createConfigFromArgs(args, configFactory);
JmxScraperConfig config = JmxScraper.createConfigFromArgs(args);

// Then
assertThat(config).isNotNull();
Expand All @@ -67,10 +64,9 @@ void shouldCreateConfig_propertiesLoadedFromStdIn()
// Given
System.setIn(stream);
List<String> args = Arrays.asList("-config", "-");
JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory();

// When
JmxScraperConfig config = JmxScraper.createConfigFromArgs(args, configFactory);
JmxScraperConfig config = JmxScraper.createConfigFromArgs(args);

// Then
assertThat(config).isNotNull();
Expand Down

0 comments on commit bb74e6e

Please sign in to comment.