1 /*
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4 *
5 * This program and the accompanying materials are dual-licensed under
6 * either the terms of the Eclipse Public License v2.0 as published by
7 * the Eclipse Foundation
8 *
9 * or (per the licensee's choosing)
10 *
11 * under the terms of the GNU Lesser General Public License version 2.1
12 * as published by the Free Software Foundation.
13 */
14
15 package ch.qos.logback.classic.blackbox;
16
17 import ch.qos.logback.classic.LoggerContext;
18 import ch.qos.logback.core.CoreConstants;
19 import ch.qos.logback.core.util.CoreVersionUtil;
20 import ch.qos.logback.core.util.VersionUtil;
21 import org.junit.jupiter.api.Disabled;
22 import org.junit.jupiter.api.Test;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.junit.jupiter.api.Assertions.fail;
27
28 /**
29 * The WithOlderCoreVersionCheckTest class is designed to perform a validation test
30 * on the compatibility of version dependencies, specifically focusing
31 * on the interaction between "logback-classic" and "logback-core" libraries.
32 *
33 * <p>In particular, it checks that when "logback-core" is older than version 1.5.25,
34 * a NoClassDefFoundError is caught.
35 * </p>
36 *
37 * <p>Use the following command to run this test
38 * </p>
39 *
40 * <pre> mvn install; # ensure up to date compilation
41 * cd logback-classic-blackbox;
42 * mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.WithOlderCoreVersionCheckTest
43 * </pre>
44 *
45 * @since 1.5.25
46 */
47
48 public class WithOlderCoreVersionCheckTest {
49
50
51 // WARNING: do not add other tests to this file without careful consideration
52
53 LoggerContext loggerContext = new LoggerContext();
54
55 @Test
56 public void olderCoreVersionTest() {
57 String olderCoreVersion = System.getProperty("olderCore", "none");
58 assertTrue(olderCoreVersion.startsWith("1.5"));
59 try {
60 CoreVersionUtil.getCoreVersionBySelfDeclaredProperties();
61 fail("Expected Error");
62 } catch (NoClassDefFoundError e) {
63 // logback-core version is 1.5.24 or older
64 System.out.println("Got expected NoClassDefFoundError.");
65 } catch (NoSuchMethodError e) {
66 // logback-core version is 1.5.25 or older
67 System.out.println("Got expected NoSuchFieldError.");
68 }
69 }
70
71
72
73
74 // WARNING: do not add other tests to this file without careful consideration
75
76 }