title: NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open XML) file - UNIT TEST Spring
body: <p>I am trying to unit test this piece of code:</p>
  <pre><code>@Slf4j
  @Service
  @RequiredArgsConstructor
  public class LeMigrationService {
  
      private final MigrationServiceClient migrationServiceClient;
  
      public FileUploadRs process(MultipartFile file) {
  
          List&lt;String&gt; listOfCifs = null;
          try {
              listOfCifs = ExcelUtil.collectColumnByIndex(file, 0);
          } catch (Exception e) {
              LOGGER.error(&quot;Failed to load excel file content &quot; + e);
          }
  
          return migrationServiceClient.process(listOfCifs);
      }
  }
  </code></pre>
  <p>The static method:</p>
  <pre><code>public class ExcelUtil {
  
      public static List&lt;String&gt; collectColumnByIndex(MultipartFile file, int index) throws Exception {
          List&lt;String&gt; listOfCifs = new ArrayList&lt;&gt;();
  
          Workbook workbook = new XSSFWorkbook(file.getInputStream());
  
          Sheet sheet = workbook.getSheetAt(0);
          for (Row row : sheet) {
  
              Cell cell = row.getCell(index);
              int cellLength = cell.getStringCellValue().length();
  
              if (cellLength &lt; 9) {
                  StringBuilder str = new StringBuilder();
                  for (int i = 0; i &lt; 9 - cellLength; i++) {
                      str.append(&quot;0&quot;);
                  }
                  str.append(cell.getStringCellValue());
                  listOfCifs.add(str.toString());
              }
              if (cellLength &gt; 9) {
                  break;
              }
              if(cellLength == 9) {
                  listOfCifs.add(cell.getStringCellValue());
              }
          }
  
          return listOfCifs;
      }
  
  }
  </code></pre>
  <p>And finally my unit test:</p>
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class LeMigrationServiceTest {
  
      @Test
      public void processFile_FileContentIsOk() throws Exception{
  
          //arrange
          final MockMultipartFile fakeFile = new MockMultipartFile(&quot;file&quot;, &quot;file.xls&quot;, MediaType.TEXT_PLAIN_VALUE, &quot;0123456789&quot;.getBytes());
  
          //act
          final List&lt;String&gt; actual = ExcelUtil.collectColumnByIndex(fakeFile, 0);
  
          final List&lt;String&gt; expected = new ArrayList&lt;&gt;();
          expected.set(0, &quot;0123456789&quot;);
  
          //assert
          assertThat(actual).isEqualTo(expected);
      }
  
  }
  </code></pre>
  <p>When I run the test, I get the error when it calls the static method &quot;collectColumnByIndex&quot;. Apparently I do not create well the object &quot;Workbook&quot; inside the method &quot;collectColumnByIndex&quot;. Do you have any ideas of how to solve this?</p>