# Spring Boot Okta sdk user creation unit test

**URL:** <https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097>\
**Category:** Questions\
**Created:** [August 28, 2019, 12:24am UTC](https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097 "2019-08-28T00:24:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hernan\_plascencia](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hernan\_plascencia](https://devforum.okta.com/u/hernan_plascencia)\
**Post date:** [August 28, 2019, 12:24am UTC](https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097/1 "2019-08-28T00:24:59Z")

</div>

I am trying to create a unit test for a okta sdk user creation  
but I am not sure where to start

I am passing user class to my metod and using sdk to create a user

Client client = Clients.builder()  
.setOrgUrl("{yourOktaDomain}")  
.setClientCredentials(new TokenClientCredentials("{apiToken}"))  
.build();

User user = UserBuilder.instance()  
.setEmail("joe.coder@example.com")  
.setFirstName(“Joe”)  
.setLastName(“Code”)  
.buildAndCreate(client);

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [August 28, 2019, 2:43pm UTC](https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097/2 "2019-08-28T14:43:14Z")

</div>

Hey @hernan_plascencia!

What mocking framework are you using? I’d recommend injecting or otherwise reusing your `Client` object, that way you can mock the client and not worry about any HTTP traffic (for your unit test)

The next thing you need to think about is how you want to mock the `UserBuilder.instance()` class, you have a few options. It’s a static method so you could use something like Powermock. You _could_ also mock out the interactions the UserBuilder has with the `client` but that gets into some details your implementation doesn’t (and shouldn’t) care about.

If you are using these static methods, I’d recommend exposing those static methods in your class so the implementation could be overwritten by your test.

Overly simplistic example:

```java
class MyService {

  private final Client client;
  
  MyService(Client client) {
    this.client = client;
  }

  void doStuff() {
   User user = userBuilder()
     .setEmail("joe.coder@example.com")
     .setFirstName(“Joe”)
     .setLastName(“Code”)
     .buildAndCreate(client);
  }

  UserBuilder userBuilder() {
    return UserBuider.instance();
  }
}

```

Then you could just override the `userBuilder()` in your test to return your mock/stub.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 17, 2024, 11:58pm UTC](https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097/3 "2024-01-17T23:58:26Z")

</div>


