-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use human-readable dataset/location types for CLI parameters
- Loading branch information
1 parent
dffca92
commit d4625f7
Showing
7 changed files
with
141 additions
and
3 deletions.
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
12 changes: 12 additions & 0 deletions
12
pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/dataset/DatasetTypeConverter.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,12 @@ | ||
package edu.colorado.cires.pace.cli.command.dataset; | ||
|
||
import edu.colorado.cires.pace.translator.DatasetType; | ||
import picocli.CommandLine.ITypeConverter; | ||
|
||
public class DatasetTypeConverter implements ITypeConverter<DatasetType> { | ||
|
||
@Override | ||
public DatasetType convert(String s) { | ||
return DatasetType.fromName(s); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-cli/src/main/java/edu/colorado/cires/pace/cli/command/dataset/LocationTypeConverter.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,12 @@ | ||
package edu.colorado.cires.pace.cli.command.dataset; | ||
|
||
import edu.colorado.cires.pace.translator.LocationType; | ||
import picocli.CommandLine.ITypeConverter; | ||
|
||
public class LocationTypeConverter implements ITypeConverter<LocationType> { | ||
|
||
@Override | ||
public LocationType convert(String s) { | ||
return LocationType.fromName(s); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...e-common-translator/src/test/java/edu/colorado/cires/pace/translator/DatasetTypeTest.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,38 @@ | ||
package edu.colorado.cires.pace.translator; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class DatasetTypeTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"sound clips,SOUND_CLIPS", | ||
"audio,AUDIO", | ||
"CPOD,CPOD", | ||
"detections,DETECTIONS", | ||
"sound level metrics,SOUND_LEVEL_METRICS", | ||
"sound propagation models,SOUND_PROPAGATION_MODELS", | ||
}) | ||
void fromName(String name, DatasetType expectedDatasetType) { | ||
assertEquals(expectedDatasetType, DatasetType.fromName(name)); | ||
} | ||
|
||
@Test | ||
void fromNameInvalid() { | ||
String name = "invalid"; | ||
Exception exception = assertThrows(IllegalArgumentException.class, () -> DatasetType.fromName(name)); | ||
assertEquals(String.format( | ||
"Invalid dataset type: %s. Was not one of: %s", | ||
name, | ||
Arrays.stream(DatasetType.values()) | ||
.map(DatasetType::getName) | ||
.collect(Collectors.joining(", ")) | ||
), exception.getMessage()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...-common-translator/src/test/java/edu/colorado/cires/pace/translator/LocationTypeTest.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,36 @@ | ||
package edu.colorado.cires.pace.translator; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class LocationTypeTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"stationary marine,STATIONARY_MARINE", | ||
"multipoint stationary marine,MULTIPOINT_STATIONARY_MARINE", | ||
"mobile marine,MOBILE_MARINE", | ||
"stationary terrestrial,STATIONARY_TERRESTRIAL" | ||
}) | ||
void fromName(String inputString, LocationType expectedType) { | ||
assertEquals(expectedType, LocationType.fromName(inputString)); | ||
} | ||
|
||
@Test | ||
void fromNameInvalidName() { | ||
String name = "invalid"; | ||
Exception exception = assertThrows(IllegalArgumentException.class, () -> LocationType.fromName(name)); | ||
assertEquals(String.format( | ||
"Invalid location type: %s. Was not one of: %s", | ||
name, | ||
Arrays.stream(LocationType.values()) | ||
.map(LocationType::getName) | ||
.collect(Collectors.joining(", ")) | ||
), exception.getMessage()); | ||
} | ||
} |