Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo committed Aug 7, 2024
1 parent 764e385 commit d1e6b95
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/mageddo/dnsproxyserver/server/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ public void start() {
this.startupEvents.forEach(StartupEvent::onStart);
}
if (shouldStartDnsServer()) {
this.dnsServerStarter.start();
this.startDnsServer();
}
this.startWebServer();
}

void startWebServer() {
this.webServer.start(Configs.getInstance().getWebServerPort());
}

void startDnsServer() {
this.dnsServerStarter.start();
}

private static boolean shouldStartDnsServer() {
return !isTest() || isMustStartFlagActive();
}
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/com/mageddo/dnsproxyserver/server/StarterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mageddo.dnsproxyserver.server;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Set;

import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class StarterTest {

final Starter starter = spy(new Starter(null, null, Set.of()));

@Test
void wontStartInTestMode() {

doNothing().when(this.starter).startWebServer();
doNothing().when(this.starter).startDnsServer();

this.starter.start();

verify(this.starter, never()).startDnsServer();
verify(this.starter).startWebServer();
}


@Test
void mustStartWhenInTestModeAndFlagForced() {

Starter.setMustStartFlagActive(true);

doNothing().when(this.starter).startWebServer();
doNothing().when(this.starter).startDnsServer();

this.starter.start();

verify(this.starter).startDnsServer();
verify(this.starter).startWebServer();

Starter.setMustStartFlagActive(false);
}
}

0 comments on commit d1e6b95

Please sign in to comment.