Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments

This commit is contained in:
Narendra Pathai
2018-10-20 17:50:52 +05:30
parent 2f569d670a
commit 543eb9a4be
73 changed files with 207 additions and 298 deletions

View File

@ -31,7 +31,7 @@ import java.io.IOException;
*/
public class AppTest {
@Test
public void test() throws IOException {
public void test() {
String[] args = {};
App.main(args);
}

View File

@ -37,16 +37,16 @@ public class FruitBowlTest {
public void fruitBowlTest() {
FruitBowl fbowl = new FruitBowl();
assertEquals(fbowl.countFruit(), 0);
assertEquals(0, fbowl.countFruit());
for (int i = 1; i <= 10; i++) {
fbowl.put(new Fruit(Fruit.FruitType.LEMON));
assertEquals(fbowl.countFruit(), i);
assertEquals(i, fbowl.countFruit());
}
for (int i = 9; i >= 0; i--) {
assertNotNull(fbowl.take());
assertEquals(fbowl.countFruit(), i);
assertEquals(i, fbowl.countFruit());
}
assertNull(fbowl.take());

View File

@ -36,12 +36,12 @@ public class SemaphoreTest {
public void acquireReleaseTest() {
Semaphore sphore = new Semaphore(3);
assertEquals(sphore.getAvailableLicenses(), 3);
assertEquals(3, sphore.getAvailableLicenses());
for (int i = 2; i >= 0; i--) {
try {
sphore.acquire();
assertEquals(sphore.getAvailableLicenses(), i);
assertEquals(i, sphore.getAvailableLicenses());
} catch (InterruptedException e) {
fail(e.toString());
}
@ -49,10 +49,10 @@ public class SemaphoreTest {
for (int i = 1; i <= 3; i++) {
sphore.release();
assertEquals(sphore.getAvailableLicenses(), i);
assertEquals(i, sphore.getAvailableLicenses());
}
sphore.release();
assertEquals(sphore.getAvailableLicenses(), 3);
assertEquals(3, sphore.getAvailableLicenses());
}
}