Last active
August 29, 2015 14:08
-
-
Save up1/7a98333717b81e966d00 to your computer and use it in GitHub Desktop.
Demo :: Test Isolation
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
FizzBuzz fizzBuzz = new FizzBuzz(); | |
@Test | |
public void กรณีอื่นๆ() { | |
assertEquals("1", fizzBuzz.say(1)); | |
} |
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
class MockCounter implements CounterPersistence { | |
private int expectedNumber; | |
private boolean done; | |
public MockCounter(int expectedNumber) { | |
this.expectedNumber = expectedNumber; | |
} | |
public void setNumber(int number) { | |
assertEquals(expectedNumber, number); | |
done = true; | |
} | |
public boolean verify(){ | |
return done; | |
} | |
public int getNumber(){ | |
return 0; | |
} | |
} |
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
@Test | |
public void checkBehaviorOfMockCounter() { | |
int input = 1; | |
MockCounter counter = new MockCounter(input); | |
FizzBuzz fizzBuzz = new FizzBuzz(counter); | |
fizzBuzz.say(input); | |
assertTrue(counter.verify()); | |
} |
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
interface CounterPersistence { | |
} |
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
class StubCounter implements CounterPersistence { | |
} |
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
@Test | |
public void กรณีอื่นๆ() { | |
CounterPersistence counter = new StubCounter(); | |
FizzBuzz fizzBuzz = new FizzBuzz(counter); | |
assertEquals("1", fizzBuzz.say(1)); | |
} |
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
interface CounterPersistence { | |
void setNumber(int number); | |
} |
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
class StubCounter implements CounterPersistence { | |
private int number; | |
public void setNumber(int number) { | |
this.number = number; | |
} | |
} |
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
@Test | |
public void กรณีอื่นๆ() { | |
int input = 1; | |
CounterPersistence counter = new StubCounter(); | |
FizzBuzz fizzBuzz = new FizzBuzz(counter); | |
assertEquals("1", fizzBuzz.say(input)); | |
} | |
class FizzBuzz { | |
CounterPersistence counter; | |
public String say(int number) { | |
this.counter.setNumber(number); | |
... | |
} | |
} |
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
class StubCounter implements CounterPersistence { | |
private int number; | |
public void setNumber(int number) { | |
this.number = number; | |
} | |
public int getNumber(){ | |
return this.number; | |
} | |
} |
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
@Test | |
public void checkNumberOfCounterPersistence() { | |
int input = 1; | |
CounterPersistence counter = new StubCounter(); | |
FizzBuzz fizzBuzz = new FizzBuzz(counter); | |
fizzBuzz.say(input); | |
assertEquals(input, counter.getNumber()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment