Posts mit dem Label java werden angezeigt. Alle Posts anzeigen
Posts mit dem Label java werden angezeigt. Alle Posts anzeigen

Dienstag, 23. Juli 2019

[Solution] Maven Proxy Issue - Maven not downloading artifacts - Maven behind Proxy

Your settings.xml - mine is in etc/maven/settings.xml on Linux - must look like:

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                                              http://maven.apache.org/xsd/settings-1.0.0.xsd">

<pluginGroups>
</pluginGroups>

<proxies>
</proxies>

<servers>

<server>
<id>myRepository</id>
<username>your user</username>
<password>your pw</password>
<configuration>
<httpConfiguration>
<all>
<usePreemptive>true</usePreemptive>
</all>
<settings>
</settings>
</httpConfiguration>
</configuration>
</server>

</servers>

<mirrors>

<mirror>
<id>myRepository</id>
<name>Proxy for XY</name>
<url>http://<maven proxy url></url>
<mirrorOf>*,!sonar</mirrorOf>
</mirror>
</mirrors>

<profiles>

</profiles>

</settings>




Montag, 17. Juni 2019

Intellij Order Of Imports

IntelliJ sometimes changes the appearance of imports in the code on checkout when organizing imports.

To control that, one can adjust the settings:

Settings -> Editor -> Code Style -> Java -> Layout static imports separately

Change the order as you need, IntelliJ will sort the imports accordingly.

Montag, 29. April 2019

Spring Security - get User Name

If you want to retrieve the name of  a logged in user, do this:


import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
private String getUserName() {
    Object principal = SecurityContextHolder
          .getContext()
          .getAuthentication()
          .getPrincipal();

    String userName;

    if (principal instanceof UserDetails) {
        userName = ((UserDetails)principal).getUsername();
    } else {
        userName = principal.toString();
    }
    return userName;
}

Mittwoch, 24. April 2019

Recover and Restore System Properties with Java - JUnit and more - Free program

Sometimes it is necessary to change System Properties. Maybe for a Test or something else. This program and test will recover and restore the System Properties to their initial state.
The program and test may be used freely under GNU General Public License Version and is brought to you by Harder IT Consulting www.harder-it-consulting.de
  

Mittwoch, 17. April 2019

Mock static methods with Mockito in Java (mock, static, method, java)


import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.BDDMockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;


@RunWith(PowerMockRunner.class)
@PrepareForTest(MyStatic.class)
...


@Test
public void someTest() {
    
    //given    
    PowerMockito.mockStatic(MyStatic.class);
    BDDMockito.given(MyStatic.someStaticMethod()).willReturn(...);

    //when
    ...

    //then     
    PowerMockito.verifyStatic();
    MyStatic.someStaticMethod();

    assertThat(//your further asserts....

NEW BLOG! http://cleancode.consulting/

Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at  http://cleancode.consulting/