Skip to content

Commit

Permalink
Merge pull request #17 from devindi/test_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
devindi authored Oct 24, 2019
2 parents 748f49f + 08c9468 commit e290dd8
Showing 1 changed file with 2 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,101 +1,30 @@
package com.devindi.gradle.diawi.task.internal

import com.devindi.gradle.diawi.dsl.DiawiUploadExtension
import org.gradle.api.logging.Logger
import org.junit.Assert
import org.junit.Test

import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.*

@SuppressWarnings("GrDeprecatedAPIUsage")
class UploadParamsFactoryTest {

def loggerMock = mock(Logger.class)
def factory = new UploadParamsFactory(loggerMock)

@Test
void callbackUrlNewDsl() {
DiawiUploadExtension extension = createExtension()
extension.callback.url = "http://example.com"

def params = factory.createParams(extension)

Assert.assertEquals("http://example.com", params.callbackUrl)
verifyNoMoreInteractions(loggerMock)
}

@Test
void callbackUrlOldDsl() {
DiawiUploadExtension extension = createExtension()
extension.callbackUrl = "http://example.com"

def params = factory.createParams(extension)
def params = UploadParamsFactory.createParams(extension)

Assert.assertEquals("http://example.com", params.callbackUrl)
verify(loggerMock).warn(any(String.class))
}

@Test
void newDslPreferredUrl() {
DiawiUploadExtension extension = createExtension()
extension.callbackUrl = "http://old.example.com"
extension.callback.url = "http://new.example.com"

def params = factory.createParams(extension)

Assert.assertEquals("http://new.example.com", params.callbackUrl)
verify(loggerMock).warn(any(String.class))
}

@Test(expected = IllegalArgumentException.class)
void tokenRequiredException() {
DiawiUploadExtension extension = new DiawiUploadExtension()

factory.createParams(extension)
}

@Test
void callbackEmailNewDsl() {
DiawiUploadExtension extension = createExtension()
extension.callback.emails = ["[email protected]"]

def params = factory.createParams(extension)
def params = UploadParamsFactory.createParams(extension)

Assert.assertEquals("[email protected]", params.callbackEmails)
verifyNoMoreInteractions(loggerMock)
}

@Test
void callbackEmailOldDsl() {
DiawiUploadExtension extension = createExtension()
extension.callbackEmail = "[email protected]"

def params = factory.createParams(extension)

Assert.assertEquals("[email protected]", params.callbackEmails)
verify(loggerMock).warn(any(String.class))
}

@Test
void newDslPreferredEmail() {
DiawiUploadExtension extension = createExtension()
extension.callbackEmail = ["[email protected]"]
extension.callback.emails = ["[email protected]"]

def params = factory.createParams(extension)

Assert.assertEquals("[email protected]", params.callbackEmails)
verify(loggerMock).warn(any(String.class))
}

@Test
void noLogsForEmpty() {
DiawiUploadExtension extension = createExtension()

factory.createParams(extension)

verifyNoMoreInteractions(loggerMock)
}

private static def createExtension() {
Expand Down

0 comments on commit e290dd8

Please sign in to comment.