Java 类org.mockito.BDDMockito 实例源码

项目:spring-cloud-release-tools    文件:SaganUpdaterTest.java   
@Test public void should_update_sagan_for_milestone() throws Exception {
    this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));

    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.0.0.M1",
                    "http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
}
项目:li-android-sdk-core    文件:LiClientManagerTest.java   
@Before
public void setUpTest() throws Exception {
    // Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
    // inject the mocks in the test the initMocks method needs to be called.
    MockitoAnnotations.initMocks(this);

    mContext = mock(Activity.class);
    mMockSharedPreferences = mock(SharedPreferences.class);
    resource = mock(Resources.class);
    when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mMockSharedPreferences);
    when(mMockSharedPreferences.getString(anyString(), anyString())).thenReturn("foobar");
    when(mContext.getResources()).thenReturn(resource);
    when(resource.getBoolean(anyInt())).thenReturn(true);
    liSDKManager = LiSDKManager.init(mContext, TestHelper.getTestAppCredentials());
    liRestv2Client = PowerMockito.mock(LiRestv2Client.class);
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
}
项目:li-android-sdk-core    文件:LiBaseGetClientTest.java   
@Before
    public void setUp() throws Exception {

        mContext = Mockito.mock(Activity.class);
        mMockSharedPreferences = Mockito.mock(SharedPreferences.class);
        resource = Mockito.mock(Resources.class);
        when(resource.getBoolean(anyInt())).thenReturn(true);
        when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mMockSharedPreferences);
        when(mMockSharedPreferences.getString(anyString(), anyString())).thenReturn("foobar");
        when(mContext.getResources()).thenReturn(resource);
        JsonObject jsonObject = new Gson().fromJson(defaultSettings, JsonObject.class);
        liSDKManager = LiSDKManager.init(mContext, TestHelper.getTestAppCredentials());
        liRestv2Client = mock(LiRestv2Client.class);
//        when(liSDKManager.getTenant()).thenReturn("test");
        PowerMockito.mockStatic(LiRestv2Client.class);
        BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
        liClient = new LiBaseGetClient(mContext, LI_ARTICLES_CLIENT_BASE_LIQL, LI_ARTICLES_CLIENT_TYPE, LI_ARTICLES_QUERYSETTINGS_TYPE, LiMessage.class);


    }
项目:li-android-sdk-core    文件:LiBaseClientTest.java   
@Before
    public void setUp() throws Exception, LiRestResponseException {

        mContext = Mockito.mock(Activity.class);
        mMockSharedPreferences = Mockito.mock(SharedPreferences.class);
        resource = Mockito.mock(Resources.class);
        when(resource.getBoolean(anyInt())).thenReturn(true);
        when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mMockSharedPreferences);
        when(mMockSharedPreferences.getString(anyString(), anyString())).thenReturn("foobar");
        when(mContext.getResources()).thenReturn(resource);
        liSDKManager = LiSDKManager.init(mContext, TestHelper.getTestAppCredentials());
        liRestv2Client = mock(LiRestv2Client.class);
        MockitoAnnotations.initMocks(this);
//        when(liSDKManager.getTenant()).thenReturn("test");
        liClientManager = mock(LiClientManager.class);
        PowerMockito.mockStatic(LiRestv2Client.class);
        BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
        PowerMockito.mockStatic(LiClientManager.class);
    }
