Skip to content

Instantly share code, notes, and snippets.

@maciejwalkowiak
Created March 2, 2022 18:25
Show Gist options
  • Save maciejwalkowiak/24ef8513b699bf6d181a190ec46d1f6d to your computer and use it in GitHub Desktop.
Save maciejwalkowiak/24ef8513b699bf6d181a190ec46d1f6d to your computer and use it in GitHub Desktop.
public class VatChecker {
static VatCheckResponse checkVat(String vat) {
return null;
}
}
class VatCheckResponse {
private VatCheckResponse() {}
boolean isValid() {
return true;
}
}
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
class VatCheckerTests {
@Test
void foo() {
try (MockedStatic<VatChecker> vatChecker = Mockito.mockStatic(VatChecker.class, Mockito.RETURNS_DEEP_STUBS)) {
vatChecker.when(() -> VatChecker.checkVat(any()).isValid()).thenReturn(false);
assertThat(VatChecker.checkVat("asd").isValid()).isFalse();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment