### Question:
Tensor implements AutoCloseable { public static <T extends TType> Tensor<T> of(DataType<T> dtype, Shape shape) { return of(dtype, shape, shape.size() * dtype.byteSize()); } private  Tensor(DataType<T> dtype, Shape shape); static Tensor<T> of(DataType<T> dtype, Shape shape); static Tensor<T> of(DataType<T> dtype, Shape shape, long size); static Tensor<T> of(DataType<T> dtype, Shape shape,
      Consumer<T> dataInitializer); static Tensor<T> of(DataType<T> dtype, Shape shape, long size,
      Consumer<T> dataInitializer); static Tensor<T> of(DataType<T> dtype, Shape shape, ByteDataBuffer rawData); @SuppressWarnings("unchecked") Tensor<U> expect(DataType<U> dt); @Override void close(); DataType<T> dataType(); long numBytes(); Shape shape(); T data(); ByteDataBuffer rawData(); @Override String toString();  }### Answer:
@Test public void allocateTensorWithSize() { try (Tensor<TInt32> t = Tensor.of(TInt32.DTYPE, Shape.of(2, 2, 2), 8 * TInt32.DTYPE.byteSize())) { } try (Tensor<TInt32> t = Tensor.of(TInt32.DTYPE, Shape.of(2, 2, 2), 9 * TInt32.DTYPE.byteSize())) { } try { Tensor.of(TInt32.DTYPE, Shape.of(2, 2, 2), 8 * TInt32.DTYPE.byteSize() - 1); fail(); } catch (IllegalArgumentException e) { } }