Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec4b73b

Browse files
committed
Converted lots of integration tests from TestNG to Spock
1 parent e4dd329 commit ec4b73b

16 files changed

+823
-1002
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2012 Daniel Bechler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.danielbechler.diff.example.phonebook
18+
19+
import de.danielbechler.diff.ObjectDifferBuilder
20+
import de.danielbechler.diff.selector.CollectionItemElementSelector
21+
import spock.lang.Specification
22+
23+
/**
24+
* @author Daniel Bechler
25+
*/
26+
public class PhoneBookIT extends Specification {
27+
28+
def 'contact middle name changes'() {
29+
given:
30+
PhoneBook phoneBook = new PhoneBook("Breaking Bad")
31+
and:
32+
Contact walterWhite = new Contact("Walter", "White")
33+
walterWhite.setPhoneNumber("Home", new PhoneNumber("1", "505", "316-7871"))
34+
walterWhite.setPhoneNumber("Work", new PhoneNumber("1", "505", "456-3788"))
35+
phoneBook.addContact(walterWhite)
36+
and:
37+
Contact jessePinkman = new Contact("Jesse", "Pinkman")
38+
jessePinkman.setPhoneNumber("Home", new PhoneNumber("1", "505", "234-4628"))
39+
phoneBook.addContact(jessePinkman)
40+
and:
41+
PhoneBook modifiedPhoneBook = PhoneBook.from(phoneBook)
42+
modifiedPhoneBook.getContact("Jesse", "Pinkman").middleName = "Bruce"
43+
modifiedPhoneBook.getContact("Walter", "White").middleName = "Hartwell"
44+
when:
45+
def node = ObjectDifferBuilder.buildDefault().compare(modifiedPhoneBook, phoneBook)
46+
then:
47+
node.hasChanges()
48+
node.hasChildren()
49+
node.childCount() == 1
50+
and:
51+
def contactsNode = node.getChild("contacts")
52+
contactsNode.hasChanges()
53+
and:
54+
def pinkmanNode = contactsNode.getChild(new CollectionItemElementSelector(jessePinkman))
55+
pinkmanNode.hasChanges()
56+
and:
57+
def middleNameNode = pinkmanNode.getChild("middleName")
58+
middleNameNode.hasChanges()
59+
middleNameNode.canonicalGet(phoneBook) == null
60+
middleNameNode.canonicalGet(modifiedPhoneBook) == "Bruce"
61+
and:
62+
def whiteNode = contactsNode.getChild(new CollectionItemElementSelector(walterWhite))
63+
whiteNode.hasChanges()
64+
and:
65+
def whiteMiddleNameNode = whiteNode.getChild("middleName")
66+
whiteMiddleNameNode.hasChanges()
67+
whiteMiddleNameNode.canonicalGet(phoneBook) == null
68+
whiteMiddleNameNode.canonicalGet(modifiedPhoneBook) == "Hartwell"
69+
}
70+
}

‎src/integration-test/java/de/danielbechler/diff/example/phonebook/PhoneBookIT.java‎

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2012 Daniel Bechler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.danielbechler.diff.integration
18+
19+
import de.danielbechler.diff.ObjectDifferBuilder
20+
import de.danielbechler.diff.example.phonebook.Contact
21+
import de.danielbechler.diff.example.phonebook.PhoneBook
22+
import de.danielbechler.diff.mock.ObjectWithString
23+
import de.danielbechler.diff.node.DiffNode
24+
import spock.lang.Specification
25+
26+
/**
27+
* @author Daniel Bechler
28+
*/
29+
public class AdditionIntegrationIT extends Specification {
30+
31+
def 'detects change from null to object referenct as addition'() {
32+
given:
33+
def base = new ObjectWithString()
34+
def working = new ObjectWithString("foo")
35+
when:
36+
def node = ObjectDifferBuilder.buildDefault().compare(working, base)
37+
then:
38+
node.getChild('value').state == DiffNode.State.ADDED
39+
}
40+
41+
def 'detects change for duplicates in list'() {
42+
def node
43+
def joe = new Contact("Joe", "Smith")
44+
def objectDiffer = ObjectDifferBuilder.buildDefault()
45+
46+
given:
47+
def phoneBookServer = new PhoneBook("devs")
48+
phoneBookServer.addContact(joe)
49+
and:
50+
def phoneBookMobile = new PhoneBook("devs")
51+
phoneBookMobile.addContact(joe)
52+
53+
when:
54+
node = objectDiffer.compare(phoneBookMobile, phoneBookServer)
55+
then:
56+
node.state == DiffNode.State.UNTOUCHED
57+
58+
when:
59+
phoneBookMobile.addContact(joe)
60+
node = objectDiffer.compare(phoneBookMobile, phoneBookServer)
61+
then:
62+
phoneBookMobile.contacts.size() == 2
63+
and:
64+
node.state == DiffNode.State.UNTOUCHED
65+
// // Eventually it should be able to detect the change as addition...
66+
// node.state == DiffNode.State.ADDED
67+
}
68+
}

‎src/integration-test/java/de/danielbechler/diff/integration/AdditionIntegrationIT.java‎

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2014 Daniel Bechler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.danielbechler.diff.integration
18+
19+
import de.danielbechler.diff.ObjectDifferBuilder
20+
import de.danielbechler.diff.mock.ObjectWithString
21+
import de.danielbechler.diff.node.DiffNode
22+
import de.danielbechler.diff.path.NodePath
23+
import spock.lang.Specification
24+
/**
25+
* @author Daniel Bechler
26+
*/
27+
public class DeepDiffingCollectionItemChangeIT extends Specification {
28+
29+
def 'returns full property graph of added collection items'() {
30+
given:
31+
def base = [:]
32+
def working = [foo: new ObjectWithString('bar')]
33+
when:
34+
def objectDiffer = ObjectDifferBuilder.startBuilding().build()
35+
def node = objectDiffer.compare(working, base)
36+
then:
37+
def fooMapEntryPath = NodePath.startBuilding().mapKey("foo").build()
38+
node.getChild(fooMapEntryPath).state == DiffNode.State.ADDED
39+
and:
40+
def fooMapEntryValuePath = NodePath.startBuildingFrom(fooMapEntryPath).propertyName('value').build()
41+
node.getChild(fooMapEntryValuePath).state == DiffNode.State.ADDED
42+
}
43+
}

‎src/integration-test/java/de/danielbechler/diff/integration/DeepDiffingCollectionItemChangeIT.java‎

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /