@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 testAddIsIdempotent() { TestLogger printer = new TestLogger(); assertThat(JobConfig.addLogger(printer)).isTrue(); assertThat(JobConfig.addLogger(printer)).isFalse(); }
@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 testRemove() { TestLogger printer = new TestLogger(); assertThat(JobConfig.addLogger(printer)).isTrue(); JobConfig.removeLogger(printer); assertThat(JobConfig.addLogger(printer)).isTrue(); }
@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"); }