项目:li-android-sdk-core    文件:LiQueryBuilderTest.java   
@Before
public void setUpTest() throws Exception {
    MockitoAnnotations.initMocks(this);
    mContext = mock(Activity.class);
    mMockSharedPreferences = mock(SharedPreferences.class);
    resource = mock(Resources.class);
    when(resource.getBoolean(anyInt())).thenReturn(true);
    when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mMockSharedPreferences);
    when(mMockSharedPreferences.getString(anyString(), anyString())).thenReturn("foobar");
    when(mContext.getResources()).thenReturn(resource);
    JsonObject jsonObject = new Gson().fromJson(defaultSettings, JsonObject.class);

    liDefaultQueryHelper = mock(LiDefaultQueryHelper.class);
    when(liDefaultQueryHelper.getDefaultSetting()).thenReturn(jsonObject);
    PowerMockito.mockStatic(LiDefaultQueryHelper.class);
    when(LiDefaultQueryHelper.initHelper(mContext)).thenReturn(liDefaultQueryHelper);
    BDDMockito.given(LiDefaultQueryHelper.getInstance()).willReturn(liDefaultQueryHelper);

    liSDKManager = LiSDKManager.init(mContext, TestHelper.getTestAppCredentials());

}
项目:ponto-inteligente-api    文件:LancamentoControllerTest.java   
@Test
@WithMockUser
public void testCadastrarLancamento() throws Exception {
    Lancamento lancamento = obterDadosLancamento();
    BDDMockito.given(this.funcionarioService.buscarPorId(Mockito.anyLong())).willReturn(Optional.of(new Funcionario()));
    BDDMockito.given(this.lancamentoService.persistir(Mockito.any(Lancamento.class))).willReturn(lancamento);

    mvc.perform(MockMvcRequestBuilders.post(URL_BASE)
            .content(this.obterJsonRequisicaoPost())
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.data.id").value(ID_LANCAMENTO))
            .andExpect(jsonPath("$.data.tipo").value(TIPO))
            .andExpect(jsonPath("$.data.data").value(this.dateFormat.format(DATA)))
            .andExpect(jsonPath("$.data.funcionarioId").value(ID_FUNCIONARIO))
            .andExpect(jsonPath("$.errors").isEmpty());
}
项目:ServiceCOLDCache    文件:DebugClientHandlerTest.java   
@Test
public void testChannelRead0_debugOnResponse() {
    Mockito.when(LOGGER.isDebugEnabled()).thenReturn(true);
    Mockito.when(response.getStatus()).thenReturn(HttpResponseStatus.OK);
    Mockito.when(response.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1);
    Mockito.when(headers.isEmpty()).thenReturn(false);
    Set<String> headersSet = new HashSet<>();
    headersSet.add("no-cache");
    Mockito.when(headers.names()).thenReturn(headersSet);
    List<String> noCacheValues = new ArrayList<>();
    noCacheValues.add("private");
    Mockito.when(headers.getAll("no-cache")).thenReturn(noCacheValues);
    PowerMockito.mockStatic(HttpHeaders.class);
    BDDMockito.given(HttpHeaders.isTransferEncodingChunked(response)).willReturn(true);
    handler.channelRead0(ctx, response);
    Mockito.verify(LOGGER, Mockito.times(1)).debug("STATUS: " + HttpResponseStatus.OK);
    Mockito.verify(LOGGER, Mockito.times(1)).debug("VERSION: " + HttpVersion.HTTP_1_1);
    Mockito.verify(LOGGER, Mockito.times(1)).debug("HEADER: no-cache = private");
    Mockito.verify(LOGGER, Mockito.times(1)).debug("CHUNKED CONTENT {");


    BDDMockito.given(HttpHeaders.isTransferEncodingChunked(response)).willReturn(false);
    handler.channelRead0(ctx, response);
    Mockito.verify(LOGGER, Mockito.times(1)).debug("CONTENT {");
}
项目:hipay-fullservice-sdk-android    文件:LoggerTest.java   
@Test
public void testLogger() throws Exception {

    String helloWorld = "Hello world!";

    BDDMockito.given(Log.d(Logger.TAG,helloWorld)).willReturn(Log.DEBUG);
    BDDMockito.given(Log.v(Logger.TAG,helloWorld)).willReturn(Log.VERBOSE);
    BDDMockito.given(Log.i(Logger.TAG,helloWorld)).willReturn(Log.INFO);
    BDDMockito.given(Log.e(Logger.TAG,helloWorld)).willReturn(Log.ERROR);
    BDDMockito.given(Log.w(Logger.TAG,helloWorld)).willReturn(Log.WARN);

    assertEquals(Logger.d(helloWorld), Log.DEBUG);
    assertEquals(Logger.v(helloWorld), Log.VERBOSE);
    assertEquals(Logger.i(helloWorld), Log.INFO);
    assertEquals(Logger.e(helloWorld), Log.ERROR);
    assertEquals(Logger.w(helloWorld), Log.WARN);

}
项目:hipay-fullservice-sdk-android    文件:FraudScreeningMapperTest.java   
@Test
public void testMethods() throws Exception {

    FraudScreeningMapper fraudScreeningMapper = new FraudScreeningMapper(jsonObject);

    when(jsonObject.optString("result", null)).thenReturn("bLOCked");
    when(jsonObject.opt("scoring")).thenReturn("1");
    when(jsonObject.optString("review", null)).thenReturn("denIEd");

    BDDMockito.given(TextUtils.isDigitsOnly("1")).willReturn(true);

    FraudScreening compareFraudScreeningCompare = new FraudScreening();
    compareFraudScreeningCompare.setScoring(1);
    compareFraudScreeningCompare.setResult(FraudScreening.FraudScreeningResult.FraudScreeningResultBlocked);
    compareFraudScreeningCompare.setReview(FraudScreening.FraudScreeningReview.FraudScreeningReviewDenied);

    FraudScreening fraudScreeningTest = fraudScreeningMapper.mappedObject();

    assertEquals(fraudScreeningTest.getResult(), compareFraudScreeningCompare.getResult());
    assertEquals(fraudScreeningTest.getReview(), compareFraudScreeningCompare.getReview());
    assertEquals(fraudScreeningTest.getScoring(), compareFraudScreeningCompare.getScoring());

}
项目:spring4-understanding    文件:ServletTestExecutionListenerTests.java   
@Test
public void standardApplicationContext() throws Exception {
    BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(getClass());
    given(testContext.getApplicationContext()).willReturn(mock(ApplicationContext.class));

    listener.beforeTestClass(testContext);
    assertAttributeExists();

    listener.prepareTestInstance(testContext);
    assertAttributeExists();

    listener.beforeTestMethod(testContext);
    assertAttributeExists();

    listener.afterTestMethod(testContext);
    assertAttributeExists();
}
项目:spring4-understanding    文件:ServletTestExecutionListenerTests.java   
@Test
public void legacyWebTestCaseWithoutExistingRequestAttributes() throws Exception {
    BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(LegacyWebTestCase.class);

    RequestContextHolder.resetRequestAttributes();
    assertAttributesNotAvailable();

    listener.beforeTestClass(testContext);

    listener.prepareTestInstance(testContext);
    assertAttributesNotAvailable();
    verify(testContext, times(0)).setAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);
    given(testContext.getAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE)).willReturn(null);

    listener.beforeTestMethod(testContext);
    assertAttributesNotAvailable();
    verify(testContext, times(0)).setAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);

    listener.afterTestMethod(testContext);
    verify(testContext, times(1)).removeAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE);
    assertAttributesNotAvailable();
}
项目:spring4-understanding    文件:ServletTestExecutionListenerTests.java   
@Test
public void legacyWebTestCaseWithPresetRequestAttributes() throws Exception {
    BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(LegacyWebTestCase.class);

    listener.beforeTestClass(testContext);
    assertAttributeExists();

    listener.prepareTestInstance(testContext);
    assertAttributeExists();
    verify(testContext, times(0)).setAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);
    given(testContext.getAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE)).willReturn(null);

    listener.beforeTestMethod(testContext);
    assertAttributeExists();
    verify(testContext, times(0)).setAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);
    given(testContext.getAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE)).willReturn(null);

    listener.afterTestMethod(testContext);
    verify(testContext, times(1)).removeAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE);
    assertAttributeExists();
}
项目:checkstyle-backport-jre6    文件:ImportControlLoaderTest.java   
@Test
public void testInputStreamThatFailsOnClose() throws Exception {
    final InputStream inputStream = PowerMockito.mock(InputStream.class);
    Mockito.doThrow(IOException.class).when(inputStream).close();
    final int available = Mockito.doThrow(IOException.class).when(inputStream).available();

    final URL url = PowerMockito.mock(URL.class);
    BDDMockito.given(url.openStream()).willReturn(inputStream);

    final URI uri = PowerMockito.mock(URI.class);
    BDDMockito.given(uri.toURL()).willReturn(url);

    try {
        ImportControlLoader.load(uri);
        //Using available to bypass 'ignored result' warning
        fail("exception expected " + available);
    }
    catch (CheckstyleException ex) {
        assertSame("Invalid exception class", IOException.class, ex.getCause().getClass());
    }
    Mockito.verify(inputStream).close();
}
项目:checkstyle-backport-jre6    文件:ImportControlLoaderTest.java   
@Test
public void testInputStreamFailsOnRead() throws Exception {
    final InputStream inputStream = PowerMockito.mock(InputStream.class);
    final int available = Mockito.doThrow(IOException.class).when(inputStream).available();

    final URL url = PowerMockito.mock(URL.class);
    BDDMockito.given(url.openStream()).willReturn(inputStream);

    final URI uri = PowerMockito.mock(URI.class);
    BDDMockito.given(uri.toURL()).willReturn(url);

    try {
        ImportControlLoader.load(uri);
        //Using available to bypass 'ignored result' warning
        fail("exception expected " + available);
    }
    catch (CheckstyleException ex) {
        assertSame("Invalid exception class",
                SAXParseException.class, ex.getCause().getClass());
    }
}
项目:checkstyle-backport-jre6    文件:FilterUtilsTest.java   
@Test
@PrepareForTest({FilterUtils.class, CommonUtils.class})
public void testExceptionOnClosing() throws Exception {
    final File file = temporaryFolder.newFile("existing.xml");
    final InputStream inputStream = PowerMockito.mock(InputStream.class);
    Mockito.doThrow(IOException.class).when(inputStream).close();

    final URL url = PowerMockito.mock(URL.class);
    BDDMockito.given(url.openStream()).willReturn(inputStream);

    final URI uri = PowerMockito.mock(URI.class);
    BDDMockito.given(uri.toURL()).willReturn(url);

    PowerMockito.mockStatic(CommonUtils.class);

    final String fileName = file.getPath();
    BDDMockito.given(CommonUtils.getUriByFilename(fileName)).willReturn(uri);
    assertFalse("Should be false, because error on close",
            FilterUtils.isFileExists(fileName));
}
项目:PermissMe    文件:PermissMeUtilsTest.java   
@Test
public void testGetDeniedPermissions_whenMixPermissionsGrantedAndUngranted_returnUngrantedPermissions() {
    // Case 3: 2 permissions, 1 ungranted, 1 granted
    BDDMockito.given(
            PermissionChecker.checkSelfPermission(
                    any(Context.class),
                    eq(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            )
    ).willReturn(PackageManager.PERMISSION_DENIED);

    BDDMockito.given(
            PermissionChecker.checkSelfPermission(any(Context.class), eq(Manifest.permission.READ_SMS))
    ).willReturn(PackageManager.PERMISSION_GRANTED);

    final String[] deniedPermissions = PermissMeUtils.getDeniedPermissions(
            mockContext,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_SMS
    );
    assertNotNull(deniedPermissions);
    assertTrue(deniedPermissions.length == 1);
    assertTrue(deniedPermissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE));
}
项目:PermissMe    文件:PermissMeUtilsTest.java   
@Test
public void testGetDeniedPermissions_whenAllPermissionsUngranted_returnAllPermissions() {
    // Case 4: 2 permissions, 2 ungranted
    BDDMockito.given(
            PermissionChecker.checkSelfPermission(any(Context.class), anyString())
    ).willReturn(PackageManager.PERMISSION_DENIED);

    String[] deniedPermissions = PermissMeUtils.getDeniedPermissions(
            mockContext,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_SMS
    );
    assertNotNull(deniedPermissions);
    assertTrue(deniedPermissions.length == 2);
    assertTrue(deniedPermissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE));
    assertTrue(deniedPermissions[1].equals(Manifest.permission.READ_SMS));
}
项目:Zipkin    文件:HttpServletRequestExtractorTests.java   
@Test
public void should_not_throw_exception_if_parent_id_is_invalid() {
    BDDMockito.given(this.request.getHeader(Span.TRACE_ID_NAME))
            .willReturn(String.valueOf(new Random().nextLong()));
    BDDMockito.given(this.request.getHeader(Span.SPAN_ID_NAME))
            .willReturn(String.valueOf(new Random().nextLong()));
    BDDMockito.given(this.request.getHeader(Span.PARENT_ID_NAME))
            .willReturn("invalid");

    try {
        this.extractor.joinTrace(this.request);
        fail("should throw an exception");
    } catch (IllegalArgumentException e) {
        then(e).hasMessageContaining("Malformed id");
    }
}
项目:Zipkin    文件:SleuthRxJavaSchedulersHookTests.java   
@Test
public void should_not_create_a_span_when_current_thread_should_be_ignored()
        throws ExecutionException, InterruptedException {
    String threadNameToIgnore = "^MyCustomThread.*$";
    RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
    SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
        this.tracer, this.traceKeys, Collections.singletonList(threadNameToIgnore));
    Future<Void> hello = executorService().submit((Callable<Void>) () -> {
        Action0 action = schedulersHook.onSchedule(() -> {
            caller = new StringBuilder("hello");
        });
        action.call();
        return null;
    });

    hello.get();

    BDDMockito.then(this.tracer).should(never()).createSpan(anyString());
    BDDMockito.then(this.tracer).should(never()).continueSpan(any());
}
项目:Zipkin    文件:SpringCloudSleuthDocTests.java   
@Test
public void should_set_runnable_name_to_annotated_value()
        throws ExecutionException, InterruptedException {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    SpanNamer spanNamer = new DefaultSpanNamer();
    Tracer tracer = Mockito.mock(Tracer.class);

    // tag::span_name_annotated_runnable_execution[]
    Runnable runnable = new TraceRunnable(tracer, spanNamer, new TaxCountingRunnable());
    Future<?> future = executorService.submit(runnable);
    // ... some additional logic ...
    future.get();
    // end::span_name_annotated_runnable_execution[]

    BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
}
项目:Zipkin    文件:SpringCloudSleuthDocTests.java   
@Test
public void should_set_runnable_name_to_to_string_value()
        throws ExecutionException, InterruptedException {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    SpanNamer spanNamer = new DefaultSpanNamer();
    Tracer tracer = Mockito.mock(Tracer.class);

    // tag::span_name_to_string_runnable_execution[]
    Runnable runnable = new TraceRunnable(tracer, spanNamer, new Runnable() {
        @Override public void run() {
            // perform logic
        }

        @Override public String toString() {
            return "calculateTax";
        }
    });
    Future<?> future = executorService.submit(runnable);
    // ... some additional logic ...
    future.get();
    // end::span_name_to_string_runnable_execution[]

    BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
    executorService.shutdown();
}
项目:infobip-bean-validation    文件:CustomConstraintViolationExceptionMapperTest.java   
@Test
public void shouldUseCustomConstraintViolationExceptionMapper() {

    Throwable thrown = catchThrowable(() -> customValidatedService.requireNonNull(null));

    then(thrown).isInstanceOf(RuntimeException.class);
    BDDMockito.then(mockMapper).should().apply(any());
}
项目:spring-cloud-release-tools    文件:PropertyStorerTests.java   
private String containsWarnMsgAboutEmptyVersion() {
    return BDDMockito.argThat(new TypeSafeMatcher<String>() {
        @Override protected boolean matchesSafely(String item) {
            return item.contains("is empty. Will not set it");
        }

        @Override public void describeTo(Description description) {

        }
    });
}
项目:spring-cloud-release-tools    文件:SaganUpdaterTest.java   
@Test public void should_update_sagan_for_rc() throws Exception {
    this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1"));

    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.0.0.RC1",
                    "http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
}
项目:spring-cloud-release-tools    文件:SaganUpdaterTest.java   
@Test public void should_update_sagan_from_master() throws Exception {
    ProjectVersion projectVersion = version("1.0.0.BUILD-SNAPSHOT");

    this.saganUpdater.updateSagan("master", projectVersion, projectVersion);

    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT",
                    "http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
项目:spring-cloud-release-tools    文件:SaganUpdaterTest.java   
@Test public void should_update_sagan_from_release_version() throws Exception {
    ProjectVersion projectVersion = version("1.0.0.RELEASE");

    this.saganUpdater.updateSagan("master", projectVersion, projectVersion);

    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE",
                    "http://cloud.spring.io/spring-cloud-static/foo/{version}/", "GENERAL_AVAILABILITY")));
    BDDMockito.then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.0.1.BUILD-SNAPSHOT",
                    "http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
