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.fail;
26
27 /**
28 * The VersionCheckTest class is designed to perform a validation test
29 * on the compatibility of version dependencies, specifically focusing
30 * on the interaction between "logback-classic" and "logback-core" libraries.
31 *
32 * <p>In particular, it checks that when "logback-core" is older than version 1.5.25,
33 * a NoClassDefFoundError is caught.
34 * </p>
35 *
36 * <p>Use the following command to run this test
37 * </p>
38 *
39 * <pre> cd logback-classic-blackbox;
40 * mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.VersionCheckTest
41 * </pre>
42 *
43 * @since 1.5.25
44 */
45
46 public class VersionCheckTest {
47
48
49 // WARNING: do not add other tests to this file
50
51 LoggerContext loggerContext = new LoggerContext();
52
53 /**
54 *
55 * Assertions:
56 * 1. Verifies that the "olderCore" property matches the expected value "1.5.20".
57 * 2. Ensures that a {@link NoClassDefFoundError} is thrown in presence of logback-core version
58 * 1.5.25 or older.
59 */
60 @Test
61 @Disabled
62 public void versionTest() {
63 String olderCoreVersion = System.getProperty("olderCore", "none");
64 //assertEquals("1.5.20", olderCoreVersion);
65 assertEquals("1.5.25", olderCoreVersion);
66 try {
67 VersionUtil.checkForVersionEquality(loggerContext, this.getClass(), CoreConstants.class, "logback-classic", "logback-core");
68 fail("Expected NoClassDefFoundError");
69 } catch (NoClassDefFoundError e) {
70 // logback-core version is older than 1.5.25
71 System.out.println("Got expected NoClassDefFoundError.");
72 }
73 }
74
75 @Test
76 public void otherVersionTest() {
77 String olderCoreVersion = System.getProperty("olderCore", "none");
78 //assertEquals("1.5.20", olderCoreVersion);
79 assertEquals("1.5.25", olderCoreVersion);
80 try {
81 CoreVersionUtil.getCoreVersionBySelfDeclaredProperties();
82 fail("Expected Error");
83 } catch (NoClassDefFoundError e) {
84 // logback-core version is 1.5.24 or older
85 System.out.println("Got expected NoClassDefFoundError.");
86 } catch (NoSuchMethodError e) {
87 // logback-core version is 1.5.25 or older
88 System.out.println("Got expected NoSuchFieldError.");
89 }
90 }
91
92
93
94
95 // WARNING: do not add other tests to this file
96
97 }