Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f325aa3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update the command for checking groups status to list all groups when...

Merge "Update the command for checking groups status to list all groups when no group is passed" into main
parents 3bfe305a 1e0b9a9f
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ public class ProtoLogCommandHandler extends ShellCommand {
        pw.println("    Print this help text.");
        pw.println();
        pw.println("  groups (list | status)");
        pw.println("    list - lists all ProtoLog groups registered with ProtoLog service");
        pw.println("    status <group> - print the status of a ProtoLog group");
        pw.println("    list - Lists all ProtoLog groups registered with ProtoLog service");
        pw.println("    status <group>? - Print the status of a ProtoLog group. If no group is "
                +  "passed then it prints the status of all groups.");
        pw.println();
        pw.println("  logcat (enable | disable) <group>?");
        pw.println("    Enable or disable ProtoLog to logcat. Passing no groups to the command "
@@ -127,7 +128,17 @@ public class ProtoLogCommandHandler extends ShellCommand {
                final String group = getNextArg();

                if (group == null) {
                    pw.println("Incomplete command. Use 'cmd protolog help' for guidance.");
                    final String[] allGroups = mProtoLogConfigurationService.getGroups();
                    if (allGroups.length == 0) {
                        pw.println("No ProtoLog groups registered with ProtoLog service.");
                    } else {
                        pw.println("Status for all ProtoLog groups:");
                        for (String currentGroup : allGroups) {
                            pw.println("  " + currentGroup + ": LOG_TO_LOGCAT = "
                                    + mProtoLogConfigurationService.isLoggingToLogcat(
                                    currentGroup));
                        }
                    }
                    return 0;
                }

+22 −2
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ public class ProtoLogCommandHandlerTest {

    @Test
    public void handlesGroupStatusCommandWithNoGroups() {
        Mockito.when(mProtoLogConfigurationService.getGroups())
                .thenReturn(new String[]{"MY_GROUP", "MY_OTHER_GROUP"});
        Mockito.when(mProtoLogConfigurationService.isLoggingToLogcat("MY_GROUP")).thenReturn(true);
        Mockito.when(mProtoLogConfigurationService.isLoggingToLogcat("MY_OTHER_GROUP"))
                .thenReturn(false);
        final ProtoLogCommandHandler cmdHandler =
                new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter);

@@ -136,7 +141,22 @@ public class ProtoLogCommandHandlerTest {
                FileDescriptor.err, new String[]{"groups", "status"});

        Mockito.verify(mPrintWriter, times(1))
                .println(contains("Incomplete command"));
                .println(contains("MY_GROUP: LOG_TO_LOGCAT = true"));
        Mockito.verify(mPrintWriter, times(1))
                .println(contains("MY_OTHER_GROUP: LOG_TO_LOGCAT = false"));
    }

    @Test
    public void handlesGroupStatusCommandWithNoGroupArgumentAndNoRegisteredGroups() {
        Mockito.when(mProtoLogConfigurationService.getGroups()).thenReturn(new String[]{});
        final ProtoLogCommandHandler cmdHandler =
                new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter);

        cmdHandler.exec(mMockBinder, FileDescriptor.in, FileDescriptor.out,
                FileDescriptor.err, new String[]{"groups", "status"});

        Mockito.verify(mPrintWriter, times(1))
                .println(contains("No ProtoLog groups registered"));
    }

    @Test