mysql tests
Some checks failed
Gradle CI with Full Reports / build (push) Failing after 15m12s

This commit is contained in:
Jan-Philipp Luithardt
2025-12-18 09:17:23 +01:00
parent facb0556a0
commit 7f96f50fb7
73 changed files with 1013 additions and 902 deletions

View File

@@ -13,86 +13,91 @@ public class TaskManager {
private Map<Integer, Task> taskMap;
private MySql mysql;
<span class="fc" id="L16"> public TaskManager(String user, String password, String port, String host) {</span>
<span class="fc" id="L17"> taskMap = new HashMap&lt;&gt;();</span>
<span class="fc" id="L18"> this.mysql = new MySql(user, password, port, host);</span>
<span class="fc" id="L19"> this.mysql.connect();</span>
<span class="fc" id="L20"> }</span>
<span class="fc" id="L16"> public TaskManager(String user, String password, String db, String host, String port) {</span>
<span class="fc bfc" id="L18" title="All 10 branches covered."> if(user == null || password == null || db == null || host == null || port == null) {</span>
<span class="fc" id="L19"> throw new NullPointerException(&quot;A argument is null&quot;);</span>
}
<span class="fc" id="L22"> taskMap = new HashMap&lt;&gt;();</span>
<span class="fc" id="L23"> this.mysql = new MySql(user, password, db, host, port);</span>
<span class="fc" id="L24"> this.mysql.connect();</span>
<span class="fc" id="L25"> }</span>
/**
* only for Testing
*/
public void resetTest() {
<span class="fc" id="L25"> this.mysql.reset();</span>
<span class="fc" id="L26"> }</span>
<span class="fc" id="L30"> this.mysql.reset();</span>
<span class="fc" id="L31"> }</span>
public Task createTask(String name, String description) {
<span class="fc bfc" id="L29" title="All 4 branches covered."> if (name == null || description == null ) {</span>
<span class="fc bfc" id="L34" title="All 4 branches covered."> if (name == null || description == null ) {</span>
<span class="fc" id="L31"> throw new IllegalArgumentException(&quot;Name/Description is null!&quot;);</span>
<span class="fc" id="L36"> throw new IllegalArgumentException(&quot;Name/Description is null!&quot;);</span>
}
<span class="fc bfc" id="L33" title="All 2 branches covered."> if(name.isEmpty()) {</span>
<span class="fc" id="L34"> throw new IllegalArgumentException(&quot;Name is empty!&quot;);</span>
<span class="fc bfc" id="L38" title="All 2 branches covered."> if(name.isEmpty()) {</span>
<span class="fc" id="L39"> throw new IllegalArgumentException(&quot;Name is empty!&quot;);</span>
}
<span class="fc bfc" id="L37" title="All 2 branches covered."> if(!checkOnlyLetterOrDigit(name)) {</span>
<span class="fc" id="L38"> throw new IllegalArgumentException(&quot;Only Letters or Digit are allowed in the name: &quot; + name);</span>
<span class="fc bfc" id="L42" title="All 2 branches covered."> if(!checkOnlyLetterOrDigit(name)) {</span>
<span class="fc" id="L43"> throw new IllegalArgumentException(&quot;Only Letters or Digit are allowed in the name: &quot; + name);</span>
}
<span class="fc" id="L41"> boolean taskExited = this.mysql.existTask(name);</span>
<span class="fc bfc" id="L42" title="All 2 branches covered."> if(taskExited) {</span>
<span class="fc" id="L43"> throw new TaskAlreadyExistsException(&quot;Task already exits, with the name: &quot; + name);</span>
<span class="fc" id="L46"> boolean taskExited = this.mysql.existTask(name);</span>
<span class="fc bfc" id="L47" title="All 2 branches covered."> if(taskExited) {</span>
<span class="fc" id="L48"> throw new TaskAlreadyExistsException(&quot;Task already exits, with the name: &quot; + name);</span>
}
<span class="fc" id="L46"> int taskId = this.mysql.createTask(name, description);</span>
<span class="fc" id="L47"> Task task = this.mysql.getTask(taskId);</span>
<span class="fc" id="L51"> int taskId = this.mysql.createTask(name, description);</span>
<span class="fc" id="L52"> Task task = this.mysql.getTask(taskId);</span>
//taskMap.put(task.getTaskID(), task);
<span class="fc" id="L50"> return task;</span>
<span class="fc" id="L55"> return task;</span>
}
public List&lt;Task&gt; getTaskList() {
<span class="fc" id="L55"> return this.mysql.getTaskList();</span>
<span class="fc" id="L60"> return this.mysql.getTaskList();</span>
}
public Task getTask(String name) {
<span class="fc bfc" id="L59" title="All 2 branches covered."> if(!this.mysql.existTask(name)) {</span>
<span class="fc" id="L60"> throw new IllegalArgumentException(&quot;Wrong name&quot;);</span>
<span class="fc bfc" id="L64" title="All 2 branches covered."> if(!this.mysql.existTask(name)) {</span>
<span class="fc" id="L65"> throw new IllegalArgumentException(&quot;Wrong name&quot;);</span>
}
<span class="fc" id="L63"> return this.mysql.getTask(name);</span>
<span class="fc" id="L68"> return this.mysql.getTask(name);</span>
}
public Task getTask(int taskID) {
<span class="fc bfc" id="L66" title="All 2 branches covered."> if(!this.mysql.existTask(taskID)) {</span>
<span class="fc" id="L67"> throw new IllegalArgumentException(&quot;Wrong id&quot;);</span>
<span class="fc bfc" id="L71" title="All 2 branches covered."> if(!this.mysql.existTask(taskID)) {</span>
<span class="fc" id="L72"> throw new IllegalArgumentException(&quot;Wrong id&quot;);</span>
}
<span class="fc" id="L69"> return this.mysql.getTask(taskID);</span>
<span class="fc" id="L74"> return this.mysql.getTask(taskID);</span>
}
public void deleteTask(String name) {
<span class="fc bfc" id="L73" title="All 2 branches covered."> if (name == null ) {</span>
<span class="fc bfc" id="L78" title="All 2 branches covered."> if (name == null ) {</span>
<span class="fc" id="L75"> throw new IllegalArgumentException(&quot;Name is null!&quot;);</span>
<span class="fc" id="L80"> throw new IllegalArgumentException(&quot;Name is null!&quot;);</span>
}
<span class="fc bfc" id="L77" title="All 4 branches covered."> if(name.isEmpty() || !this.mysql.existTask(name)) {</span>
<span class="fc" id="L78"> throw new IllegalArgumentException(&quot;Wrong name!&quot;);</span>
<span class="fc bfc" id="L82" title="All 4 branches covered."> if(name.isEmpty() || !this.mysql.existTask(name)) {</span>
<span class="fc" id="L83"> throw new IllegalArgumentException(&quot;Wrong name!&quot;);</span>
}
<span class="fc" id="L81"> this.mysql.deleteTask(name);</span>
<span class="fc" id="L86"> this.mysql.deleteTask(name);</span>
<span class="fc" id="L83"> }</span>
<span class="fc" id="L88"> }</span>
private boolean checkOnlyLetterOrDigit(String text) {
<span class="fc" id="L86"> boolean result = true;</span>
<span class="fc" id="L91"> boolean result = true;</span>
<span class="fc bfc" id="L88" title="All 2 branches covered."> for(int i = 0; i &lt; text.length(); i++) {</span>
<span class="fc" id="L89"> char c = text.charAt(i);</span>
<span class="fc bfc" id="L90" title="All 2 branches covered."> if(!Character.isLetterOrDigit(c)) {</span>
<span class="fc" id="L91"> result = false;</span>
<span class="fc" id="L92"> break;</span>
<span class="fc bfc" id="L93" title="All 2 branches covered."> for(int i = 0; i &lt; text.length(); i++) {</span>
<span class="fc" id="L94"> char c = text.charAt(i);</span>
<span class="fc bfc" id="L95" title="All 2 branches covered."> if(!Character.isLetterOrDigit(c)) {</span>
<span class="fc" id="L96"> result = false;</span>
<span class="fc" id="L97"> break;</span>
}
}
<span class="fc" id="L95"> return result;</span>
<span class="fc" id="L100"> return result;</span>
}
// private boolean checkOnlyLetter(String text) {
// boolean result = true;