This file contains hidden or 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
| package com.mcy.rule.temporaryFolder; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Test; |
This file contains hidden or 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
| public class TemporaryFolderTest { | |
| @Rule | |
| public TemporaryFolder folder = new TemporaryFolder(); | |
| @Test | |
| public void test() throws IOException { | |
| File file = folder.newFile("deneme.txt"); | |
| assertThat(file).isFile(); | |
| } |
This file contains hidden or 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
| public class WithoutTimeoutRuleTest { | |
| @Test(timeout = 1000) | |
| public void test() throws InterruptedException { | |
| Thread.sleep(1100); | |
| } | |
| @Test(timeout = 1000) | |
| public void test2() throws InterruptedException { | |
| Thread.sleep(1100); |
This file contains hidden or 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
| public class TimeoutRuleTest { | |
| @Rule | |
| public Timeout timeout = new Timeout(1000, TimeUnit.MILLISECONDS); | |
| @Test | |
| public void test() throws InterruptedException { | |
| Thread.sleep(1100); | |
| } |
This file contains hidden or 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
| public class RuleChainTest { | |
| @Rule | |
| public final TestRule chain = RuleChain.outerRule(new LoggingRule("cevreleyen rule")) | |
| .around(new LoggingRule("ikinci rule")) | |
| .around(new LoggingRule("ucuncu rule")); | |
| @Test | |
| public void example() { | |
| assertTrue(true); | |
| } |
This file contains hidden or 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
| public class TestWatcherTest { | |
| private static String watchedLog; | |
| @Rule | |
| public final TestRule watchman = new TestWatcher() { | |
| @Override | |
| public Statement apply(Statement base, Description description) { | |
| return super.apply(base, description); | |
| } |
This file contains hidden or 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
| public class LoggingRule implements TestRule { | |
| private String value; | |
| public LoggingRule(String value) { | |
| super(); | |
| this.value = value; | |
| } | |
| public Statement apply(final Statement st, Description desc) { |
This file contains hidden or 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
| public interface AnyService { | |
| public String deneme(String val); | |
| } |
This file contains hidden or 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
| public class MockInitRuleTest { | |
| // Mesela bu sekilde sadece rule ile mocklarin ayaga kaldirilmasini | |
| // saglayabilinir. | |
| // Bu rule'u extend eden diger rule'larda behaviour'lar tanimlanabilir | |
| @Rule | |
| public MockInitRule rule = new MockInitRule(this); | |
| @Mock |
This file contains hidden or 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
| public class MockInitRule implements TestRule{ | |
| private final Object target; | |
| public MockInitRule(Object target) { | |
| super(); | |
| this.target = target; | |
| } | |
| public Statement apply(final Statement st, Description desc) { |