Skip to content

Commit 78eb6c1

Browse files
Remove test cases duplicated code
Removed auto generated code comment
1 parent 935113f commit 78eb6c1

File tree

9 files changed

+100
-179
lines changed

9 files changed

+100
-179
lines changed

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@
1919
import java.util.List;
2020

2121
import org.junit.Assert;
22+
import org.junit.Test;
2223
import org.mockito.Mockito;
2324
import org.powermock.api.mockito.PowerMockito;
2425

2526
import com.cloud.utils.script.Script;
2627

27-
public abstract class CitrixResourceBaseTest {
28+
public class CitrixResourceBaseTest {
2829

29-
public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {
30+
protected CitrixResourceBase citrixResourceBase = new CitrixResourceBase() {
31+
@Override
32+
protected String getPatchFilePath() {
33+
return null;
34+
}
35+
};
36+
37+
public void testGetPathFilesExeption() {
3038
String patch = citrixResourceBase.getPatchFilePath();
3139

3240
PowerMockito.mockStatic(Script.class);
@@ -36,7 +44,7 @@ public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {
3644

3745
}
3846

39-
public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase) {
47+
public void testGetPathFilesListReturned() {
4048
String patch = citrixResourceBase.getPatchFilePath();
4149

4250
PowerMockito.mockStatic(Script.class);
@@ -50,31 +58,35 @@ public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase)
5058
Assert.assertEquals(receivedPath, pathExpected);
5159
}
5260

53-
public void testGetGuestOsTypeNull(CitrixResourceBase citrixResourceBase) {
61+
@Test
62+
public void testGetGuestOsTypeNull() {
5463
String platformEmulator = null;
5564

5665
String expected = "Other install media";
5766
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
5867
Assert.assertEquals(expected, guestOsType);
5968
}
6069

61-
public void testGetGuestOsTypeEmpty(CitrixResourceBase citrixResourceBase) {
70+
@Test
71+
public void testGetGuestOsTypeEmpty() {
6272
String platformEmulator = "";
6373

6474
String expected = "Other install media";
6575
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
6676
Assert.assertEquals(expected, guestOsType);
6777
}
6878

69-
public void testGetGuestOsTypeBlank(CitrixResourceBase citrixResourceBase) {
79+
@Test
80+
public void testGetGuestOsTypeBlank() {
7081
String platformEmulator = " ";
7182

7283
String expected = "Other install media";
7384
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
7485
Assert.assertEquals(expected, guestOsType);
7586
}
7687

77-
public void testGetGuestOsTypeOther(CitrixResourceBase citrixResourceBase) {
88+
@Test
89+
public void testGetGuestOsTypeOther() {
7890
String platformEmulator = "My Own Linux Distribution Y.M (64-bit)";
7991

8092
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XcpOssResourceTest.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.cloud.hypervisor.xenserver.resource;
1717

1818
import org.junit.Assert;
19+
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.junit.runner.RunWith;
2122
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -26,11 +27,14 @@
2627
@RunWith(PowerMockRunner.class)
2728
public class XcpOssResourceTest extends CitrixResourceBaseTest{
2829

29-
private XcpOssResource xcpOssResource = new XcpOssResource();
30+
@Before
31+
public void beforeTest() {
32+
super.citrixResourceBase = new XcpOssResource();
33+
}
3034

3135
@Test
3236
public void testPatchFilePath() {
33-
String patchFilePath = xcpOssResource.getPatchFilePath();
37+
String patchFilePath = citrixResourceBase.getPatchFilePath();
3438
String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
3539

3640
Assert.assertEquals(patch, patchFilePath);
@@ -39,29 +43,12 @@ public void testPatchFilePath() {
3943
@Test(expected = CloudRuntimeException.class)
4044
@PrepareForTest(Script.class )
4145
public void testGetFiles(){
42-
testGetPathFilesExeption(xcpOssResource);
46+
testGetPathFilesExeption();
4347
}
4448

4549
@Test
4650
@PrepareForTest(Script.class )
4751
public void testGetFilesListReturned(){
48-
testGetPathFilesListReturned(xcpOssResource);
49-
}
50-
51-
@Test
52-
public void testGetOsTypeNull() {
53-
testGetGuestOsTypeNull(xcpOssResource);
54-
}
55-
@Test
56-
public void testGetOsTypeEmpty() {
57-
testGetGuestOsTypeEmpty(xcpOssResource);
58-
}
59-
@Test
60-
public void testGetOsTypeBlank() {
61-
testGetGuestOsTypeBlank(xcpOssResource);
62-
}
63-
@Test
64-
public void testGetOsTypeOther() {
65-
testGetGuestOsTypeOther(xcpOssResource);
52+
testGetPathFilesListReturned();
6653
}
6754
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XcpServerResourceTest.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.cloud.hypervisor.xenserver.resource;
1717

1818
import org.junit.Assert;
19+
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.junit.runner.RunWith;
2122
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -27,11 +28,14 @@
2728
@RunWith(PowerMockRunner.class)
2829
public class XcpServerResourceTest extends CitrixResourceBaseTest{
2930

30-
private XcpServerResource xcpServerResource = new XcpServerResource();
31+
@Before
32+
public void beforeTest() {
33+
super.citrixResourceBase = new XcpServerResource();
34+
}
3135

3236
@Test
3337
public void testPatchFilePath() {
34-
String patchFilePath = xcpServerResource.getPatchFilePath();
38+
String patchFilePath = citrixResourceBase.getPatchFilePath();
3539
String patch = "scripts/vm/hypervisor/xenserver/xcpserver/patch";
3640

3741
Assert.assertEquals(patch, patchFilePath);
@@ -40,29 +44,12 @@ public void testPatchFilePath() {
4044
@Test(expected = CloudRuntimeException.class)
4145
@PrepareForTest(Script.class )
4246
public void testGetFilesExeption(){
43-
testGetPathFilesExeption(xcpServerResource);
47+
testGetPathFilesExeption();
4448
}
4549

4650
@Test
4751
@PrepareForTest(Script.class )
4852
public void testGetFilesListReturned(){
49-
testGetPathFilesListReturned(xcpServerResource);
50-
}
51-
52-
@Test
53-
public void testGetOsTypeNull() {
54-
testGetGuestOsTypeNull(xcpServerResource);
55-
}
56-
@Test
57-
public void testGetOsTypeEmpty() {
58-
testGetGuestOsTypeEmpty(xcpServerResource);
59-
}
60-
@Test
61-
public void testGetOsTypeBlank() {
62-
testGetGuestOsTypeBlank(xcpServerResource);
63-
}
64-
@Test
65-
public void testGetOsTypeOther() {
66-
testGetGuestOsTypeOther(xcpServerResource);
53+
testGetPathFilesListReturned();
6754
}
6855
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56FP1ResourceTest.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,40 @@
1616
package com.cloud.hypervisor.xenserver.resource;
1717

1818
import org.junit.Assert;
19+
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.junit.runner.RunWith;
2122
import org.powermock.core.classloader.annotations.PrepareForTest;
2223
import org.powermock.modules.junit4.PowerMockRunner;
2324

2425
import com.cloud.utils.exception.CloudRuntimeException;
2526
import com.cloud.utils.script.Script;
27+
2628
@RunWith(PowerMockRunner.class)
2729
public class XenServer56FP1ResourceTest extends CitrixResourceBaseTest{
2830

29-
private XenServer56FP1Resource xenServer56FP1Resource = new XenServer56FP1Resource();
31+
@Before
32+
public void beforeTest() {
33+
super.citrixResourceBase = new XenServer56FP1Resource();
34+
}
3035

3136
@Test
3237
public void testPatchFilePath() {
33-
String patchFilePath = xenServer56FP1Resource.getPatchFilePath();
38+
String patchFilePath = citrixResourceBase.getPatchFilePath();
3439
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
3540

3641
Assert.assertEquals(patch, patchFilePath);
3742
}
43+
3844
@Test(expected = CloudRuntimeException.class)
3945
@PrepareForTest(Script.class )
4046
public void testGetFiles(){
41-
testGetPathFilesExeption(xenServer56FP1Resource);
47+
testGetPathFilesExeption();
4248
}
49+
4350
@Test
4451
@PrepareForTest(Script.class )
4552
public void testGetFilesListReturned(){
46-
testGetPathFilesListReturned(xenServer56FP1Resource);
47-
}
48-
49-
@Test
50-
public void testGetOsTypeNull() {
51-
testGetGuestOsTypeNull(xenServer56FP1Resource);
52-
}
53-
@Test
54-
public void testGetOsTypeEmpty() {
55-
testGetGuestOsTypeEmpty(xenServer56FP1Resource);
56-
}
57-
@Test
58-
public void testGetOsTypeBlank() {
59-
testGetGuestOsTypeBlank(xenServer56FP1Resource);
60-
}
61-
@Test
62-
public void testGetOsTypeOther() {
63-
testGetGuestOsTypeOther(xenServer56FP1Resource);
53+
testGetPathFilesListReturned();
6454
}
6555
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56ResourceTest.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.cloud.hypervisor.xenserver.resource;
1717

1818
import org.junit.Assert;
19+
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.junit.runner.RunWith;
2122
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -26,11 +27,14 @@
2627
@RunWith(PowerMockRunner.class)
2728
public class XenServer56ResourceTest extends CitrixResourceBaseTest {
2829

29-
private XenServer56Resource xenServer56Resource = new XenServer56Resource();
30+
@Before
31+
public void beforeTest() {
32+
super.citrixResourceBase = new XenServer56Resource();
33+
}
3034

3135
@Test
3236
public void testPatchFilePath() {
33-
String patchFilePath = xenServer56Resource.getPatchFilePath();
37+
String patchFilePath = citrixResourceBase.getPatchFilePath();
3438
String patch = "scripts/vm/hypervisor/xenserver/xenserver56/patch";
3539

3640
Assert.assertEquals(patch, patchFilePath);
@@ -39,28 +43,12 @@ public void testPatchFilePath() {
3943
@Test(expected = CloudRuntimeException.class)
4044
@PrepareForTest(Script.class )
4145
public void testGetFiles(){
42-
testGetPathFilesExeption(xenServer56Resource);
46+
testGetPathFilesExeption();
4347
}
48+
4449
@Test
4550
@PrepareForTest(Script.class )
4651
public void testGetFilesListReturned(){
47-
testGetPathFilesListReturned(xenServer56Resource);
48-
}
49-
50-
@Test
51-
public void testGetOsTypeNull() {
52-
testGetGuestOsTypeNull(xenServer56Resource);
53-
}
54-
@Test
55-
public void testGetOsTypeEmpty() {
56-
testGetGuestOsTypeEmpty(xenServer56Resource);
57-
}
58-
@Test
59-
public void testGetOsTypeBlank() {
60-
testGetGuestOsTypeBlank(xenServer56Resource);
61-
}
62-
@Test
63-
public void testGetOsTypeOther() {
64-
testGetGuestOsTypeOther(xenServer56Resource);
52+
testGetPathFilesListReturned();
6553
}
6654
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56SP2ResourceTest.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.cloud.hypervisor.xenserver.resource;
1717

1818
import org.junit.Assert;
19+
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.junit.runner.RunWith;
2122
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -26,40 +27,28 @@
2627
@RunWith(PowerMockRunner.class)
2728
public class XenServer56SP2ResourceTest extends CitrixResourceBaseTest{
2829

29-
private XenServer56SP2Resource xenServer56SP2Resource = new XenServer56SP2Resource();
30+
@Before
31+
public void beforeTest() {
32+
super.citrixResourceBase = new XenServer56SP2Resource();
33+
}
3034

3135
@Test
3236
public void testPatchFilePath() {
33-
String patchFilePath = xenServer56SP2Resource.getPatchFilePath();
37+
String patchFilePath = citrixResourceBase.getPatchFilePath();
3438
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
3539

3640
Assert.assertEquals(patch, patchFilePath);
3741
}
42+
3843
@Test(expected = CloudRuntimeException.class)
3944
@PrepareForTest(Script.class )
4045
public void testGetFiles(){
41-
testGetPathFilesExeption(xenServer56SP2Resource);
46+
testGetPathFilesExeption();
4247
}
48+
4349
@Test
4450
@PrepareForTest(Script.class )
4551
public void testGetFilesListReturned(){
46-
testGetPathFilesListReturned(xenServer56SP2Resource);
47-
}
48-
49-
@Test
50-
public void testGetOsTypeNull() {
51-
testGetGuestOsTypeNull(xenServer56SP2Resource);
52-
}
53-
@Test
54-
public void testGetOsTypeEmpty() {
55-
testGetGuestOsTypeEmpty(xenServer56SP2Resource);
56-
}
57-
@Test
58-
public void testGetOsTypeBlank() {
59-
testGetGuestOsTypeBlank(xenServer56SP2Resource);
60-
}
61-
@Test
62-
public void testGetOsTypeOther() {
63-
testGetGuestOsTypeOther(xenServer56SP2Resource);
52+
testGetPathFilesListReturned();
6453
}
6554
}

0 commit comments

Comments
 (0)