-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use different test execution phase instead of before class
- Loading branch information
Showing
11 changed files
with
64 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../test/java/org/grpcmock/springboot/TestExecutionListenerAllowsOtherBeforeActionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.grpcmock.springboot; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.grpcmock.springboot.TestExecutionListenerAllowsOtherBeforeActionsTest.ApplicationEventListener; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
|
||
/** | ||
* @author Fadelis | ||
*/ | ||
@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.NONE) | ||
@AutoConfigureGrpcMock | ||
@DirtiesContext | ||
@Import(ApplicationEventListener.class) | ||
class TestExecutionListenerAllowsOtherBeforeActionsTest extends TestBase { | ||
|
||
private static boolean beforeAllRunSuccessful; | ||
private static boolean applicationContextInitialized; | ||
|
||
@BeforeAll | ||
static void checkIfApplicationContextNotInitialized() { | ||
beforeAllRunSuccessful = !applicationContextInitialized; | ||
} | ||
|
||
@Test | ||
void should_run_before_all_action_before_application_context_is_available() { | ||
// check that beforeAll method was actually run before the application context was initialized | ||
assertThat(beforeAllRunSuccessful).isTrue(); | ||
// check that grpc mock instance is running | ||
simpleHealthCheckRequest(); | ||
} | ||
|
||
|
||
public static class ApplicationEventListener implements ApplicationListener<ContextRefreshedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
applicationContextInitialized = true; | ||
} | ||
} | ||
} |