Skip to content

Commit 6ac8877

Browse files
committed
Extracting method in test
1 parent 3b967b0 commit 6ac8877

File tree

2 files changed

+39
-60
lines changed

2 files changed

+39
-60
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/cluster/SubunitCluster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public boolean mergeIdentical(SubunitCluster other) {
241241
* same Subunit. This is checked by comparing the entity identifiers of the subunits
242242
* if one can be found.
243243
* Thus this only makes sense when the subunits are complete chains of a
244-
* deposited PDB entry. I
244+
* deposited PDB entry.
245245
*
246246
* @param other
247247
* SubunitCluster

biojava-structure/src/test/java/org/biojava/nbio/structure/cluster/TestSubunitCluster.java

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,7 @@ public class TestSubunitCluster {
5353
public void testMergeIdentical() {
5454

5555
// Create an Atom Array of poly-alanine
56-
List<Atom> atoms = new ArrayList<>(10);
57-
for (int i = 0; i < 10; i++) {
58-
Group g = new AminoAcidImpl();
59-
g.setPDBName("ALA");
60-
Atom a = new AtomImpl();
61-
a.setName(StructureTools.CA_ATOM_NAME);
62-
g.addAtom(a);
63-
atoms.add(a);
64-
}
65-
Atom[] reprAtoms = atoms.toArray(new Atom[atoms.size()]);
56+
Atom[] reprAtoms = mockAtomArray(10, "ALA", -1, null);
6657

6758
// Create two identical SubunitCluster
6859
SubunitCluster sc1 = new SubunitCluster(new Subunit(reprAtoms,
@@ -79,16 +70,7 @@ public void testMergeIdentical() {
7970
assertEquals(sc1.length(), 10);
8071

8172
// Create an Atom Array of poly-glycine
82-
List<Atom> atoms2 = new ArrayList<>(10);
83-
for (int i = 0; i < 10; i++) {
84-
Group g = new AminoAcidImpl();
85-
g.setPDBName("GLY");
86-
Atom a = new AtomImpl();
87-
a.setName(StructureTools.CA_ATOM_NAME);
88-
g.addAtom(a);
89-
atoms2.add(a);
90-
}
91-
Atom[] reprAtoms2 = atoms2.toArray(new Atom[atoms2.size()]);
73+
Atom[] reprAtoms2 = mockAtomArray(10, "GLY", -1, null);
9274

9375
SubunitCluster sc3 = new SubunitCluster(new Subunit(reprAtoms2,
9476
"subunit 1", null, null));
@@ -111,17 +93,8 @@ public void testMergeIdentical() {
11193
@Test
11294
public void testMergeSequence() throws CompoundNotFoundException {
11395

114-
// Create an Atom Array of ploy-alanine
115-
List<Atom> atoms = new ArrayList<>(100);
116-
for (int i = 0; i < 100; i++) {
117-
Group g = new AminoAcidImpl();
118-
g.setPDBName("ALA");
119-
Atom a = new AtomImpl();
120-
a.setName(StructureTools.CA_ATOM_NAME);
121-
g.addAtom(a);
122-
atoms.add(a);
123-
}
124-
Atom[] reprAtoms = atoms.toArray(new Atom[atoms.size()]);
96+
// Create an Atom Array of poly-alanine
97+
Atom[] reprAtoms = mockAtomArray(100, "ALA", -1, null);
12598

12699
// Create two identical SubunitCluster
127100
SubunitCluster sc1 = new SubunitCluster(new Subunit(reprAtoms,
@@ -140,16 +113,7 @@ public void testMergeSequence() throws CompoundNotFoundException {
140113
assertEquals(sc1.length(), 100);
141114

142115
// Create an Atom Array of poly-glycine
143-
List<Atom> atoms2 = new ArrayList<Atom>(100);
144-
for (int i = 0; i < 100; i++) {
145-
Group g = new AminoAcidImpl();
146-
g.setPDBName("GLY");
147-
Atom a = new AtomImpl();
148-
a.setName(StructureTools.CA_ATOM_NAME);
149-
g.addAtom(a);
150-
atoms2.add(a);
151-
}
152-
Atom[] reprAtoms2 = atoms2.toArray(new Atom[atoms2.size()]);
116+
Atom[] reprAtoms2 = mockAtomArray(100, "GLY", -1, null);
153117

154118
SubunitCluster sc3 = new SubunitCluster(new Subunit(reprAtoms2,
155119
"subunit 3", null, null));
@@ -163,24 +127,7 @@ public void testMergeSequence() throws CompoundNotFoundException {
163127
assertEquals(sc1.length(), 100);
164128

165129
// Create an Atom Array of 9 glycine and 91 alanine
166-
List<Atom> atoms3 = new ArrayList<>(100);
167-
for (int i = 0; i < 9; i++) {
168-
Group g = new AminoAcidImpl();
169-
g.setPDBName("GLY");
170-
Atom a = new AtomImpl();
171-
a.setName(StructureTools.CA_ATOM_NAME);
172-
g.addAtom(a);
173-
atoms3.add(a);
174-
}
175-
for (int i = 0; i < 91; i++) {
176-
Group g = new AminoAcidImpl();
177-
g.setPDBName("ALA");
178-
Atom a = new AtomImpl();
179-
a.setName(StructureTools.CA_ATOM_NAME);
180-
g.addAtom(a);
181-
atoms3.add(a);
182-
}
183-
Atom[] reprAtoms3 = atoms3.toArray(new Atom[atoms3.size()]);
130+
Atom[] reprAtoms3 = mockAtomArray(9, "GLY", 91, "ALA");
184131

185132
SubunitCluster sc4 = new SubunitCluster(new Subunit(reprAtoms3,
186133
"subunit 4", null, null));
@@ -283,4 +230,36 @@ public void testDivideInternally() throws StructureException, IOException {
283230
assertEquals(sc1.getAlignedAtomsSubunit(0).length,
284231
sc1.getAlignedAtomsSubunit(1).length);
285232
}
233+
234+
/**
235+
* Create a mock atom array, with size1 residues of type1, followed by size2 residues of type2
236+
* @param size1 the number of residues of type1 to add
237+
* @param type1 the 3 letter code of residue
238+
* @param size2 the number of residues of type2 to add, if -1 none are added
239+
* @param type2 the 3 letter code of residue, if null none are added
240+
* @return the mock atom array
241+
*/
242+
private Atom[] mockAtomArray(int size1, String type1, int size2, String type2) {
243+
List<Atom> atoms = new ArrayList<>(size1 + size2);
244+
for (int i = 0; i < size1; i++) {
245+
Group g = new AminoAcidImpl();
246+
g.setPDBName(type1);
247+
Atom a = new AtomImpl();
248+
a.setName(StructureTools.CA_ATOM_NAME);
249+
g.addAtom(a);
250+
atoms.add(a);
251+
}
252+
253+
if (size2 >= 0 && type2 !=null) {
254+
for (int i = 0; i < size2; i++) {
255+
Group g = new AminoAcidImpl();
256+
g.setPDBName(type2);
257+
Atom a = new AtomImpl();
258+
a.setName(StructureTools.CA_ATOM_NAME);
259+
g.addAtom(a);
260+
atoms.add(a);
261+
}
262+
}
263+
return atoms.toArray(new Atom[0]);
264+
}
286265
}

0 commit comments

Comments
 (0)