title: How to test a method that requires a model as a argument (Java, Springboot)
body: <p>I'm new to testing methods with JUnit. I'm currently working on a Springboot application, which I want to test properly now. However, I don't understand what needs to be done in order to test a method that has a model as an argument.</p>
  <p>The method I want to test:</p>
  <pre><code>public void updateCheckoutIncome(Model model, MonetaryAmount amount) {
          checkoutIncome = checkoutIncome.add(amount);
          model.addAttribute(&quot;checkoutIncome&quot;, checkoutIncome);
      }
  </code></pre>
  <p>I then went ahead and wrote this test file that should test the class above:</p>
  <pre><code>public class AccountingManagementTest {
  
      @SpringBootTest
      @AutoConfigureMockMvc
      public class AccountingControllerTest {
  
          @Autowired
          MockMvc mvc;
          @Autowired
          AccountingManagement accountingManagement;
  
  
          
          @Test
          @WithMockUser(roles = &quot;BOSS,EMPLOYEE&quot;)
          void updateCheckoutIncomeTest() throws Exception {
  
              MonetaryAmount checkoutIncome = Money.of(10.00, EURO);
              Model cart = new ModelAttribute(&quot;cart&quot;);
  
              accountingManagement.updateCheckoutIncome(cart, Money.of(19.99, EURO));
              Assertions.assertEquals(Money.of(29.99, EURO), checkoutIncome);
  
          }
      }
  }
  </code></pre>
  <p><strong>My question is:</strong> How do I test create the &quot;model&quot;, that I need to pass along to the method call in the test? I could find a method creating a new &quot;ModelAndView&quot; element, but my method requires a &quot;Model&quot; element. Can anyone guide me what I'm missing?</p>
  <p><em>To explain the model a little bit: This defines a view element in springboot. If you're having a model &quot;cart&quot; for example, this contains information which will be passed over to an HTML file (for example).</em></p>