mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 00:59:37 +00:00
fix: monitor pattern is not being built (#1956)
* fix: update the version in pom.xml * fixes the checksyle error and adds javadoc * fix: bugs and code-smells in sonarcloud * replaced logger library with Slf4j * fix tests and add a previously dropped method * adds license * fix: codesmells and bug * replace Random with SecureRandom * test: add tests for Main to improve coverage
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
*The MIT License
|
||||
*Copyright © 2014-2021 Ilkka Seppälä
|
||||
*
|
||||
*Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
*of this software and associated documentation files (the "Software"), to deal
|
||||
*in the Software without restriction, including without limitation the rights
|
||||
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
*copies of the Software, and to permit persons to whom the Software is
|
||||
*furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*The above copyright notice and this permission notice shall be included in
|
||||
*all copies or substantial portions of the Software.
|
||||
*
|
||||
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
*THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.monitor;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
public class BankTest {
|
||||
|
||||
private static final int ACCOUNT_NUM = 4;
|
||||
private static final int BASE_AMOUNT = 1000;
|
||||
private static Bank bank;
|
||||
|
||||
@BeforeAll
|
||||
public static void Setup() {
|
||||
bank = new Bank(ACCOUNT_NUM, BASE_AMOUNT);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void TearDown() {
|
||||
bank = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void GetAccountHaveNotBeNull() {
|
||||
assertNotNull(bank.getAccounts());
|
||||
}
|
||||
|
||||
@Test
|
||||
void LengthOfAccountsHaveToEqualsToAccountNumConstant() {
|
||||
assumeTrue(bank.getAccounts() != null);
|
||||
assertEquals(ACCOUNT_NUM, bank.getAccounts().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void TransferMethodHaveToTransferAmountFromAnAccountToOtherAccount() {
|
||||
bank.transfer(0, 1, 1000);
|
||||
int[] accounts = bank.getAccounts();
|
||||
assertEquals(0, accounts[0]);
|
||||
assertEquals(2000, accounts[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void BalanceHaveToBeOK() {
|
||||
assertEquals(4000, bank.getBalance());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
*The MIT License
|
||||
*Copyright © 2014-2021 Ilkka Seppälä
|
||||
*
|
||||
*Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
*of this software and associated documentation files (the "Software"), to deal
|
||||
*in the Software without restriction, including without limitation the rights
|
||||
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
*copies of the Software, and to permit persons to whom the Software is
|
||||
*furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*The above copyright notice and this permission notice shall be included in
|
||||
*all copies or substantial portions of the Software.
|
||||
*
|
||||
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
*THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.monitor;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Test if the application starts without throwing an exception. */
|
||||
class MainTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> Main.main(new String[] {}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void RunnerExecuteWithoutException() {
|
||||
var bank = new Bank(4, 1000);
|
||||
assertDoesNotThrow(() -> Main.runner(bank));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user