Last active
August 29, 2015 14:08
-
-
Save up1/3f4604850b118b363296 to your computer and use it in GitHub Desktop.
Demo :: Good unit test with JUnit
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 getMyImage() { | |
Fixture.useDefaultResourceManager(); | |
ResourceManager resourceManager = getResourceManager(); | |
assertFalse(resourceManager.isRegistered(Fixture.IMAGE1)); | |
Image image1 = Graphics.getImage(Fixture.IMAGE1); | |
String imagePath = getRegisterPath(image1); | |
assertTrue(resourceManager.isRegistered(imagePath)); | |
File directory = new File(pathname); | |
assertTrue(new File(directory, imagePath).exists()); | |
Image sameImage = Graphics.getImage(Fixture.IMAGE1); | |
assertSame(image1, sameImage); | |
} |
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 testFizzBuzze(){ | |
FizzBuzz fizzBuzz = new FizzBuzz(); | |
String result = fizzBuzz.say(1); | |
assertEquals("1", result); | |
} |
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 sayOne(){ | |
FizzBuzz fizzBuzz = new FizzBuzz(); | |
String result = fizzBuzz.say(1); | |
assertEquals("1", actual); | |
} | |
@Test | |
public void sayTwo(){ | |
FizzBuzz fizzBuzz = new FizzBuzz(); | |
String result = fizzBuzz.say(2); | |
assertEquals("2", actual); | |
} |
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; | |
@Before | |
public void setUp() { | |
FizzBuzz = new FizzBuzz(); | |
} | |
@Test | |
public void sayOne() { | |
String result = fizzBuzz.say(1); | |
assertEquals("1", actual); | |
} | |
@Test | |
public void sayTwo() { | |
String result = fizzBuzz.say(2); | |
assertEquals("2", actual); | |
} |
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 exceedRange() { | |
NumberRangeCounter counter = new NumberRangeCounter(LOWER_BOUND, 0); | |
try { | |
counter.next(); | |
fail(); | |
} catch (IllegalStateException expected) { | |
} | |
} |
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(expected=IllegalStateException.class) | |
public void exceedRange() { | |
NumberRangeCounter counter = new NumberRangeCounter(LOWER_BOUND, 0); | |
counter.next(); | |
} |
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
@Rule | |
public ExpectedException thrown = ExpectedException.none(); | |
@Test | |
public void exceedRange() { | |
thrown.expect(IllegalStateException.class); | |
new NumberRangeCounter(LOWER_BOUND, 0).next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment