@Before public void setup() { JobConfig.addLogger(jobLogger); holder = new JobCreatorHolder(); }
@Override protected void before() throws Throwable { JobIntentServiceReset.reset(); JobConfig.addLogger(TestLogger.INSTANCE); JobConfig.setSkipJobReschedule(true); mManager = JobManager.create(mContext); mManager.addJobCreator(mJobCreator); }
@Test public void testSingleCustomLoggerAddAfter() { JobCat cat = new JobCat("Tag"); TestLogger printer = new TestLogger(); assertThat(JobConfig.addLogger(printer)).isTrue(); cat.d("hello"); cat.w("world"); assertThat(printer.mMessages).containsExactly("hello", "world"); }
@Test public void test100Loggers() { JobCat cat1 = new JobCat("Tag1"); List<TestLogger> printers = new ArrayList<>(); for (int i = 0; i < 100; i++) { TestLogger printer = new TestLogger(); assertThat(JobConfig.addLogger(printer)).isTrue(); printers.add(printer); } JobCat cat2 = new JobCat("Tag2"); cat1.d("hello"); cat2.w("world"); for (TestLogger printer : printers) { assertThat(printer.mTags).containsExactly("Tag1", "Tag2"); assertThat(printer.mMessages).containsExactly("hello", "world"); } TestLogger removedPrinter = printers.remove(50); JobConfig.removeLogger(removedPrinter); cat1.d("third"); for (TestLogger printer : printers) { assertThat(printer.mTags).containsExactly("Tag1", "Tag2", "Tag1"); assertThat(printer.mMessages).containsExactly("hello", "world", "third"); } assertThat(removedPrinter.mTags).containsExactly("Tag1", "Tag2"); assertThat(removedPrinter.mMessages).containsExactly("hello", "world"); }
@Test public void testSingleCustomLoggerAddBefore() { TestLogger printer = new TestLogger(); assertThat(JobConfig.addLogger(printer)).isTrue(); JobCat cat = new JobCat("Tag"); cat.d("hello"); cat.w("world"); assertThat(printer.mMessages).contains("hello", "world"); }
@Test public void testWarningWhenTooFarInTheFuture() { class TestPrinter implements JobLogger { private final List<String> mMessages = new ArrayList<>(); @Override public void log(int priority, @NonNull String tag, @NonNull String message, @Nullable Throwable t) { mMessages.add(message); } } TestPrinter testPrinter = new TestPrinter(); JobConfig.addLogger(testPrinter); getBuilder().setExecutionWindow(TimeUnit.DAYS.toMillis(366), TimeUnit.DAYS.toMillis(367)).build(); getBuilder().setExact(TimeUnit.DAYS.toMillis(366)).build(); JobConfig.removeLogger(testPrinter); assertThat(testPrinter.mMessages).containsSubsequence( "Warning: job with tag SuccessJob scheduled over a year in the future", "Warning: job with tag SuccessJob scheduled over a year in the future" ); }