Use PrintStream in ConfirmingCommand (#2140)

* Use PrintStream in ConfirmingCommand

* Add errorPrintStream

* remove unneccesary line
This commit is contained in:
sarahcaseybot
2023-09-19 12:11:18 -04:00
committed by GitHub
parent e182692a5f
commit fc1857717d
22 changed files with 79 additions and 38 deletions
@@ -198,7 +198,7 @@ public abstract class CommandTestCase<C extends Command> {
}
void assertInStderr(String... expected) {
String stderror = new String(stderr.toByteArray(), UTF_8);
String stderror = getStderrAsString();
for (String line : expected) {
assertThat(stderror).contains(line);
}
@@ -38,6 +38,7 @@ class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand
@BeforeEach
void beforeEach() {
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
command.printStream = System.out;
}
@Test
@@ -68,6 +68,7 @@ class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand>
2048,
ImmutableSet.of("secp256r1", "secp384r1"),
fakeClock);
command.printStream = System.out;
}
@Test
@@ -37,6 +37,7 @@ class CreateRegistrarGroupsCommandTest extends CommandTestCase<CreateRegistrarGr
@Test
void test_createGroupsForTwoRegistrars() throws Exception {
command.printStream = System.out;
runCommandForced("NewRegistrar", "TheRegistrar");
verify(connection)
.sendPostRequest(
@@ -521,6 +521,7 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception {
command.errorPrintStream = System.err;
runReservedListsTestOverride("common_abuse,tld_banned");
String errMsg =
"Error overridden: The reserved list(s) tld_banned "
@@ -53,6 +53,7 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
preNot2 = persistToken("prefix8ZZZhs8", null, false);
othrRed = persistToken("h97987sasdfhh", null, true);
othrNot = persistToken("asdgfho7HASDS", null, false);
command.printStream = System.out;
}
@Test
@@ -37,6 +37,8 @@ class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
command.setConnection(connection);
createTld("example");
persistNewRegistrar("acme", "ACME", Registrar.Type.REAL, 99L);
command.printStream = System.out;
command.errorPrintStream = System.err;
}
@Test
@@ -50,6 +50,7 @@ class LockDomainCommandTest extends CommandTestCase<LockDomainCommand> {
new DeterministicStringGenerator(Alphabets.BASE_58),
"adminreg",
new CloudTasksHelper(fakeClock).getTestCloudTasksUtils());
command.printStream = System.out;
}
@Test
@@ -61,6 +61,7 @@ class UniformRapidSuspensionCommandTest
ImmutableSet.of(
DomainDsData.create(1, 2, 3, new HexBinaryAdapter().unmarshal("dead")),
DomainDsData.create(4, 5, 6, new HexBinaryAdapter().unmarshal("beef")));
command.printStream = System.out;
}
private void persistDomainWithHosts(
@@ -53,6 +53,7 @@ class UnlockDomainCommandTest extends CommandTestCase<UnlockDomainCommand> {
new DeterministicStringGenerator(Alphabets.BASE_58),
"adminreg",
new CloudTasksHelper(fakeClock).getTestCloudTasksUtils());
command.printStream = System.out;
}
private Domain persistLockedDomain(String domainName, String registrarId) {
@@ -55,6 +55,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
createTld("tld");
fakeClock.setTo(DateTime.parse("2016-12-06T13:55:01Z"));
command.clock = fakeClock;
command.printStream = System.out;
}
@Test
@@ -178,6 +179,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
@Test
void test_varietyOfInvalidDomains_displaysErrors() {
command.errorPrintStream = System.err;
DateTime now = fakeClock.nowUtc();
persistResource(
DatabaseHelper.newDomain("deleting.tld")
@@ -1048,6 +1048,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test
void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception {
command.errorPrintStream = System.err;
runReservedListsTestOverride("common_abuse,tld_banned");
String errMsg =
"Error overridden: The reserved list(s) tld_banned "
@@ -34,6 +34,7 @@ import google.registry.model.reporting.HistoryEntryDao;
import google.registry.persistence.VKey;
import google.registry.testing.DatabaseHelper;
import google.registry.tools.CommandTestCase;
import java.io.PrintStream;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.junit.jupiter.api.BeforeEach;
@@ -59,6 +60,7 @@ public class CreateCancellationsForBillingEventsCommandTest
fakeClock.nowUtc(),
fakeClock.nowUtc().plusYears(2));
billingEventToCancel = createBillingEvent();
command.printStream = System.out;
}
@Test
@@ -97,8 +99,10 @@ public class CreateCancellationsForBillingEventsCommandTest
@Test
void testAlreadyCancelled() throws Exception {
// multiple runs / cancellations should be a no-op
command.printStream = new PrintStream(tmpDir.resolve("test.txt").toFile());
runCommandForced(String.valueOf(billingEventToCancel.getId()));
assertBillingEventCancelled();
command.printStream = System.out;
runCommandForced(String.valueOf(billingEventToCancel.getId()));
assertBillingEventCancelled();
assertThat(DatabaseHelper.loadAllOf(BillingCancellation.class)).hasSize(1);