Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 151 - test cleanup #204

Merged
merged 3 commits into from
Mar 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions test/StageDecorationsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StageDecorationsTest {
@Test
void applyAddedDecorationsAroundInnerClosure() {
def testSpy = spy(new TestSpy())
def decoration = spy { nestedClosure -> nestedClosure() }
def decoration = { nestedClosure -> nestedClosure() }

def decorations = new StageDecorations()
decorations.add(decoration)
Expand All @@ -36,19 +36,10 @@ class StageDecorationsTest {
verify(testSpy, times(1)).foo()
}

private class TestSpy {
public foo() { return }
public inlinedClosureCalled() { return }
public innerClosureCalled() { return }
public middleClosureCalled() { return }
public outerClosureCalled() { return }
}

@Test
void applyHandlesMultipleNestedClosures() {
def testSpy = spy(new TestSpy())

def inlinedClosure = { -> testSpy.inlinedClosureCalled() }
def outerClosure = { nestedClosure -> nestedClosure(); testSpy.outerClosureCalled() }
def middleClosure = { nestedClosure -> nestedClosure(); testSpy.middleClosureCalled() }
def innerClosure = { nestedClosure -> nestedClosure(); testSpy.innerClosureCalled() }
Expand All @@ -59,14 +50,22 @@ class StageDecorationsTest {
decorations.add(outerClosure)

decorations.apply {
inlinedClosure()
testSpy.inlinedClosureCalled()
}

verify(testSpy, times(1)).outerClosureCalled()
verify(testSpy, times(1)).middleClosureCalled()
verify(testSpy, times(1)).innerClosureCalled()
verify(testSpy, times(1)).inlinedClosureCalled()
}

private class TestSpy {
public foo() { return }
public inlinedClosureCalled() { return }
public innerClosureCalled() { return }
public middleClosureCalled() { return }
public outerClosureCalled() { return }
}
}

class WithGroup {
Expand All @@ -85,7 +84,7 @@ class StageDecorationsTest {
@Test
void applyAddedDecorationsAroundInnerClosure() {
def testSpy = spy(new TestSpy())
def decoration = spy { nestedClosure -> nestedClosure() }
def decoration = { nestedClosure -> nestedClosure() }
def group = 'somegroup'

def decorations = new StageDecorations()
Expand All @@ -98,20 +97,11 @@ class StageDecorationsTest {
verify(testSpy, times(1)).foo()
}

private class TestSpy {
public foo() { return }
public inlinedClosureCalled() { return }
public innerClosureCalled() { return }
public middleClosureCalled() { return }
public outerClosureCalled() { return }
}

@Test
void applyHandlesMultipleNestedClosures() {
def testSpy = spy(new TestSpy())
def group = 'somegroup'

def inlinedClosure = { -> testSpy.inlinedClosureCalled() }
def outerClosure = { nestedClosure -> nestedClosure(); testSpy.outerClosureCalled() }
def middleClosure = { nestedClosure -> nestedClosure(); testSpy.middleClosureCalled() }
def innerClosure = { nestedClosure -> nestedClosure(); testSpy.innerClosureCalled() }
Expand All @@ -122,21 +112,25 @@ class StageDecorationsTest {
decorations.add(group, outerClosure)

decorations.apply(group) {
inlinedClosure()
testSpy.inlinedClosureCalled()
}

verify(testSpy, times(1)).outerClosureCalled()
verify(testSpy, times(1)).middleClosureCalled()
verify(testSpy, times(1)).innerClosureCalled()
verify(testSpy, times(1)).inlinedClosureCalled()
}
}

class WithAndWithoutGroups {
private class TestSpy {
public foo() { return }
public inlinedClosureCalled() { return }
public innerClosureCalled() { return }
public middleClosureCalled() { return }
public outerClosureCalled() { return }
}
}

class WithAndWithoutGroups {
@Test
void applyWithoutGroupDoesNotRunGroupdDecorations() {
def withoutGroup = spy(new TestSpy())
Expand Down Expand Up @@ -175,5 +169,8 @@ class StageDecorationsTest {
verify(withGroup, times(1)).foo()
}

private class TestSpy {
public foo() { return }
}
}
}