Skip to content

Commit 7a0005b

Browse files
author
Manu
committed
75% coverage, removed empty classes
1 parent 6f3485f commit 7a0005b

File tree

6 files changed

+105
-98
lines changed

6 files changed

+105
-98
lines changed

src/main/java/io/elastest/ece/application/EceApplication.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void main(String[] args) {
3737
* Check number of parameters
3838
* @param args as string array
3939
*/
40-
private static void checkParameters(String[] args) {
40+
public static void checkParameters(String[] args) {
4141
if (args.length == 0) {
4242
String log = "A configuration file path has to be provided (as argument), otherwise the Elastest Cost Engine cannot be properly loaded";
4343
logger.error(log);
@@ -52,7 +52,7 @@ private static void checkParameters(String[] args) {
5252
* Check whether parameter was help
5353
* @param param to be examined
5454
*/
55-
private static void checkHelp(String param) {
55+
public static void checkHelp(String param) {
5656
if (param.equals("-h") || param.equals("--help")) {
5757
System.exit(0);
5858
}
@@ -64,7 +64,7 @@ private static void checkHelp(String param) {
6464
* Make sure configuration file is valid
6565
* @param param path
6666
*/
67-
private static void checkConfigurationFile(String param) {
67+
public static void checkConfigurationFile(String param) {
6868
try {
6969
// create and parse configuration settings
7070
Loader.createInstance(param);
@@ -81,7 +81,7 @@ private static void checkConfigurationFile(String param) {
8181
/**
8282
* Check and configure Hibernate
8383
*/
84-
private static void checkAndConfigureHibernate() {
84+
public static void checkAndConfigureHibernate() {
8585
try {
8686
// get credentials
8787
HibernateCredentials credentials = Loader.getSettings().getHibernateCredentials();
@@ -102,11 +102,11 @@ private static void checkAndConfigureHibernate() {
102102
outputProgressBar();
103103
}
104104

105-
private static void outputProgressBar() {
105+
public static void outputProgressBar() {
106106
outputProgressBar("...");
107107
}
108108

109-
private static void outputProgressBar(String text, Boolean ... emptyLine) {
109+
public static void outputProgressBar(String text, Boolean ... emptyLine) {
110110
if (emptyLine.length > 0 && emptyLine[0]) {
111111
System.out.println();
112112
}

src/main/java/io/elastest/ece/model/TJobItem.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/io/elastest/ece/persistance/HibernateConfiguration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222

2323
import io.elastest.ece.load.model.HibernateCredentials;
2424
import io.elastest.ece.model.CostModel;
25-
import io.elastest.ece.model.CostItem;
2625
import io.elastest.ece.model.TJob;
27-
import io.elastest.ece.model.TJobItem;
2826
import org.hibernate.cfg.Configuration;
2927

3028
public class HibernateConfiguration {
3129
public static Configuration createConfiguration(HibernateCredentials credentials) {
3230
Configuration conf = new Configuration();
3331

3432
// add mandatory hibernate classes
35-
conf.addAnnotatedClass(TJob.class).addAnnotatedClass(TJobItem.class).addAnnotatedClass(CostModel.class).addAnnotatedClass(CostItem.class);
33+
conf.addAnnotatedClass(TJob.class).addAnnotatedClass(CostModel.class);
3634

3735
// now set properties
3836
conf.setProperty("hibernate.connection.driver_class", credentials.getHibernateDriver())
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package elastest.io.ece.api;
2+
3+
import io.elastest.ece.model.CostModel;
4+
import junit.framework.TestCase;
5+
import org.junit.Test;
6+
7+
import java.util.HashMap;
8+
9+
/**
10+
* Copyright (c) 2017. Zuercher Hochschule fuer Angewandte Wissenschaften
11+
* All Rights Reserved.
12+
* <p>
13+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
14+
* not use this file except in compliance with the License. You may obtain
15+
* a copy of the License at
16+
* <p>
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
* <p>
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
22+
* License for the specific language governing permissions and limitations
23+
* under the License.
24+
* <p>
25+
* Created by Manu Perez on 25.08.17.
26+
*/
27+
28+
public class CostModelTest extends TestCase{
29+
30+
@Test
31+
public void testEquals(){
32+
CostModel costModel = new CostModel("costModel", "test", new HashMap());
33+
CostModel sameCostModel = new CostModel("costModel", "test", new HashMap());
34+
35+
costModel.setVar_rate(new HashMap<>());
36+
costModel.setComponents(new HashMap<>());
37+
costModel.setDescription("");
38+
sameCostModel.setVar_rate(new HashMap<>());
39+
sameCostModel.setComponents(new HashMap<>());
40+
sameCostModel.setDescription("");
41+
42+
assertNotSame(new Double(0), costModel);
43+
assertEquals(costModel, sameCostModel);
44+
}
45+
}
Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
package elastest.io.ece.api;
22

3-
import junit.framework.Test;
3+
import io.elastest.ece.application.EceApplication;
44
import junit.framework.TestCase;
5-
import junit.framework.TestSuite;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.junit.rules.ExpectedException;
9+
10+
import java.io.ByteArrayOutputStream;
11+
import java.io.PrintStream;
612

713
/**
814
* Unit test for simple App.
915
*/
1016
public class EceApplicationTests
1117
extends TestCase {
12-
/**
13-
* Create the test case
14-
*
15-
* @param testName name of the test case
16-
*/
17-
public EceApplicationTests(String testName) {
18-
super(testName);
18+
19+
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
20+
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
21+
22+
public void setUpStreams(){
23+
System.setOut(new PrintStream(outContent));
24+
System.setErr(new PrintStream(errContent));
1925
}
2026

21-
/**
22-
* @return the suite of tests being tested
23-
*/
24-
public static Test suite() {
25-
return new TestSuite(EceApplicationTests.class);
27+
public void cleanUpStreams(){
28+
System.setOut(null);
29+
System.setErr(null);
30+
}
31+
@Test
32+
public void testCheckParameters()
33+
{
34+
setUpStreams();
35+
String[] array = new String[1];
36+
array[0] = "param";
37+
EceApplication.checkParameters(array);
38+
assertEquals("...", outContent.toString());
39+
cleanUpStreams();
2640
}
2741

28-
/**
29-
* Rigourous Test :-)
30-
*/
31-
public void testApp() {
32-
assertTrue(true);
42+
@Test
43+
public void testCheckHelp()
44+
{
45+
setUpStreams();
46+
EceApplication.checkHelp("");
47+
assertEquals("...", outContent.toString());
48+
cleanUpStreams();
3349
}
50+
51+
3452
}
Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
package io.elastest.ece.model;
1+
package elastest.io.ece.api;
22

3+
import io.elastest.ece.model.CostModel;
4+
import io.elastest.ece.model.TJob;
5+
import junit.framework.TestCase;
6+
import org.junit.Test;
37

4-
5-
import javax.persistence.*;
8+
import java.util.HashMap;
69

710
/**
811
* Copyright (c) 2017. Zuercher Hochschule fuer Angewandte Wissenschaften
@@ -20,29 +23,21 @@
2023
* License for the specific language governing permissions and limitations
2124
* under the License.
2225
* <p>
23-
* Created by Manu Perez on 14/07/17.
26+
* Created by Manu Perez on 25.08.17.
2427
*/
2528

26-
@Entity
27-
public class CostItem {
28-
@Id
29-
@GeneratedValue(strategy= GenerationType.AUTO)
30-
private Long id;
31-
private Double cost;
29+
public class TJobTest extends TestCase{
3230

33-
public CostItem(Double cost) {
34-
this.cost = Double.valueOf(cost);
35-
}
31+
@Test
32+
public void testEquals(){
33+
TJob tJob = new TJob("tjob", new HashMap());
34+
TJob tJob1 = new TJob("tjob", new HashMap());
3635

37-
public Long getId() {
38-
return id;
39-
}
36+
tJob.setMetadata(new HashMap<>());
37+
tJob1.setMetadata(new HashMap<>());
4038

41-
public double getCost() {
42-
return cost;
43-
}
39+
assertNotSame(new Double(0), tJob);
40+
assertEquals(tJob, tJob1);
4441

45-
public void setCost(double cost) {
46-
this.cost = cost;
4742
}
4843
}

0 commit comments

Comments
 (0)