diff options
Diffstat (limited to 'core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java')
-rw-r--r-- | core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java b/core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java index b88c36f20bc6..0e09dd3e9aab 100644 --- a/core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java +++ b/core/tests/coretests/src/android/app/timedetector/NetworkTimeSuggestionTest.java @@ -18,10 +18,12 @@ package android.app.timedetector; import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable; import static android.app.timezonedetector.ParcelableTestSupport.roundTripParcelable; +import static android.app.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import android.os.ShellCommand; import android.os.TimestampedValue; import org.junit.Test; @@ -63,4 +65,36 @@ public class NetworkTimeSuggestionTest { NetworkTimeSuggestion rtSuggestion = roundTripParcelable(suggestion); assertEquals(suggestion.getDebugInfo(), rtSuggestion.getDebugInfo()); } + + @Test(expected = IllegalArgumentException.class) + public void testParseCommandLineArg_noReferenceTime() { + ShellCommand testShellCommand = createShellCommandWithArgsAndOptions( + "--unix_epoch_time 12345"); + NetworkTimeSuggestion.parseCommandLineArg(testShellCommand); + } + + @Test(expected = IllegalArgumentException.class) + public void testParseCommandLineArg_noUnixEpochTime() { + ShellCommand testShellCommand = createShellCommandWithArgsAndOptions( + "--reference_time 54321"); + NetworkTimeSuggestion.parseCommandLineArg(testShellCommand); + } + + @Test + public void testParseCommandLineArg_validSuggestion() { + ShellCommand testShellCommand = createShellCommandWithArgsAndOptions( + "--reference_time 54321 --unix_epoch_time 12345"); + TimestampedValue<Long> timeSignal = new TimestampedValue<>(54321L, 12345L); + NetworkTimeSuggestion expectedSuggestion = new NetworkTimeSuggestion(timeSignal); + NetworkTimeSuggestion actualSuggestion = + NetworkTimeSuggestion.parseCommandLineArg(testShellCommand); + assertEquals(expectedSuggestion, actualSuggestion); + } + + @Test(expected = IllegalArgumentException.class) + public void testParseCommandLineArg_unknownArgument() { + ShellCommand testShellCommand = createShellCommandWithArgsAndOptions( + "--reference_time 54321 --unix_epoch_time 12345 --bad_arg 0"); + NetworkTimeSuggestion.parseCommandLineArg(testShellCommand); + } } |