Object getCellValue(Cell cell, Schema.FieldType type) {
    ByteString cellValue = cell.getValue();
    int valueSize = cellValue.size();
    switch (type.getTypeName()) {
      case BOOLEAN:
        checkArgument(valueSize == 1, message("Boolean", 1));
        return cellValue.toByteArray()[0] != 0;
      case BYTE:
        checkArgument(valueSize == 1, message("Byte", 1));
        return cellValue.toByteArray()[0];
      case INT16:
        checkArgument(valueSize == 2, message("Int16", 2));
        return Shorts.fromByteArray(cellValue.toByteArray());
      case INT32:
        checkArgument(valueSize == 4, message("Int32", 4));
        return Ints.fromByteArray(cellValue.toByteArray());
      case INT64:
        checkArgument(valueSize == 8, message("Int64", 8));
        return Longs.fromByteArray(cellValue.toByteArray());
      case FLOAT:
        checkArgument(valueSize == 4, message("Float", 4));
        return Float.intBitsToFloat(Ints.fromByteArray(cellValue.toByteArray()));
      case DOUBLE:
        checkArgument(valueSize == 8, message("Double", 8));
        return Double.longBitsToDouble(Longs.fromByteArray(cellValue.toByteArray()));
      case DATETIME:
        return DateTime.parse(cellValue.toStringUtf8());
      case STRING:
        return cellValue.toStringUtf8();
      case BYTES:
        return cellValue.toByteArray();
      case LOGICAL_TYPE:
        String identifier = checkArgumentNotNull(type.getLogicalType()).getIdentifier();
        throw new IllegalStateException("Unsupported logical type: " + identifier);
      default:
        throw new IllegalArgumentException(
            String.format("Unsupported cell value type '%s'.", type.getTypeName()));
    }
  }
@Test
  public void shouldFailParseInt16TypeTooLong() {
    byte[] value = new byte[6];
    IllegalArgumentException exception =
        assertThrows(IllegalArgumentException.class, () -> PARSER.getCellValue(cell(value), INT16));
    checkMessage(exception.getMessage(), "Int16 has to be 2-bytes long bytearray");
  }