By throwing a test charged particle into a Reissner-Nordstrom (RN) black hole, we test the validity of the first and second laws of thermodynamics and the weak cosmic censorship conjecture (WCCC) with two types of boundary conditions: the asymptotically anti-de Sitter (AdS) space and a Dirichlet cavity wall placed in an asymptotically flat space. For the RN-AdS black hole, the second law of thermodynamics is satisfied, and the WCCC is violated for both extremal and near-extremal black holes. For the RN black hole in a cavity, the entropy can either increase or decrease depending on the change in the charge, and the WCCC is satisfied/violated for the extremal/near-extremal black hole. Our results indicate that there may be a connection between the black hole thermodynamics and the boundary condition imposed on the black hole.