Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sofa-boot-project/sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.compatibility;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link VerificationResult}.
*
* @author JPSINH27
* @version VerificationResultTests, v 0.1 2024年03月02日 10:20 PM
*/
public class VerificationResultTests {

@Test
public void testEquals_SameDescriptionAndAction_ReturnsTrue() {
VerificationResult result1 = VerificationResult.notCompatible("Error", "Take action");
VerificationResult result2 = VerificationResult.notCompatible("Error", "Take action");
assertThat(result1).isEqualTo(result2);
}

@Test
public void testEquals_DifferentDescriptions_ReturnsFalse() {
VerificationResult result1 = VerificationResult.notCompatible("Error 1", "Take action");
VerificationResult result2 = VerificationResult.notCompatible("Error 2", "Take action");
assertThat(result1).isNotEqualTo(result2);
}

@Test
public void testEquals_DifferentActions_ReturnsFalse() {
VerificationResult result1 = VerificationResult.notCompatible("Error", "Take action 1");
VerificationResult result2 = VerificationResult.notCompatible("Error", "Take action 2");
assertThat(result1).isNotEqualTo(result2);
}

@Test
public void testEquals_ComparingWithNull_ReturnsFalse() {
VerificationResult result1 = VerificationResult.notCompatible("Error", "Take action");
assertThat(result1).isNotEqualTo(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.startup;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Tests for {@link StartupReporter}.
*
* @author JPSINH27
* @version StartupReporterTests.java, v 0.1 2024年01月03日 10:19 PM
*/
public class StartupReporterTests {

@Mock
ConfigurableApplicationContext mockContext;

@Mock
ConfigurableEnvironment mockEnvironment;

@BeforeEach
public void setup() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testApplicationBootFinish() {
StartupReporter startupReporter = new StartupReporter();
assertDoesNotThrow(startupReporter::applicationBootFinish);
}

@Test
public void testAddCommonStartupStat() {
StartupReporter startupReporter = new StartupReporter();
BaseStat baseStat = new BaseStat();
assertDoesNotThrow(() -> {
startupReporter.addCommonStartupStat(baseStat);
});
}

@Test
public void testDrainStartupStaticsModel() {
StartupReporter startupReporter = new StartupReporter();
assertNotNull(startupReporter.drainStartupStaticsModel());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* Tests for {@link SofaBootEnvUtils}.
Expand Down Expand Up @@ -49,4 +51,38 @@ public void testEnv() {
public void arkEnv() {
assertThat(SofaBootEnvUtils.isArkEnv()).isFalse();
}

@Test
void testIsSpringCloudBootstrapEnvironment_NullEnvironment() {
assertFalse(SofaBootEnvUtils.isSpringCloudBootstrapEnvironment(null));
}

@Test
public void testInitSpringTestEnv() {

boolean expectedTestEnv = true;

boolean actualTestEnv = isInitSpringTestEnv();

assertEquals(expectedTestEnv, actualTestEnv);
}

private boolean isInitSpringTestEnv() {
StackTraceElement[] stackTrace = new StackTraceElement[] {
new StackTraceElement("SomeClass", "someMethod", "SomeClass.java", 10),
new StackTraceElement("AnotherClass", "loadContext", "AnotherClass.java", 20),
new StackTraceElement(
"org.springframework.boot.test.context.SpringBootContextLoader", "loadContext",
"SpringBootContextLoader.java", 30) };
boolean TEST_ENV = false;
for (StackTraceElement stackTraceElement : stackTrace) {
if ("loadContext".equals(stackTraceElement.getMethodName())
&& "org.springframework.boot.test.context.SpringBootContextLoader"
.equals(stackTraceElement.getClassName())) {
TEST_ENV = true;
break;
}
}
return TEST_ENV;
}
}