Montag, 27. Mai 2019

My Advice to Founders + Anyone Starting Their Own Business


Here is my advice when you are about to start your own business.

No matter what business you start, at a certain level it is all the same. 

#1 Get a Coach

Look for someone who is able to help you out by giving advice to you. The best thing was if this person has already achieved what you want to achieve. For instance, my own Coach is successfully running multiple companies. It may cost you money but investing in yourself is the best thing you can do!

#2 Manage yourself as a boss and employee in one. 

Enjoy the freedom and flexibility regarding time, appointments and mindset - you are your own boss now. Because of this: negotiate clever and be tough as nails regarding your ressource planning, even more with yourself ;)

#3 Go with the flow 

It is easier for me to accept the limits or moods of my employees than accepting my own. But if I hit the floor because of sleep deprivation or anxiety, my business will go down, too. Thus: 

#4 Be kind to yourself

... as you do already have proven that you have the courage to walk your own path. Being kind to yourself will help you to not crack under the pressure. 

#5 Fun is the most important thing

Life is too short. Never forget that stress is a powerful force. Do always remember that fun is what this is about. The rest will follow - #lawOfAttraction 

Wish you much success with your business and all the best! 
Tim

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....

Donnerstag, 28. März 2019

Scan Files For Search Terms - Java Program Code + Download


I have written a small progam to help us out. Download

Maven - How to create Maven Java Project From Scratch

Install Maven, go to the Apache Site

In your command line enter: 

D:\>mvn archetype:generate -DgroupId=de.consulting.it.harder -DartifactId=java-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This will create a basic Maven project from scratch.

Update your POM with the following properties to define the Compiler:

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>


Define JUnit as your first dependency for Testing with scope "test":

    <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
    </dependency>


I suggest Hamcrest, if you do not know it yet:


     <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->               
    </dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>        
        <scope>test</scope>
    </dependency>

If you want to package as executable JAR:
$ mvn clean package

If you want to start the  JAR:
$ java -jar <your jar file name here> 

Here is the POM with all attributes for executable JARs: Download Example POM

Dienstag, 19. März 2019

How To Resolve GIT Merge Conflicts with IntelliJ

Resolve a Merge Conflict in GIT with IntelliJ


Let us assume you are using Bitbucket or a similar tool to administrate and host your GIT repositories.
You are using the Open Source principle with Pull Request, Review, Merge: 
  • Push changes
  • Assign a reviewer or two
  • Depending on your team agreement, either you or the reviewer will merge the feature onto your main develop branch (I will call it "develop"). The pull request is merged.

In some cases there will be incompatible changes which happened on the develop branch when you are about to merge.
The pull request cannot be merged due to merge conflicts with your develop branch.

1) Checkout the current develop branch from remote locally.
2) Checkout the feature branch locally
3) When you have switched to your feature branch, use this command:
$git merge develop
4) The merge conflicts are now shown.
5) Use IntelliiJ Merge Tool to resolve the merge conflicts: https://www.jetbrains.com/help/idea/resolving-conflicts.html
Note: there is also the standard GIT merge-tool which will work as a stand-alone without an IDE.
6) Push everything to your remote feature branch
7) Merge the pull request via Bitbucket or other tool.

Freitag, 23. November 2018

GIT - Replace local branch with remote branch.


  • Delete the local branch:
  git branch -d local_branch
  • Fetch remote branch: 
 git fetch origin remote_branch
  • Rebuild the local branch with remote content: 
 git checkout -b local_branch origin/remote_branch


Donnerstag, 30. August 2018

GIT Troubleshooting - revert and pull not possible?

Sometimes a file does not differ from the repository version. But GIT shows it as modified and does not accept a revert.

This file, however should not be commited, because it has not changed, but is simply not properly managed by GIT.

This is related to GIT working in file mode.

Try this and then pull again:

$git config core.fileMode false

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/