[JAVA-22519] Created new module libraries-stream and added 5 articles (#15403)
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.jcommander.helloworld;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
|
||||
public class HelloWorldAppUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenJCommanderInvokedWithArgs_thenArgsParsed() {
|
||||
|
||||
HelloWorldArgs jArgs = new HelloWorldArgs();
|
||||
JCommander helloCmd = JCommander
|
||||
.newBuilder()
|
||||
.addObject(jArgs)
|
||||
.build();
|
||||
|
||||
// when
|
||||
String[] argv = new String[] {
|
||||
"--name", "JavaWorld"
|
||||
};
|
||||
helloCmd.parse(argv);
|
||||
|
||||
// then
|
||||
assertEquals("JavaWorld", jArgs.getName());
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.baeldung.jcommander.usagebilling.cli;
|
||||
|
||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
|
||||
public class FetchCurrentChargesCommandUnitTest {
|
||||
|
||||
private JCommander jc = JCommander.newBuilder()
|
||||
.addObject(new FetchCurrentChargesCommand())
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void whenParsedMultipleSubscriptionsParameter_thenParameterSubscriptionsIsPopulated() {
|
||||
FetchCurrentChargesCommand cmd = (FetchCurrentChargesCommand) jc
|
||||
.getObjects()
|
||||
.get(0);
|
||||
|
||||
jc.parse(new String[] {
|
||||
"-C", "cb898e7a-f2a0-46d2-9a09-531f1cee1839",
|
||||
"-S", "subscriptionA001",
|
||||
"-S", "subscriptionA002",
|
||||
"-S", "subscriptionA003",
|
||||
});
|
||||
|
||||
assertThat(cmd.getSubscriptionIds(),
|
||||
contains("subscriptionA001", "subscriptionA002", "subscriptionA003"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenParsedSubscriptionsColonSeparatedParameter_thenParameterSubscriptionsIsPopulated() {
|
||||
FetchCurrentChargesCommand cmd = (FetchCurrentChargesCommand) jc
|
||||
.getObjects()
|
||||
.get(0);
|
||||
|
||||
jc.parse(new String[] {
|
||||
"-C", "cb898e7a-f2a0-46d2-9a09-531f1cee1839",
|
||||
"-S", "subscriptionA001:subscriptionA002:subscriptionA003",
|
||||
});
|
||||
|
||||
assertThat(cmd.getSubscriptionIds(),
|
||||
contains("subscriptionA001", "subscriptionA002", "subscriptionA003"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenParsedSubscriptionsWithVariableArity_thenParameterSubscriptionsIsPopulated() {
|
||||
FetchCurrentChargesCommand cmd = (FetchCurrentChargesCommand) jc
|
||||
.getObjects()
|
||||
.get(0);
|
||||
|
||||
jc.parse(new String[] {
|
||||
"-C", "cb898e7a-f2a0-46d2-9a09-531f1cee1839",
|
||||
"-S", "subscriptionA001", "subscriptionA002", "subscriptionA003",
|
||||
});
|
||||
|
||||
assertThat(cmd.getSubscriptionIds(),
|
||||
contains("subscriptionA001", "subscriptionA002", "subscriptionA003"));
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.baeldung.jcommander.usagebilling.cli;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
import com.beust.jcommander.ParameterException;
|
||||
|
||||
public class SubmitUsageCommandUnitTest {
|
||||
|
||||
private JCommander jc = JCommander.newBuilder()
|
||||
.addObject(new SubmitUsageCommand())
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void whenParsedCustomerParameter_thenParameterOfTypeStringIsPopulated() {
|
||||
jc.parse(new String[] {
|
||||
"--customer", "cb898e7a-f2a0-46d2-9a09-531f1cee1839",
|
||||
"--subscription", "subscriptionPQRMN001",
|
||||
"--pricing-type", "PRE_RATED",
|
||||
"--timestamp", "2019-10-03T10:58:00",
|
||||
"--quantity", "7",
|
||||
"--price", "24.56"
|
||||
});
|
||||
|
||||
SubmitUsageCommand cmd = (SubmitUsageCommand) jc
|
||||
.getObjects()
|
||||
.get(0);
|
||||
assertEquals("cb898e7a-f2a0-46d2-9a09-531f1cee1839", cmd.getCustomerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenParsedTimestampParameter_thenParameterOfTypeInstantIsPopulated() {
|
||||
jc.parse(new String[] {
|
||||
"--customer", "cb898e7a-f2a0-46d2-9a09-531f1cee1839",
|
||||
"--subscription", "subscriptionPQRMN001",
|
||||
"--pricing-type", "PRE_RATED",
|
||||
"--timestamp", "2019-10-03T10:58:00",
|
||||
"--quantity", "7",
|
||||
"--price", "24.56"
|
||||
});
|
||||
|
||||
SubmitUsageCommand cmd = (SubmitUsageCommand) jc
|
||||
.getObjects()
|
||||
.get(0);
|
||||
assertEquals("2019-10-03T10:58:00Z", cmd
|
||||
.getTimestamp()
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Test(expected = ParameterException.class)
|
||||
public void whenParsedCustomerIdNotUUID_thenParameterException() {
|
||||
jc.parse(new String[] {
|
||||
"--customer", "customer001",
|
||||
"--subscription", "subscriptionPQRMN001",
|
||||
"--pricing-type", "PRE_RATED",
|
||||
"--timestamp", "2019-10-03T10:58:00",
|
||||
"--quantity", "7",
|
||||
"--price", "24.56"
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user