Skip to content

Commit 70f6e54

Browse files
stailleboisnpathai
authored andcommitted
Fix blocker issues on Sonar iluwatar#508 (iluwatar#810)
* Fix blocker issues on Sonar * Replace Assertj assertions with JUnit ones
1 parent 1f1fcae commit 70f6e54

File tree

4 files changed

+195
-234
lines changed

4 files changed

+195
-234
lines changed

naked-objects/dom/src/test/java/domainapp/dom/modules/simple/SimpleObjectTest.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*/
1515
package domainapp.dom.modules.simple;
1616

17-
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertNull;
1819

1920
import org.junit.Before;
2021
import org.junit.Test;
@@ -30,24 +31,18 @@ public class SimpleObjectTest {
3031
public void setUp() throws Exception {
3132
simpleObject = new SimpleObject();
3233
}
33-
34-
/**
35-
* Test for Names for SimpleObjects
36-
*/
37-
public static class Name extends SimpleObjectTest {
38-
39-
@Test
40-
public void happyCase() throws Exception {
41-
// given
42-
String name = "Foobar";
43-
assertThat(simpleObject.getName()).isNull();
44-
45-
// when
46-
simpleObject.setName(name);
47-
48-
// then
49-
assertThat(simpleObject.getName()).isEqualTo(name);
50-
}
34+
35+
@Test
36+
public void testName() throws Exception {
37+
// given
38+
String name = "Foobar";
39+
assertNull(simpleObject.getName());
40+
41+
// when
42+
simpleObject.setName(name);
43+
44+
// then
45+
assertEquals(name, simpleObject.getName());
5146
}
5247

5348
}

naked-objects/dom/src/test/java/domainapp/dom/modules/simple/SimpleObjectsTest.java

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
*/
1515
package domainapp.dom.modules.simple;
1616

17-
import static org.assertj.core.api.Assertions.assertThat;
18-
1917
import com.google.common.collect.Lists;
18+
19+
import static org.junit.Assert.assertEquals;
20+
2021
import java.util.List;
2122
import org.apache.isis.applib.DomainObjectContainer;
2223
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
@@ -46,63 +47,52 @@ public void setUp() throws Exception {
4647
simpleObjects = new SimpleObjects();
4748
simpleObjects.container = mockContainer;
4849
}
49-
50-
/**
51-
* Test Creation of Simple Objects
52-
*/
53-
public static class Create extends SimpleObjectsTest {
54-
55-
@Test
56-
public void happyCase() throws Exception {
57-
58-
// given
59-
final SimpleObject simpleObject = new SimpleObject();
60-
61-
final Sequence seq = context.sequence("create");
62-
context.checking(new Expectations() {
63-
{
64-
oneOf(mockContainer).newTransientInstance(SimpleObject.class);
65-
inSequence(seq);
66-
will(returnValue(simpleObject));
67-
68-
oneOf(mockContainer).persistIfNotAlready(simpleObject);
69-
inSequence(seq);
70-
}
71-
});
72-
73-
// when
74-
final SimpleObject obj = simpleObjects.create("Foobar");
75-
76-
// then
77-
assertThat(obj).isEqualTo(simpleObject);
78-
assertThat(obj.getName()).isEqualTo("Foobar");
79-
}
80-
50+
51+
@Test
52+
public void testCreate() throws Exception {
53+
54+
// given
55+
final SimpleObject simpleObject = new SimpleObject();
56+
57+
final Sequence seq = context.sequence("create");
58+
context.checking(new Expectations() {
59+
{
60+
oneOf(mockContainer).newTransientInstance(SimpleObject.class);
61+
inSequence(seq);
62+
will(returnValue(simpleObject));
63+
64+
oneOf(mockContainer).persistIfNotAlready(simpleObject);
65+
inSequence(seq);
66+
}
67+
});
68+
69+
// when
70+
String objectName = "Foobar";
71+
final SimpleObject obj = simpleObjects.create(objectName);
72+
73+
// then
74+
assertEquals(simpleObject, obj);
75+
assertEquals(objectName, obj.getName());
8176
}
77+
78+
@Test
79+
public void testListAll() throws Exception {
8280

83-
/**
84-
* Test Listing of Simple Objects
85-
*/
86-
public static class ListAll extends SimpleObjectsTest {
81+
// given
82+
final List<SimpleObject> all = Lists.newArrayList();
8783

88-
@Test
89-
public void happyCase() throws Exception {
84+
context.checking(new Expectations() {
85+
{
86+
oneOf(mockContainer).allInstances(SimpleObject.class);
87+
will(returnValue(all));
88+
}
89+
});
9090

91-
// given
92-
final List<SimpleObject> all = Lists.newArrayList();
91+
// when
92+
final List<SimpleObject> list = simpleObjects.listAll();
9393

94-
context.checking(new Expectations() {
95-
{
96-
oneOf(mockContainer).allInstances(SimpleObject.class);
97-
will(returnValue(all));
98-
}
99-
});
100-
101-
// when
102-
final List<SimpleObject> list = simpleObjects.listAll();
103-
104-
// then
105-
assertThat(list).isEqualTo(all);
106-
}
94+
// then
95+
assertEquals(all, list);
10796
}
97+
10898
}

naked-objects/integtests/src/test/java/domainapp/integtests/tests/modules/simple/SimpleObjectIntegTest.java

Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,37 @@
1818
*/
1919
package domainapp.integtests.tests.modules.simple;
2020

21-
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertNotNull;
2223

23-
import domainapp.dom.modules.simple.SimpleObject;
24-
import domainapp.fixture.scenarios.RecreateSimpleObjects;
25-
import domainapp.integtests.tests.SimpleAppIntegTest;
2624
import javax.inject.Inject;
25+
2726
import org.apache.isis.applib.DomainObjectContainer;
2827
import org.apache.isis.applib.fixturescripts.FixtureScripts;
2928
import org.apache.isis.applib.services.wrapper.DisabledException;
3029
import org.apache.isis.applib.services.wrapper.InvalidException;
3130
import org.junit.Before;
3231
import org.junit.Test;
3332

33+
import domainapp.dom.modules.simple.SimpleObject;
34+
import domainapp.fixture.scenarios.RecreateSimpleObjects;
35+
import domainapp.integtests.tests.SimpleAppIntegTest;
36+
3437
/**
3538
* Test Fixtures with Simple Objects
3639
*/
3740
public class SimpleObjectIntegTest extends SimpleAppIntegTest {
3841

3942
@Inject
4043
FixtureScripts fixtureScripts;
44+
@Inject
45+
DomainObjectContainer container;
4146

4247
RecreateSimpleObjects fs;
4348
SimpleObject simpleObjectPojo;
4449
SimpleObject simpleObjectWrapped;
50+
51+
private static final String NEW_NAME = "new name";
4552

4653
@Before
4754
public void setUp() throws Exception {
@@ -51,80 +58,59 @@ public void setUp() throws Exception {
5158

5259
simpleObjectPojo = fs.getSimpleObjects().get(0);
5360

54-
assertThat(simpleObjectPojo).isNotNull();
61+
assertNotNull(simpleObjectPojo);
5562
simpleObjectWrapped = wrap(simpleObjectPojo);
5663
}
57-
58-
/**
59-
* Test Object Name accessibility
60-
*/
61-
public static class Name extends SimpleObjectIntegTest {
62-
63-
@Test
64-
public void accessible() throws Exception {
65-
// when
66-
final String name = simpleObjectWrapped.getName();
67-
// then
68-
assertThat(name).isEqualTo(fs.names.get(0));
69-
}
70-
71-
@Test
72-
public void cannotBeUpdatedDirectly() throws Exception {
73-
74-
// expect
75-
expectedExceptions.expect(DisabledException.class);
76-
77-
// when
78-
simpleObjectWrapped.setName("new name");
79-
}
64+
65+
@Test
66+
public void testNameAccessible() throws Exception {
67+
// when
68+
final String name = simpleObjectWrapped.getName();
69+
// then
70+
assertEquals(fs.names.get(0), name);
8071
}
72+
73+
@Test
74+
public void testNameCannotBeUpdatedDirectly() throws Exception {
8175

82-
/**
83-
* Test Validation of SimpleObject Names
84-
*/
85-
public static class UpdateName extends SimpleObjectIntegTest {
86-
87-
@Test
88-
public void happyCase() throws Exception {
89-
90-
// when
91-
simpleObjectWrapped.updateName("new name");
76+
// expect
77+
expectedExceptions.expect(DisabledException.class);
9278

93-
// then
94-
assertThat(simpleObjectWrapped.getName()).isEqualTo("new name");
95-
}
96-
97-
@Test
98-
public void failsValidation() throws Exception {
79+
// when
80+
simpleObjectWrapped.setName(NEW_NAME);
81+
}
82+
83+
@Test
84+
public void testUpdateName() throws Exception {
9985

100-
// expect
101-
expectedExceptions.expect(InvalidException.class);
102-
expectedExceptions.expectMessage("Exclamation mark is not allowed");
86+
// when
87+
simpleObjectWrapped.updateName(NEW_NAME);
10388

104-
// when
105-
simpleObjectWrapped.updateName("new name!");
106-
}
89+
// then
90+
assertEquals(NEW_NAME, simpleObjectWrapped.getName());
10791
}
92+
93+
@Test
94+
public void testUpdateNameFailsValidation() throws Exception {
10895

109-
/**
110-
* Test ContainerTitle generation based on SimpleObject Name
111-
*/
112-
public static class Title extends SimpleObjectIntegTest {
113-
114-
@Inject
115-
DomainObjectContainer container;
96+
// expect
97+
expectedExceptions.expect(InvalidException.class);
98+
expectedExceptions.expectMessage("Exclamation mark is not allowed");
11699

117-
@Test
118-
public void interpolatesName() throws Exception {
100+
// when
101+
simpleObjectWrapped.updateName(NEW_NAME + "!");
102+
}
103+
104+
@Test
105+
public void testInterpolatesName() throws Exception {
119106

120-
// given
121-
final String name = simpleObjectWrapped.getName();
107+
// given
108+
final String name = simpleObjectWrapped.getName();
122109

123-
// when
124-
final String title = container.titleOf(simpleObjectWrapped);
110+
// when
111+
final String title = container.titleOf(simpleObjectWrapped);
125112

126-
// then
127-
assertThat(title).isEqualTo("Object: " + name);
128-
}
113+
// then
114+
assertEquals("Object: " + name, title);
129115
}
130116
}

0 commit comments

Comments
 (0)