项目:spring-cloud-release-tools    文件:SaganUpdaterTest.java   
@Test public void should_update_sagan_from_non_master() throws Exception {
    ProjectVersion projectVersion = version("1.1.0.BUILD-SNAPSHOT");

    this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion);

    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
            BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT",
                    "http://cloud.spring.io/foo/1.1.x/", "SNAPSHOT")));
}
项目:spring-cloud-release-tools    文件:AcceptanceTests.java   
@Test
public void should_perform_a_release_of_consul() throws Exception {
    File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), this.springCloudConsulProject);
    pomVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    pomParentVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    File project = GitTestUtils.clonedProject(this.tmp.newFolder(), tmpFile("spring-cloud-consul"));
    GitTestUtils.setOriginOnProjectToTmp(origin, project);
    SpringReleaser releaser = releaser(project, "vCamden.SR5", "1.1.2.RELEASE");

    releaser.release();

    Iterable<RevCommit> commits = listOfCommits(project);
    Iterator<RevCommit> iterator = commits.iterator();
    tagIsPresentInOrigin(origin, "v1.1.2.RELEASE");
    commitIsPresent(iterator, "Bumping versions to 1.2.1.BUILD-SNAPSHOT after release");
    commitIsPresent(iterator, "Going back to snapshots");
    commitIsPresent(iterator, "Update SNAPSHOT to 1.1.2.RELEASE");
    pomVersionIsEqualTo(project, "1.2.1.BUILD-SNAPSHOT");
    pomParentVersionIsEqualTo(project, "1.2.1.BUILD-SNAPSHOT");
    then(this.gitHandler.closedMilestones).isTrue();
    then(emailTemplate()).exists();
    then(emailTemplateContents())
            .contains("Spring Cloud Camden.SR5 available")
            .contains("Spring Cloud Camden SR5 Train release");
    then(blogTemplate()).exists();
    then(blogTemplateContents())
            .contains("I am pleased to announce that the Service Release 5 (SR5)");
    then(releaseNotesTemplate()).exists();
    then(releaseNotesTemplateContents())
            .contains("Camden.SR5")
            .contains("- Spring Cloud Config `1.2.2.RELEASE` ([issues](http://foo.bar.com/1.2.2.RELEASE))")
            .contains("- Spring Cloud Aws `1.1.3.RELEASE` ([issues](http://foo.bar.com/1.1.3.RELEASE))");
    // once for updating GA
    // second time to update SNAPSHOT
    BDDMockito.then(this.saganClient).should(BDDMockito.times(2)).updateRelease(BDDMockito.eq("spring-cloud-consul"),
            BDDMockito.anyList());
    BDDMockito.then(this.saganClient).should().deleteRelease("spring-cloud-consul", "1.1.2.BUILD-SNAPSHOT");
}
项目:spring-cloud-release-tools    文件:AcceptanceTests.java   
@Test
public void should_perform_a_release_of_consul_rc1() throws Exception {
    File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), this.springCloudConsulProject);
    pomVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    pomParentVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    File project = GitTestUtils.clonedProject(this.tmp.newFolder(), tmpFile("spring-cloud-consul"));
    GitTestUtils.setOriginOnProjectToTmp(origin, project);
    SpringReleaser releaser = releaser(project, "Dalston.RC1", "1.2.0.RC1");

    releaser.release();

    Iterable<RevCommit> commits = listOfCommits(project);
    tagIsPresentInOrigin(origin, "v1.2.0.RC1");
    commitIsNotPresent(commits, "Bumping versions to 1.2.1.BUILD-SNAPSHOT after release");
    Iterator<RevCommit> iterator = listOfCommits(project).iterator();
    commitIsPresent(iterator, "Going back to snapshots");
    commitIsPresent(iterator, "Update SNAPSHOT to 1.2.0.RC1");
    pomVersionIsEqualTo(project, "1.2.0.BUILD-SNAPSHOT");
    pomParentVersionIsEqualTo(project, "1.2.0.BUILD-SNAPSHOT");
    then(this.gitHandler.closedMilestones).isTrue();
    then(emailTemplate()).exists();
    then(emailTemplateContents())
            .contains("Spring Cloud Dalston.RC1 available")
            .contains("Spring Cloud Dalston RC1 Train release");
    then(blogTemplate()).exists();
    then(blogTemplateContents())
            .contains("I am pleased to announce that the Release Candidate 1 (RC1)");
    then(tweetTemplate()).exists();
    then(tweetTemplateContents())
            .contains("The Dalston.RC1 version of @springcloud has been released!");
    then(releaseNotesTemplate()).exists();
    then(releaseNotesTemplateContents())
            .contains("Dalston.RC1")
            .contains("- Spring Cloud Build `1.3.1.RELEASE` ([issues](http://foo.bar.com/1.3.1.RELEASE))")
            .contains("- Spring Cloud Bus `1.3.0.M1` ([issues](http://foo.bar.com/1.3.0.M1))");
    BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("spring-cloud-consul"),
            BDDMockito.anyList());
}
项目:spring-cloud-release-tools    文件:AcceptanceTests.java   
@Test
public void should_generate_templates_only() throws Exception {
    File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), this.springCloudConsulProject);
    pomVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    pomParentVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
    File project = GitTestUtils.clonedProject(this.tmp.newFolder(), tmpFile("spring-cloud-consul"));
    GitTestUtils.setOriginOnProjectToTmp(origin, project);
    SpringReleaser releaser = templateOnlyReleaser(project, "Dalston.RC1", "1.2.0.RC1");

    releaser.release();

    then(this.gitHandler.closedMilestones).isFalse();
    then(emailTemplate()).exists();
    then(emailTemplateContents())
            .contains("Spring Cloud Dalston.RC1 available")
            .contains("Spring Cloud Dalston RC1 Train release");
    then(blogTemplate()).exists();
    then(blogTemplateContents())
            .contains("I am pleased to announce that the Release Candidate 1 (RC1)");
    then(tweetTemplate()).exists();
    then(tweetTemplateContents())
            .contains("The Dalston.RC1 version of @springcloud has been released!");
    then(releaseNotesTemplate()).exists();
    then(releaseNotesTemplateContents())
            .contains("Dalston.RC1")
            .contains("- Spring Cloud Build `1.3.1.RELEASE` ([issues](http://foo.bar.com/1.3.1.RELEASE))")
            .contains("- Spring Cloud Bus `1.3.0.M1` ([issues](http://foo.bar.com/1.3.0.M1)");
    BDDMockito.then(this.saganClient).should(BDDMockito.never()).updateRelease(
            BDDMockito.anyString(), BDDMockito.anyList());
}
项目:li-android-sdk-core    文件:LiBasePostClientTest.java   
@Before
public void setUp() throws LiRestResponseException {
    mContext = Mockito.mock(Activity.class);
    liRestv2Client = mock(LiRestv2Client.class);
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
    liClient = new LiBasePostClient(mContext, BASE_PATH);
    PowerMockito.verifyStatic();
}
项目:li-android-sdk-core    文件:LiBasePutClientTest.java   
@Before
public void setUp() throws LiRestResponseException {
    mContext = Mockito.mock(Activity.class);
    liRestv2Client = mock(LiRestv2Client.class);
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
    liClient = new LiBasePutClient(mContext, BASE_PATH);
    PowerMockito.verifyStatic();
}
项目:li-android-sdk-core    文件:LiBaseClientTest.java   
@Test
public void testGetGsonForNull() throws LiRestResponseException {
    LiRestv2Client liRestv2Client = null;
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
    LiBaseClient liClient = new LiBaseGetClient(mContext, LI_ARTICLES_CLIENT_BASE_LIQL, LI_ARTICLES_CLIENT_TYPE, LI_ARTICLES_QUERYSETTINGS_TYPE, LiMessage.class);
    Assert.assertEquals(null, liClient.getGson());
    PowerMockito.verifyStatic();
}
项目:li-android-sdk-core    文件:LiBaseDeleteClientTest.java   
@Before
public void setUp() throws LiRestResponseException {
    mContext = Mockito.mock(Activity.class);
    liRestv2Client = mock(LiRestv2Client.class);
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
    liClient = new LiBaseDeleteClient(mContext, BASE_PATH);
    PowerMockito.verifyStatic();
}
项目:li-android-sdk-core    文件:LiSystemClockTest.java   
@Test
public void testGetCurrentTimeMillis() {
    PowerMockito.mockStatic(System.class);
    BDDMockito.given(System.currentTimeMillis()).willReturn(currentTime);
    long output = LiSystemClock.INSTANCE.getCurrentTimeMillis();
    PowerMockito.verifyStatic();
    Assert.assertEquals(1L, output);
}
项目:li-android-sdk-core    文件:LiRestv2ClientTest.java   
@Test
public void testValidateResponse() throws Exception {
    context = Mockito.mock(Activity.class);
    PowerMockito.mockStatic(LiClientManager.class);
    LiClientManager liClientManager = PowerMockito.mock(LiClientManager.class);

    PowerMockito.mockStatic(SSLContext.class);
    SSLContext sslContext = PowerMockito.mock(SSLContext.class);
    when(sslContext.getInstance("SSL")).thenReturn(sslContext);
    Mockito.doNothing().when(sslContext).init(isA(KeyManager[].class), isA(TrustManager[].class), isA(SecureRandom.class));
    SSLSocketFactory socketFactory = mock(SSLSocketFactory.class);
    when(sslContext.getSocketFactory()).thenReturn(socketFactory);

    PowerMockito.mockStatic(Platform.class);
    Platform platform = PowerMockito.mock(Platform.class);
    X509TrustManager trustManager = mock(X509TrustManager.class);
    when(platform.trustManager(socketFactory)).thenReturn(trustManager);
    BDDMockito.given(Platform.get()).willReturn(platform);

    BDDMockito.given(SSLContext.getInstance("SSL")).willReturn(sslContext);

    LiRestv2Client liRestv2Client = LiRestv2Client.getInstance();
    final LiBaseResponse liBaseResponse = mock(LiBaseResponse.class);
    when(liBaseResponse.getHttpCode()).thenReturn(200);
    LiRestv2Client liRestv2ClientSpy = spy(LiRestv2Client.class);
    doReturn(liBaseResponse).when(liRestv2ClientSpy).processSync(isA(LiBaseRestRequest.class));

    LiRestV2Request liBaseRestRequest = new LiRestV2Request(context, liql, "message");
    liBaseRestRequest.addQueryParam("test");

    LiBaseResponse liBaseResponse1 = liRestv2ClientSpy.processSync(liBaseRestRequest);

    Assert.assertEquals(200, liBaseResponse1.getHttpCode());
    PowerMockito.verifyStatic();
}
项目:ponto-inteligente-api    文件:LancamentoServiceTest.java   
@Before
public void setUp() throws Exception {
    BDDMockito
            .given(this.lancamentoRepository.findByFuncionarioId(Mockito.anyLong(), Mockito.any(PageRequest.class)))
            .willReturn(new PageImpl<Lancamento>(new ArrayList<Lancamento>()));
    BDDMockito.given(this.lancamentoRepository.findOne(Mockito.anyLong())).willReturn(new Lancamento());
    BDDMockito.given(this.lancamentoRepository.save(Mockito.any(Lancamento.class))).willReturn(new Lancamento());
}
项目:ponto-inteligente-api    文件:FuncionarioServiceTest.java   
@Before
public void setUp() throws Exception {
    BDDMockito.given(this.funcionarioRepository.save(Mockito.any(Funcionario.class))).willReturn(new Funcionario());
    BDDMockito.given(this.funcionarioRepository.findOne(Mockito.anyLong())).willReturn(new Funcionario());
    BDDMockito.given(this.funcionarioRepository.findByEmail(Mockito.anyString())).willReturn(new Funcionario());
    BDDMockito.given(this.funcionarioRepository.findByCpf(Mockito.anyString())).willReturn(new Funcionario());
}
项目:ponto-inteligente-api    文件:EmpresaControllerTest.java   
@Test
@WithMockUser
public void testBuscarEmpresaCnpjInvalido() throws Exception {
    BDDMockito.given(this.empresaService.buscarPorCnpj(Mockito.anyString())).willReturn(Optional.empty());

    mvc.perform(MockMvcRequestBuilders.get(BUSCAR_EMPRESA_CNPJ_URL + CNPJ).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isBadRequest())
            .andExpect(jsonPath("$.errors").value("Empresa não encontrada para o CNPJ " + CNPJ));
}
项目:ponto-inteligente-api    文件:EmpresaControllerTest.java   
@Test
@WithMockUser
public void testBuscarEmpresaCnpjValido() throws Exception {
    BDDMockito.given(this.empresaService.buscarPorCnpj(Mockito.anyString()))
            .willReturn(Optional.of(this.obterDadosEmpresa()));

    mvc.perform(MockMvcRequestBuilders.get(BUSCAR_EMPRESA_CNPJ_URL + CNPJ)
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.data.id").value(ID))
            .andExpect(jsonPath("$.data.razaoSocial", equalTo(RAZAO_SOCIAL)))
            .andExpect(jsonPath("$.data.cnpj", equalTo(CNPJ)))
            .andExpect(jsonPath("$.errors").isEmpty());
}